mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
A spot of refactoring
This commit is contained in:
parent
4c9fb6becd
commit
313ce6b0c9
@ -147,14 +147,22 @@ def get_comic_book_info(d, mi, series_index='volume'):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def get_comic_metadata(stream, stream_type, series_index='volume'):
|
def parse_comic_comment(comment, 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
|
||||||
|
import json
|
||||||
comment = None
|
|
||||||
|
|
||||||
mi = MetaInformation(None, None)
|
mi = MetaInformation(None, None)
|
||||||
|
m = json.loads(comment)
|
||||||
|
if isinstance(m, dict):
|
||||||
|
for cat in m:
|
||||||
|
if cat.startswith('ComicBookInfo'):
|
||||||
|
get_comic_book_info(m[cat], mi, series_index=series_index)
|
||||||
|
break
|
||||||
|
return mi
|
||||||
|
|
||||||
|
|
||||||
|
def get_comic_metadata(stream, stream_type, series_index='volume'):
|
||||||
|
comment = None
|
||||||
if stream_type == 'cbz':
|
if stream_type == 'cbz':
|
||||||
from calibre.utils.zipfile import ZipFile
|
from calibre.utils.zipfile import ZipFile
|
||||||
zf = ZipFile(stream)
|
zf = ZipFile(stream)
|
||||||
@ -163,12 +171,4 @@ def get_comic_metadata(stream, stream_type, series_index='volume'):
|
|||||||
from calibre.utils.unrar import comment as get_comment
|
from calibre.utils.unrar import comment as get_comment
|
||||||
comment = get_comment(stream)
|
comment = get_comment(stream)
|
||||||
|
|
||||||
if comment:
|
return parse_comic_comment(comment or b'{}', series_index=series_index)
|
||||||
import json
|
|
||||||
m = json.loads(comment)
|
|
||||||
if hasattr(m, 'iterkeys'):
|
|
||||||
for cat in m.iterkeys():
|
|
||||||
if cat.startswith('ComicBookInfo'):
|
|
||||||
get_comic_book_info(m[cat], mi, series_index=series_index)
|
|
||||||
break
|
|
||||||
return mi
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user