2
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-12 01:10:46 +00:00

more error adaptive

This commit is contained in:
林檎 2017-03-02 23:15:15 +08:00
parent 879510da82
commit 13b4ae4c24

View File

@ -48,13 +48,16 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
else: else:
epub_metadata[s] = "Unknown" epub_metadata[s] = "Unknown"
#detect lang need futher modification in web.py /upload #detect lang need futher modification in web.py /upload
lang = p.xpath('dc:language/text()', namespaces=ns)[0] try:#maybe dc:language isn't present, less possible but possible
lang = lang.split('-', 1)[0] lang = p.xpath('dc:language/text()', namespaces=ns)[0]
if len(lang) == 2: lang = lang.split('-', 1)[0]
epub_metadata['languages'] = isoLanguages.get(part1=lang).name if len(lang) == 2:
elif len(lang) == 3: epub_metadata['languages'] = isoLanguages.get(part1=lang).name
epub_metadata['languages'] = isoLanguages.get(part3=lang).name elif len(lang) == 3:
else: epub_metadata['languages'] = isoLanguages.get(part3=lang).name
else:
epub_metadata['languages'] = ""
except:
epub_metadata['languages'] = "" epub_metadata['languages'] = ""
coversection = tree.xpath("/pkg:package/pkg:manifest/pkg:item[@id='cover-image']/@href", namespaces=ns) coversection = tree.xpath("/pkg:package/pkg:manifest/pkg:item[@id='cover-image']/@href", namespaces=ns)