try not to break if file can not be parsed

This commit is contained in:
j 2016-01-15 13:03:42 +05:30
parent 3339c641c1
commit 4528ab60c4

View file

@ -18,6 +18,9 @@ from . import opf
from meta.utils import decode_html_data, to_isbn13
import settings
import logging
logger = logging.getLogger(__name__)
def get_id(f=None, data=None):
if data:
return base64.b32encode(hashlib.sha1(data).digest()).decode()
@ -30,6 +33,7 @@ def metadata(f, from_=None):
data['extension'] = ext
data['size'] = os.stat(f).st_size
try:
if ext == 'cbr':
info = cbr.info(f)
elif ext in ('epub', 'kepub'):
@ -39,6 +43,9 @@ def metadata(f, from_=None):
info = pdf.info(f)
elif ext == 'txt':
info = txt.info(f)
except:
logger.debug('failed to load %s info from %s', ext, f, exc_info=1)
info = {}
opf_info = {}
metadata_opf = os.path.join(os.path.dirname(from_ or f), 'metadata.opf')