mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix bug 6015 - Metadata was not being resaved to the metadata file after the device was reconnected
This commit is contained in:
parent
f37f5126a2
commit
bac3965847
@ -23,7 +23,7 @@ class Book(MetaInformation):
|
|||||||
'uuid', 'device_collections',
|
'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, '')
|
MetaInformation.__init__(self, '')
|
||||||
self.device_collections = []
|
self.device_collections = []
|
||||||
@ -42,10 +42,8 @@ class Book(MetaInformation):
|
|||||||
else:
|
else:
|
||||||
self.authors = [authors]
|
self.authors = [authors]
|
||||||
self.mime = mime
|
self.mime = mime
|
||||||
try:
|
|
||||||
self.size = os.path.getsize(self.path)
|
self.size = size # will be set later if None
|
||||||
except OSError:
|
|
||||||
self.size = 0
|
|
||||||
try:
|
try:
|
||||||
if ContentType == '6':
|
if ContentType == '6':
|
||||||
self.datetime = time.strptime(date, "%Y-%m-%dT%H:%M:%S.%f")
|
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)
|
idx = bl_cache.get(lpath, None)
|
||||||
if idx is not None:
|
if idx is not None:
|
||||||
|
bl_cache[lpath] = None
|
||||||
if ImageID is not None:
|
if ImageID is not None:
|
||||||
imagename = self.normalize_path(self._main_prefix + '.kobo/images/' + ImageID + ' - NickelBookCover.parsed')
|
imagename = self.normalize_path(self._main_prefix + '.kobo/images/' + ImageID + ' - NickelBookCover.parsed')
|
||||||
#print "Image name Normalized: " + imagename
|
#print "Image name Normalized: " + imagename
|
||||||
if imagename is not None:
|
if imagename is not None:
|
||||||
bl[idx].thumbnail = ImageWrapper(imagename)
|
bl[idx].thumbnail = ImageWrapper(imagename)
|
||||||
bl_cache[lpath] = None
|
|
||||||
if ContentType != '6':
|
if ContentType != '6':
|
||||||
if self.update_metadata_item(bl[idx]):
|
if self.update_metadata_item(bl[idx]):
|
||||||
# print 'update_metadata_item returned true'
|
# print 'update_metadata_item returned true'
|
||||||
changed = True
|
changed = True
|
||||||
bl[idx].device_collections = playlist_map.get(lpath, [])
|
bl[idx].device_collections = playlist_map.get(lpath, [])
|
||||||
else:
|
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'
|
# print 'Update booklist'
|
||||||
if bl.add_book(book, replace_metadata=False):
|
if bl.add_book(book, replace_metadata=False):
|
||||||
changed = True
|
changed = True
|
||||||
@ -381,3 +381,19 @@ class KOBO(USBMS):
|
|||||||
|
|
||||||
return USBMS.get_file(self, path, *args, **kwargs)
|
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