This commit is contained in:
j 2016-01-07 15:42:48 +05:30
parent c33f580edf
commit 0e71dcd9a8
5 changed files with 53 additions and 41 deletions

View file

@ -19,6 +19,7 @@ class Install(Thread):
base_url = 'http://downloads.openmedialibrary.com/'
status = {}
failed = False
def __init__(self, target):
self.target = target
@ -72,8 +73,9 @@ class Install(Thread):
print('You need to install Pillow, lxml and pyOpenSSL\ni.e. sudo pip3 install pillow lxml pyOpenSSL')
if 'poppler' in apt_packages:
print('You need to install pdftocairo (part of poppler-utils)')
input("After installing those packages, press Enter to continue...")
sys.exit(1)
input("After installing those packages, run install again")
self.failed = True
return
target = self.target
target = os.path.normpath(os.path.join(os.path.abspath(target)))
if not os.path.exists(target):
@ -161,4 +163,5 @@ if __name__ == '__main__':
install = Install(target)
install.join()
subprocess.call([os.path.join(target, 'ctl'), 'open'])
if not install.failed:
subprocess.call([os.path.join(target, 'ctl'), 'open'])

View file

@ -11,7 +11,7 @@ from sqlalchemy import func
from oxtornado import actions
from utils import cleanup_id
from websocket import trigger_event
import metaremote as meta
import meta
from . import models
from . import query
from .person import get_sort_name
@ -265,6 +265,9 @@ def getMetadata(data):
response = meta.lookup(key, value)
if include_edits:
response.update(models.Metadata.load(key, value))
for key in [k['id'] for k in settings.config['itemKeys'] if isinstance(k['type'], list)]:
if key in response and not isinstance(response[key], list):
response[key] = [response[key]]
if response:
response['primaryid'] = [key, value]
return response

View file

@ -23,7 +23,8 @@ from utils import remove_empty_folders
from websocket import trigger_event
import db
import media
import metaremote as meta
#import metaremote as meta
import meta
import settings
import state
import utils

View file

@ -51,41 +51,44 @@ def lookup_provider(arg):
def lookup(key, value):
if not isvalid_id(key, value):
return {}
data = {key: [value]}
ids = set([(key, value)])
provider_data = {}
done = False
if key == 'isbn':
data = google.info(key, value)
else:
data = {key: [value]}
ids = set([(key, value)])
provider_data = {}
done = False
while not done:
done = True
for provider, id in providers:
result = lookup_provider((provider, id, ids, key, value))
done = not result - ids
ids.update(result)
logger.debug('FIXME: sort ids')
ids = sorted(ids, key=lambda i: ox.sort_string(''.join(i)))
logger.debug('IDS %s', ids)
for k, v in ids:
for provider, id in providers:
if id == k:
if provider not in provider_data:
provider_data[provider] = {}
for k_, v_ in globals()[provider].lookup(v).items():
if k_ not in provider_data[provider]:
provider_data[provider][k_] = v_
for provider in sorted(
list(provider_data.keys()),
key=lambda x: -len(provider_data[x])
):
logger.debug('%s %s %s', provider, len(provider_data[provider]), list(provider_data[provider].keys()))
for k_, v_ in provider_data[provider].items():
if not k_ in data:
data[k_] = v_
for k, v in ids:
if k not in data:
data[k] = []
if v not in data[k]:
data[k].append(v)
while not done:
done = True
for provider, id in providers:
result = lookup_provider((provider, id, ids, key, value))
done = not result - ids
ids.update(result)
logger.debug('FIXME: sort ids')
ids = sorted(ids, key=lambda i: ox.sort_string(''.join(i)))
logger.debug('IDS %s', ids)
for k, v in ids:
for provider, id in providers:
if id == k:
if provider not in provider_data:
provider_data[provider] = {}
for k_, v_ in globals()[provider].lookup(v).items():
if k_ not in provider_data[provider]:
provider_data[provider][k_] = v_
for provider in sorted(
list(provider_data.keys()),
key=lambda x: -len(provider_data[x])
):
logger.debug('%s %s %s', provider, len(provider_data[provider]), list(provider_data[provider].keys()))
for k_, v_ in provider_data[provider].items():
if not k_ in data:
data[k_] = v_
for k, v in ids:
if k not in data:
data[k] = []
if v not in data[k]:
data[k].append(v)
for key in [k['id'] for k in settings.config['itemKeys'] if isinstance(k['type'], list)]:
if key in data and not isinstance(data[key], list):
data[key] = [data[key]]

View file

@ -45,7 +45,7 @@ def info(key, value):
store.delete(url)
raise IOError(url, r)
if not 'items' in r:
print('unkown %s: %s [%s]' % (key, value, r))
print('unknown %s: %s [%s]' % (key, value, r))
return {}
_data = r['items'][0]['volumeInfo']
data = {}
@ -81,7 +81,9 @@ def info(key, value):
data['isbn'].append(k['identifier'])
else:
print('unknown identifier', k)
if 'publisher' in data and isinstance(data['publisher'], str):
data['publisher'] = [data['publisher']]
if 'language' in _data:
data['language'] = get_language(_data['language'])
data['language'] = [get_language(_data['language'])]
return data