mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Fix #6015 (Kobo issue with multiple author books)
This commit is contained in:
commit
d8b578cadb
@ -23,7 +23,7 @@ class Book(MetaInformation):
|
||||
'uuid', 'device_collections',
|
||||
]
|
||||
|
||||
def __init__(self, prefix, lpath, title, authors, mime, date, ContentType, thumbnail_name, other=None):
|
||||
def __init__(self, prefix, lpath, title, authors, mime, date, ContentType, thumbnail_name, size=None, other=None):
|
||||
|
||||
MetaInformation.__init__(self, '')
|
||||
self.device_collections = []
|
||||
@ -42,10 +42,8 @@ class Book(MetaInformation):
|
||||
else:
|
||||
self.authors = [authors]
|
||||
self.mime = mime
|
||||
try:
|
||||
self.size = os.path.getsize(self.path)
|
||||
except OSError:
|
||||
self.size = 0
|
||||
|
||||
self.size = size # will be set later if None
|
||||
try:
|
||||
if ContentType == '6':
|
||||
self.datetime = time.strptime(date, "%Y-%m-%dT%H:%M:%S.%f")
|
||||
|
@ -94,19 +94,19 @@ class KOBO(USBMS):
|
||||
|
||||
idx = bl_cache.get(lpath, None)
|
||||
if idx is not None:
|
||||
bl_cache[lpath] = None
|
||||
if ImageID is not None:
|
||||
imagename = self.normalize_path(self._main_prefix + '.kobo/images/' + ImageID + ' - NickelBookCover.parsed')
|
||||
#print "Image name Normalized: " + imagename
|
||||
if imagename is not None:
|
||||
bl[idx].thumbnail = ImageWrapper(imagename)
|
||||
bl_cache[lpath] = None
|
||||
if ContentType != '6':
|
||||
if self.update_metadata_item(bl[idx]):
|
||||
# print 'update_metadata_item returned true'
|
||||
changed = True
|
||||
bl[idx].device_collections = playlist_map.get(lpath, [])
|
||||
else:
|
||||
book = Book(prefix, lpath, title, authors, mime, date, ContentType, ImageID)
|
||||
book = self.book_from_path(prefix, lpath, title, authors, mime, date, ContentType, ImageID)
|
||||
# print 'Update booklist'
|
||||
if bl.add_book(book, replace_metadata=False):
|
||||
changed = True
|
||||
@ -316,10 +316,10 @@ class KOBO(USBMS):
|
||||
lpath = lpath[1:]
|
||||
#print "path: " + lpath
|
||||
#book = self.book_class(prefix, lpath, other=info)
|
||||
lpath = self.normalize_path(prefix + lpath)
|
||||
book = Book(prefix, lpath, '', '', '', '', '', '', other=info)
|
||||
if book.size is None:
|
||||
book.size = os.stat(self.normalize_path(path)).st_size
|
||||
book._new_book = True # Must be before add_book
|
||||
booklists[blist].add_book(book, replace_metadata=True)
|
||||
self.report_progress(1.0, _('Adding books to device metadata listing...'))
|
||||
|
||||
@ -380,3 +380,19 @@ class KOBO(USBMS):
|
||||
|
||||
return USBMS.get_file(self, path, *args, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def book_from_path(cls, prefix, lpath, title, authors, mime, date, ContentType, ImageID):
|
||||
from calibre.ebooks.metadata import MetaInformation
|
||||
|
||||
if cls.settings().read_metadata or cls.MUST_READ_METADATA:
|
||||
mi = cls.metadata_from_path(cls.normalize_path(os.path.join(prefix, lpath)))
|
||||
else:
|
||||
from calibre.ebooks.metadata.meta import metadata_from_filename
|
||||
mi = metadata_from_filename(cls.normalize_path(os.path.basename(lpath)),
|
||||
cls.build_template_regexp())
|
||||
if mi is None:
|
||||
mi = MetaInformation(os.path.splitext(os.path.basename(lpath))[0],
|
||||
[_('Unknown')])
|
||||
size = os.stat(cls.normalize_path(os.path.join(prefix, lpath))).st_size
|
||||
book = Book(prefix, lpath, title, authors, mime, date, ContentType, ImageID, size=size, other=mi)
|
||||
return book
|
||||
|
Loading…
x
Reference in New Issue
Block a user