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/' base_url = 'http://downloads.openmedialibrary.com/'
status = {} status = {}
failed = False
def __init__(self, target): def __init__(self, target):
self.target = 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') print('You need to install Pillow, lxml and pyOpenSSL\ni.e. sudo pip3 install pillow lxml pyOpenSSL')
if 'poppler' in apt_packages: if 'poppler' in apt_packages:
print('You need to install pdftocairo (part of poppler-utils)') print('You need to install pdftocairo (part of poppler-utils)')
input("After installing those packages, press Enter to continue...") input("After installing those packages, run install again")
sys.exit(1) self.failed = True
return
target = self.target target = self.target
target = os.path.normpath(os.path.join(os.path.abspath(target))) target = os.path.normpath(os.path.join(os.path.abspath(target)))
if not os.path.exists(target): if not os.path.exists(target):
@ -161,4 +163,5 @@ if __name__ == '__main__':
install = Install(target) install = Install(target)
install.join() 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 oxtornado import actions
from utils import cleanup_id from utils import cleanup_id
from websocket import trigger_event from websocket import trigger_event
import metaremote as meta import meta
from . import models from . import models
from . import query from . import query
from .person import get_sort_name from .person import get_sort_name
@ -265,6 +265,9 @@ def getMetadata(data):
response = meta.lookup(key, value) response = meta.lookup(key, value)
if include_edits: if include_edits:
response.update(models.Metadata.load(key, value)) 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: if response:
response['primaryid'] = [key, value] response['primaryid'] = [key, value]
return response return response

View file

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

View file

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

View file

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