mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix open files with PDF metadata reader
This commit is contained in:
parent
3dc42b5302
commit
8119b9e868
@ -39,13 +39,13 @@ def metadata_from_formats(formats):
|
||||
return mi2
|
||||
|
||||
for path, ext in zip(formats, extensions):
|
||||
stream = open(path, 'rb')
|
||||
try:
|
||||
mi.smart_update(get_metadata(stream, stream_type=ext, use_libprs_metadata=True))
|
||||
except:
|
||||
continue
|
||||
if getattr(mi, 'application_id', None) is not None:
|
||||
return mi
|
||||
with open(path, 'rb') as stream:
|
||||
try:
|
||||
mi.smart_update(get_metadata(stream, stream_type=ext, use_libprs_metadata=True))
|
||||
except:
|
||||
continue
|
||||
if getattr(mi, 'application_id', None) is not None:
|
||||
return mi
|
||||
|
||||
if not mi.title:
|
||||
mi.title = _('Unknown')
|
||||
|
@ -67,6 +67,8 @@ def set_metadata(stream, mi):
|
||||
stream.seek(0)
|
||||
|
||||
def get_cover(stream):
|
||||
data = StringIO.StringIO()
|
||||
|
||||
try:
|
||||
pdf = PdfFileReader(stream)
|
||||
output = PdfFileWriter()
|
||||
@ -88,12 +90,12 @@ def get_cover(stream):
|
||||
|
||||
img = Image.open('%s.jpg' % cover_path)
|
||||
|
||||
data = StringIO.StringIO()
|
||||
img.save(data, 'JPEG')
|
||||
return data.getvalue()
|
||||
except:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
return data.getvalue()
|
||||
|
||||
def option_parser():
|
||||
p = get_parser('pdf')
|
||||
|
Loading…
x
Reference in New Issue
Block a user