store metadata per user. remove primaryid. only store isbn13
This commit is contained in:
parent
90648f9e65
commit
02e040d9f5
16 changed files with 245 additions and 192 deletions
|
|
@ -15,7 +15,7 @@ from . import epub
|
|||
from . import txt
|
||||
from . import opf
|
||||
|
||||
from meta.utils import decode_html_data
|
||||
from meta.utils import decode_html_data, to_isbn13
|
||||
|
||||
def get_id(f=None, data=None):
|
||||
if data:
|
||||
|
|
@ -23,7 +23,6 @@ def get_id(f=None, data=None):
|
|||
else:
|
||||
return base64.b32encode(codecs.decode(ox.sha1sum(f, cached=True), 'hex')).decode()
|
||||
|
||||
|
||||
def metadata(f, from_=None):
|
||||
ext = f.split('.')[-1]
|
||||
data = {}
|
||||
|
|
@ -64,10 +63,17 @@ def metadata(f, from_=None):
|
|||
data[key] = data[key].replace('\x00', '')
|
||||
elif isinstance(data[key], list):
|
||||
data[key] = [e.replace('\x00', '') if isinstance(e, str) else e for e in data[key]]
|
||||
if 'isbn' in data:
|
||||
data['primaryid'] = ['isbn', data['isbn'][0]]
|
||||
elif 'asin' in data:
|
||||
data['primaryid'] = ['asin', data['asin'][0]]
|
||||
if 'isbn' in data and isinstance(data['isbn'], list):
|
||||
isbns = set()
|
||||
for i in data['isbn']:
|
||||
i = to_isbn13(i)
|
||||
if i:
|
||||
isbns.add(i)
|
||||
if isbns:
|
||||
data['isbn'] = list(isbns)[0]
|
||||
else:
|
||||
del data['isbn']
|
||||
|
||||
if 'author' in data:
|
||||
if isinstance(data['author'], str):
|
||||
if data['author'].strip():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue