From 767bee56a2e39f562d5de2c674801cd276d2bafc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 15 Aug 2013 09:14:04 +0530 Subject: [PATCH] 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) --- src/calibre/customize/builtins.py | 8 +++++++- src/calibre/ebooks/metadata/archive.py | 13 ++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 0812325157..24c3a688b2 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -130,6 +130,9 @@ class ComicMetadataReader(MetadataReaderPlugin): file_types = set(['cbr', 'cbz']) 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): if hasattr(stream, 'seek') and hasattr(stream, 'tell'): pos = stream.tell() @@ -151,8 +154,11 @@ class ComicMetadataReader(MetadataReaderPlugin): mi = MetaInformation(None, None) stream.seek(0) if ftype in {'cbr', 'cbz'}: + series_index = self.site_customization + if series_index not in {'volume', 'issue'}: + series_index = 'volume' try: - mi.smart_update(get_comic_metadata(stream, ftype)) + mi.smart_update(get_comic_metadata(stream, ftype, series_index=series_index)) except: pass if ret is not None: diff --git a/src/calibre/ebooks/metadata/archive.py b/src/calibre/ebooks/metadata/archive.py index b236064ed8..7b8ecd2ca9 100644 --- a/src/calibre/ebooks/metadata/archive.py +++ b/src/calibre/ebooks/metadata/archive.py @@ -86,13 +86,16 @@ class ArchiveExtract(FileTypePlugin): of.write(zf.read(fname)) 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 series = d.get('series', '') if series.strip(): mi.series = series - if d.get('volume', -1) > -1: - mi.series_index = float(d['volume']) + si = d.get(series_index, None) + 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: mi.rating = d['rating'] for x in ('title', 'publisher'): @@ -126,7 +129,7 @@ def get_comic_book_info(d, mi): except: 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 from calibre.ebooks.metadata import MetaInformation @@ -149,7 +152,7 @@ def get_comic_metadata(stream, stream_type): if hasattr(m, 'iterkeys'): for cat in m.iterkeys(): if cat.startswith('ComicBookInfo'): - get_comic_book_info(m[cat], mi) + get_comic_book_info(m[cat], mi, series_index=series_index) break return mi