mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #5402 (CBZ meta data not imported)
This commit is contained in:
parent
6c62c10ac2
commit
0c168b0306
@ -7,7 +7,7 @@ import os
|
|||||||
import glob
|
import glob
|
||||||
from calibre.customize import FileTypePlugin, MetadataReaderPlugin, MetadataWriterPlugin
|
from calibre.customize import FileTypePlugin, MetadataReaderPlugin, MetadataWriterPlugin
|
||||||
from calibre.constants import numeric_version
|
from calibre.constants import numeric_version
|
||||||
from calibre.ebooks.metadata.archive import ArchiveExtract
|
from calibre.ebooks.metadata.archive import ArchiveExtract, get_cbz_metadata
|
||||||
|
|
||||||
class HTML2ZIP(FileTypePlugin):
|
class HTML2ZIP(FileTypePlugin):
|
||||||
name = 'HTML to ZIP'
|
name = 'HTML to ZIP'
|
||||||
@ -97,6 +97,12 @@ class ComicMetadataReader(MetadataReaderPlugin):
|
|||||||
from calibre.ebooks.metadata import MetaInformation
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
ret = extract_first(stream)
|
ret = extract_first(stream)
|
||||||
mi = MetaInformation(None, None)
|
mi = MetaInformation(None, None)
|
||||||
|
stream.seek(0)
|
||||||
|
if ftype == 'cbz':
|
||||||
|
try:
|
||||||
|
mi.smart_update(get_cbz_metadata(stream))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
if ret is not None:
|
if ret is not None:
|
||||||
path, data = ret
|
path, data = ret
|
||||||
ext = os.path.splitext(path)[1][1:]
|
ext = os.path.splitext(path)[1][1:]
|
||||||
|
@ -64,3 +64,45 @@ class ArchiveExtract(FileTypePlugin):
|
|||||||
of.write(zf.read(fname))
|
of.write(zf.read(fname))
|
||||||
return of.name
|
return of.name
|
||||||
|
|
||||||
|
def get_comic_book_info(d, mi):
|
||||||
|
series = d.get('series', '')
|
||||||
|
if series.strip():
|
||||||
|
mi.series = series
|
||||||
|
if d.get('volume', -1) > -1:
|
||||||
|
mi.series_index = float(d['volume'])
|
||||||
|
if d.get('rating', -1) > -1:
|
||||||
|
mi.rating = d['rating']
|
||||||
|
for x in ('title', 'publisher'):
|
||||||
|
y = d.get(x, '').strip()
|
||||||
|
if y:
|
||||||
|
setattr(mi, x, y)
|
||||||
|
tags = d.get('tags', [])
|
||||||
|
if tags:
|
||||||
|
mi.tags = tags
|
||||||
|
authors = []
|
||||||
|
for credit in d.get('credits', []):
|
||||||
|
if credit.get('role', '') in ('Writer', 'Artist', 'Cartoonist',
|
||||||
|
'Creator'):
|
||||||
|
x = credit.get('person', '')
|
||||||
|
if x:
|
||||||
|
x = ' '.join((reversed(x.split(', '))))
|
||||||
|
authors.append(x)
|
||||||
|
if authors:
|
||||||
|
mi.authors = authors
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_cbz_metadata(stream):
|
||||||
|
from calibre.utils.zipfile import ZipFile
|
||||||
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
|
import json
|
||||||
|
|
||||||
|
zf = ZipFile(stream)
|
||||||
|
mi = MetaInformation(None, None)
|
||||||
|
if zf.comment:
|
||||||
|
m = json.loads(zf.comment)
|
||||||
|
if hasattr(m, 'keys'):
|
||||||
|
for cat in m.keys():
|
||||||
|
if cat.startswith('ComicBookInfo'):
|
||||||
|
get_comic_book_info(m[cat], mi)
|
||||||
|
return mi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user