Allow customization of comic metadata reader plugin

Allow customizing the comic metadata reader plugin via
Preferences->Plugins to read the series index from either the volume
or the issue number of the comic. Fixes #1211433 [comicinfo metada uses volume instead of issue](https://bugs.launchpad.net/calibre/+bug/1211433)
This commit is contained in:
Kovid Goyal 2013-08-15 09:14:04 +05:30
parent c8083b0995
commit 767bee56a2
2 changed files with 15 additions and 6 deletions

View File

@ -130,6 +130,9 @@ class ComicMetadataReader(MetadataReaderPlugin):
file_types = set(['cbr', 'cbz']) file_types = set(['cbr', 'cbz'])
description = _('Extract cover from comic files') description = _('Extract cover from comic files')
def customization_help(self, gui=False):
return 'Read series number from volume or issue number. Default is volume, set this to issue to use issue number instead.'
def get_metadata(self, stream, ftype): def get_metadata(self, stream, ftype):
if hasattr(stream, 'seek') and hasattr(stream, 'tell'): if hasattr(stream, 'seek') and hasattr(stream, 'tell'):
pos = stream.tell() pos = stream.tell()
@ -151,8 +154,11 @@ class ComicMetadataReader(MetadataReaderPlugin):
mi = MetaInformation(None, None) mi = MetaInformation(None, None)
stream.seek(0) stream.seek(0)
if ftype in {'cbr', 'cbz'}: if ftype in {'cbr', 'cbz'}:
series_index = self.site_customization
if series_index not in {'volume', 'issue'}:
series_index = 'volume'
try: try:
mi.smart_update(get_comic_metadata(stream, ftype)) mi.smart_update(get_comic_metadata(stream, ftype, series_index=series_index))
except: except:
pass pass
if ret is not None: if ret is not None:

View File

@ -86,13 +86,16 @@ 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): def get_comic_book_info(d, mi, series_index='volume'):
# See http://code.google.com/p/comicbookinfo/wiki/Example # See http://code.google.com/p/comicbookinfo/wiki/Example
series = d.get('series', '') series = d.get('series', '')
if series.strip(): if series.strip():
mi.series = series mi.series = series
if d.get('volume', -1) > -1: si = d.get(series_index, None)
mi.series_index = float(d['volume']) if si is None:
si = d.get('issue' if series_index == 'volume' else 'volume', None)
if si is not None:
mi.series_index = float(si)
if d.get('rating', -1) > -1: if d.get('rating', -1) > -1:
mi.rating = d['rating'] mi.rating = d['rating']
for x in ('title', 'publisher'): for x in ('title', 'publisher'):
@ -126,7 +129,7 @@ def get_comic_book_info(d, mi):
except: except:
pass pass
def get_comic_metadata(stream, stream_type): def get_comic_metadata(stream, stream_type, series_index='volume'):
# See http://code.google.com/p/comicbookinfo/wiki/Example # See http://code.google.com/p/comicbookinfo/wiki/Example
from calibre.ebooks.metadata import MetaInformation from calibre.ebooks.metadata import MetaInformation
@ -149,7 +152,7 @@ def get_comic_metadata(stream, stream_type):
if hasattr(m, 'iterkeys'): if hasattr(m, 'iterkeys'):
for cat in 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, series_index=series_index)
break break
return mi return mi