try not to break if file can not be parsed
This commit is contained in:
parent
3339c641c1
commit
4528ab60c4
1 changed files with 16 additions and 9 deletions
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue