mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix reading metadata from MOBI files in RAR archives
This commit is contained in:
parent
76c6434898
commit
b3011cad59
@ -8,9 +8,10 @@ Read metadata from RAR archives
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from cStringIO import StringIO
|
|
||||||
from calibre.ptempfile import PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryFile, TemporaryDirectory
|
||||||
from calibre.libunrar import extract_member, names
|
from calibre.libunrar import extract_member, names
|
||||||
|
from calibre import CurrentDir
|
||||||
|
|
||||||
def get_metadata(stream):
|
def get_metadata(stream):
|
||||||
from calibre.ebooks.metadata.archive import is_comic
|
from calibre.ebooks.metadata.archive import is_comic
|
||||||
@ -32,8 +33,10 @@ def get_metadata(stream):
|
|||||||
stream_type = stream_type[1:]
|
stream_type = stream_type[1:]
|
||||||
if stream_type in ('lit', 'opf', 'prc', 'mobi', 'fb2', 'epub',
|
if stream_type in ('lit', 'opf', 'prc', 'mobi', 'fb2', 'epub',
|
||||||
'rb', 'imp', 'pdf', 'lrf'):
|
'rb', 'imp', 'pdf', 'lrf'):
|
||||||
data = extract_member(path, match=None, name=f)[1]
|
with TemporaryDirectory() as tdir:
|
||||||
stream = StringIO(data)
|
with CurrentDir(tdir):
|
||||||
|
stream = extract_member(path, match=None, name=f,
|
||||||
|
as_file=True)[1]
|
||||||
return get_metadata(stream, stream_type)
|
return get_metadata(stream, stream_type)
|
||||||
raise ValueError('No ebook found in RAR archive')
|
raise ValueError('No ebook found in RAR archive')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user