Read series number from fb2 files

This commit is contained in:
Kovid Goyal 2008-08-16 15:41:54 -07:00
parent 9fa67e9fe3
commit c9fa1d673e
3 changed files with 8 additions and 4 deletions

View File

@ -201,7 +201,7 @@ class MetaInformation(object):
#: mi.cover_data = (ext, data) #: mi.cover_data = (ext, data)
self.cover_data = mi.cover_data if (mi and hasattr(mi, 'cover_data')) else (None, None) self.cover_data = mi.cover_data if (mi and hasattr(mi, 'cover_data')) else (None, None)
self.application_id = mi.application_id if (mi and hasattr(mi, 'application_id')) else None self.application_id = mi.application_id if (mi and hasattr(mi, 'application_id')) else None
self.manifest = getattr(mi, 'manifest', None) self.manifest = getattr(mi, 'manifest', None)
self.toc = getattr(mi, 'toc', None) self.toc = getattr(mi, 'toc', None)
self.spine = getattr(mi, 'spine', None) self.spine = getattr(mi, 'spine', None)
self.guide = getattr(mi, 'guide', None) self.guide = getattr(mi, 'guide', None)

View File

@ -41,6 +41,10 @@ def get_metadata(stream):
mi.author_sort = lastname+'; '+firstname mi.author_sort = lastname+'; '+firstname
if series: if series:
mi.series = series.get('name', None) mi.series = series.get('name', None)
try:
mi.series_index = int(series.get('number', None))
except (TypeError, ValueError):
pass
if cdata: if cdata:
mi.cover_data = cdata mi.cover_data = cdata
return mi return mi

View File

@ -12,7 +12,7 @@ from calibre.ebooks.metadata.lit import get_metadata as lit_metadata
from calibre.ebooks.metadata.epub import get_metadata as epub_metadata from calibre.ebooks.metadata.epub import get_metadata as epub_metadata
from calibre.ebooks.metadata.html import get_metadata as html_metadata from calibre.ebooks.metadata.html import get_metadata as html_metadata
from calibre.ebooks.mobi.reader import get_metadata as mobi_metadata from calibre.ebooks.mobi.reader import get_metadata as mobi_metadata
from calibre.ebooks.metadata.opf import OPFReader from calibre.ebooks.metadata.opf import OPFReader
from calibre.ebooks.metadata.rtf import set_metadata as set_rtf_metadata from calibre.ebooks.metadata.rtf import set_metadata as set_rtf_metadata
from calibre.ebooks.lrf.meta import set_metadata as set_lrf_metadata from calibre.ebooks.lrf.meta import set_metadata as set_lrf_metadata
from calibre.ebooks.metadata.epub import set_metadata as set_epub_metadata from calibre.ebooks.metadata.epub import set_metadata as set_epub_metadata
@ -29,14 +29,14 @@ _METADATA_PRIORITIES = [
# Higher values should be used to update metadata from lower values # Higher values should be used to update metadata from lower values
METADATA_PRIORITIES = collections.defaultdict(lambda:0) METADATA_PRIORITIES = collections.defaultdict(lambda:0)
for i, ext in enumerate(_METADATA_PRIORITIES): for i, ext in enumerate(_METADATA_PRIORITIES):
METADATA_PRIORITIES[ext] = i METADATA_PRIORITIES[ext] = i
def path_to_ext(path): def path_to_ext(path):
return os.path.splitext(path)[1][1:].lower() return os.path.splitext(path)[1][1:].lower()
def metadata_from_formats(formats): def metadata_from_formats(formats):
mi = MetaInformation(None, None) mi = MetaInformation(None, None)
formats.sort(cmp=lambda x,y: cmp(METADATA_PRIORITIES[path_to_ext(x)], formats.sort(cmp=lambda x,y: cmp(METADATA_PRIORITIES[path_to_ext(x)],
METADATA_PRIORITIES[path_to_ext(y)])) METADATA_PRIORITIES[path_to_ext(y)]))
for path in formats: for path in formats:
ext = path_to_ext(path) ext = path_to_ext(path)