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
|
from meta.utils import decode_html_data, to_isbn13
|
||||||
import settings
|
import settings
|
||||||
|
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def get_id(f=None, data=None):
|
def get_id(f=None, data=None):
|
||||||
if data:
|
if data:
|
||||||
return base64.b32encode(hashlib.sha1(data).digest()).decode()
|
return base64.b32encode(hashlib.sha1(data).digest()).decode()
|
||||||
|
@ -30,15 +33,19 @@ def metadata(f, from_=None):
|
||||||
data['extension'] = ext
|
data['extension'] = ext
|
||||||
data['size'] = os.stat(f).st_size
|
data['size'] = os.stat(f).st_size
|
||||||
|
|
||||||
if ext == 'cbr':
|
try:
|
||||||
info = cbr.info(f)
|
if ext == 'cbr':
|
||||||
elif ext in ('epub', 'kepub'):
|
info = cbr.info(f)
|
||||||
info = epub.info(f)
|
elif ext in ('epub', 'kepub'):
|
||||||
data['extension'] = 'epub'
|
info = epub.info(f)
|
||||||
elif ext == 'pdf':
|
data['extension'] = 'epub'
|
||||||
info = pdf.info(f)
|
elif ext == 'pdf':
|
||||||
elif ext == 'txt':
|
info = pdf.info(f)
|
||||||
info = txt.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 = {}
|
opf_info = {}
|
||||||
metadata_opf = os.path.join(os.path.dirname(from_ or f), 'metadata.opf')
|
metadata_opf = os.path.join(os.path.dirname(from_ or f), 'metadata.opf')
|
||||||
|
|
Loading…
Reference in a new issue