diff --git a/oml/media/__init__.py b/oml/media/__init__.py index cbfe8cd..7d4eee1 100644 --- a/oml/media/__init__.py +++ b/oml/media/__init__.py @@ -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,15 +33,19 @@ def metadata(f, from_=None): data['extension'] = ext data['size'] = os.stat(f).st_size - if ext == 'cbr': - info = cbr.info(f) - elif ext in ('epub', 'kepub'): - info = epub.info(f) - data['extension'] = 'epub' - elif ext == 'pdf': - info = pdf.info(f) - elif ext == 'txt': - info = txt.info(f) + try: + if ext == 'cbr': + info = cbr.info(f) + elif ext in ('epub', 'kepub'): + info = epub.info(f) + data['extension'] = 'epub' + elif ext == 'pdf': + 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')