mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Read metadata from ebooks in zip archives. Fixes #1570 (FB2 metadata from ZIP archive)
This commit is contained in:
parent
1f05c41c7a
commit
33f07eedc8
@ -25,6 +25,17 @@ every time you add an HTML file to the library.\
|
|||||||
html2oeb(htmlfile, of)
|
html2oeb(htmlfile, of)
|
||||||
return of.name
|
return of.name
|
||||||
|
|
||||||
|
class OPFMetadataReader(MetadataReaderPlugin):
|
||||||
|
|
||||||
|
name = 'Read OPF metadata'
|
||||||
|
file_types = set(['opf'])
|
||||||
|
description = _('Read metadata from %s files')%'OPF'
|
||||||
|
|
||||||
|
def get_metadata(self, stream, ftype):
|
||||||
|
from calibre.ebooks.metadata.opf2 import OPF
|
||||||
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
|
return MetaInformation(OPF(stream, os.getcwd()))
|
||||||
|
|
||||||
class RTFMetadataReader(MetadataReaderPlugin):
|
class RTFMetadataReader(MetadataReaderPlugin):
|
||||||
|
|
||||||
name = 'Read RTF metadata'
|
name = 'Read RTF metadata'
|
||||||
@ -167,6 +178,16 @@ class ComicMetadataReader(MetadataReaderPlugin):
|
|||||||
ext = os.path.splitext(path)[1][1:]
|
ext = os.path.splitext(path)[1][1:]
|
||||||
mi.cover_data = (ext.lower(), data)
|
mi.cover_data = (ext.lower(), data)
|
||||||
return mi
|
return mi
|
||||||
|
|
||||||
|
class ZipMetadataReader(MetadataReaderPlugin):
|
||||||
|
|
||||||
|
name = 'Read ZIP metadata'
|
||||||
|
file_types = set(['zip', 'oebzip'])
|
||||||
|
description = _('Read metadata from ebooks in ZIP archives')
|
||||||
|
|
||||||
|
def get_metadata(self, stream, ftype):
|
||||||
|
from calibre.ebooks.metadata.zip import get_metadata
|
||||||
|
return get_metadata(stream)
|
||||||
|
|
||||||
class EPUBMetadataWriter(MetadataWriterPlugin):
|
class EPUBMetadataWriter(MetadataWriterPlugin):
|
||||||
|
|
||||||
|
24
src/calibre/ebooks/metadata/zip.py
Normal file
24
src/calibre/ebooks/metadata/zip.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
from __future__ import with_statement
|
||||||
|
__license__ = 'GPL v3'
|
||||||
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
|
import os
|
||||||
|
from zipfile import ZipFile
|
||||||
|
from cStringIO import StringIO
|
||||||
|
|
||||||
|
|
||||||
|
def get_metadata(stream):
|
||||||
|
stream_type = None
|
||||||
|
zf = ZipFile(stream, 'r')
|
||||||
|
for f in zf.namelist():
|
||||||
|
stream_type = os.path.splitext(f)[1].lower()
|
||||||
|
if stream_type:
|
||||||
|
stream_type = stream_type[1:]
|
||||||
|
if stream_type in ('lit', 'opf', 'prc', 'mobi', 'fb2', 'epub',
|
||||||
|
'rb', 'imp', 'pdf', 'lrf'):
|
||||||
|
from calibre.ebooks.metadata.meta import get_metadata
|
||||||
|
stream = StringIO(zf.read(f))
|
||||||
|
return get_metadata(stream, stream_type)
|
||||||
|
raise ValueError('No ebook found in ZIP archive')
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user