mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Comic metadata: Support reading metadata from cbr files. Also read the comments and published date info from the metadata. Fixes #1082340 (Metadata in cbz and cbr files)
This commit is contained in:
parent
3e5028e275
commit
adcc860474
@ -8,7 +8,7 @@ from calibre import guess_type
|
|||||||
from calibre.customize import (FileTypePlugin, MetadataReaderPlugin,
|
from calibre.customize import (FileTypePlugin, MetadataReaderPlugin,
|
||||||
MetadataWriterPlugin, PreferencesPlugin, InterfaceActionBase, StoreBase)
|
MetadataWriterPlugin, PreferencesPlugin, InterfaceActionBase, StoreBase)
|
||||||
from calibre.constants import numeric_version
|
from calibre.constants import numeric_version
|
||||||
from calibre.ebooks.metadata.archive import ArchiveExtract, get_cbz_metadata
|
from calibre.ebooks.metadata.archive import ArchiveExtract, get_comic_metadata
|
||||||
from calibre.ebooks.html.to_zip import HTML2ZIP
|
from calibre.ebooks.html.to_zip import HTML2ZIP
|
||||||
|
|
||||||
plugins = []
|
plugins = []
|
||||||
@ -150,9 +150,9 @@ class ComicMetadataReader(MetadataReaderPlugin):
|
|||||||
ret = extract_first(stream)
|
ret = extract_first(stream)
|
||||||
mi = MetaInformation(None, None)
|
mi = MetaInformation(None, None)
|
||||||
stream.seek(0)
|
stream.seek(0)
|
||||||
if ftype == 'cbz':
|
if ftype in {'cbr', 'cbz'}:
|
||||||
try:
|
try:
|
||||||
mi.smart_update(get_cbz_metadata(stream))
|
mi.smart_update(get_comic_metadata(stream, ftype))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
if ret is not None:
|
if ret is not None:
|
||||||
|
@ -110,21 +110,44 @@ def get_comic_book_info(d, mi):
|
|||||||
authors.append(x)
|
authors.append(x)
|
||||||
if authors:
|
if authors:
|
||||||
mi.authors = authors
|
mi.authors = authors
|
||||||
|
comments = d.get('comments', '')
|
||||||
|
if comments and comments.strip():
|
||||||
|
mi.comments = comments.strip()
|
||||||
|
pubm, puby = d.get('publicationMonth', None), d.get('publicationYear', None)
|
||||||
|
if puby is not None:
|
||||||
|
from calibre.utils.date import parse_only_date
|
||||||
|
from datetime import date
|
||||||
|
try:
|
||||||
|
dt = date(puby, 6 if pubm is None else pubm, 15)
|
||||||
|
dt = parse_only_date(str(dt))
|
||||||
|
mi.pubdate = dt
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_comic_metadata(stream, stream_type):
|
||||||
|
|
||||||
def get_cbz_metadata(stream):
|
|
||||||
# See http://code.google.com/p/comicbookinfo/wiki/Example
|
# See http://code.google.com/p/comicbookinfo/wiki/Example
|
||||||
from calibre.utils.zipfile import ZipFile
|
|
||||||
from calibre.ebooks.metadata import MetaInformation
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
import json
|
|
||||||
|
|
||||||
zf = ZipFile(stream)
|
comment = None
|
||||||
|
|
||||||
mi = MetaInformation(None, None)
|
mi = MetaInformation(None, None)
|
||||||
if zf.comment:
|
|
||||||
m = json.loads(zf.comment)
|
if stream_type == 'cbz':
|
||||||
if hasattr(m, 'keys'):
|
from calibre.utils.zipfile import ZipFile
|
||||||
for cat in m.keys():
|
zf = ZipFile(stream)
|
||||||
|
comment = zf.comment
|
||||||
|
elif stream_type == 'cbr':
|
||||||
|
from calibre.utils.unrar import RARFile
|
||||||
|
f = RARFile(stream, get_comment=True)
|
||||||
|
comment = f.comment
|
||||||
|
|
||||||
|
if comment:
|
||||||
|
import json
|
||||||
|
m = json.loads(comment)
|
||||||
|
if hasattr(m, 'iterkeys'):
|
||||||
|
for cat in m.iterkeys():
|
||||||
if cat.startswith('ComicBookInfo'):
|
if cat.startswith('ComicBookInfo'):
|
||||||
get_comic_book_info(m[cat], mi)
|
get_comic_book_info(m[cat], mi)
|
||||||
|
break
|
||||||
return mi
|
return mi
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user