From 619ea1f5c258558067996e3902ebafe065dc1737 Mon Sep 17 00:00:00 2001 From: Timothy Legge Date: Fri, 10 Sep 2010 19:08:18 -0300 Subject: [PATCH 1/4] Move the lookup of content id by extension to a function - cleanup/preparation for device collections --- src/calibre/devices/kobo/driver.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index 5e1c752c76..04c4256a49 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -231,21 +231,9 @@ class KOBO(USBMS): path = self.normalize_path(path) # print "Delete file normalized path: " + path extension = os.path.splitext(path)[1] - - if extension == '.kobo': - # Kobo books do not have book files. They do have some images though - #print "kobo book" - ContentType = 6 - ContentID = self.contentid_from_path(path, ContentType) - elif extension == '.pdf' or extension == '.epub': - # print "ePub or pdf" - ContentType = 16 - #print "Path: " + path - ContentID = self.contentid_from_path(path, ContentType) - # print "ContentID: " + ContentID - else: # if extension == '.html' or extension == '.txt': - ContentType = 999 # Yet another hack: to get around Kobo changing how ContentID is stored - ContentID = self.contentid_from_path(path, ContentType) + ContentType = self.get_content_type_from_extension(extension) + + ContentID = self.contentid_from_path(path, ContentType) ImageID = self.delete_via_sql(ContentID, ContentType) #print " We would now delete the Images for" + ImageID @@ -343,6 +331,17 @@ class KOBO(USBMS): ContentID = ContentID.replace("\\", '/') return ContentID + def get_content_type_from_extension(self, extension): + if extension == '.kobo': + # Kobo books do not have book files. They do have some images though + #print "kobo book" + ContentType = 6 + elif extension == '.pdf' or extension == '.epub': + # print "ePub or pdf" + ContentType = 16 + else: # if extension == '.html' or extension == '.txt': + ContentType = 999 # Yet another hack: to get around Kobo changing how ContentID is stored + return ContentType def path_from_contentid(self, ContentID, ContentType, oncard): path = ContentID From b1b099d7e8fc9484eca0ee0b197334969b30d312 Mon Sep 17 00:00:00 2001 From: Timothy Legge Date: Fri, 10 Sep 2010 19:12:52 -0300 Subject: [PATCH 2/4] Fix bug processing kobo books introduced in 6084.1.4 - no one mentioned it so it must not have caused any real issues --- src/calibre/devices/kobo/driver.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index 04c4256a49..9bed6bf0bf 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -106,7 +106,10 @@ class KOBO(USBMS): changed = True bl[idx].device_collections = playlist_map.get(lpath, []) else: - book = self.book_from_path(prefix, lpath, title, authors, mime, date, ContentType, ImageID) + if ContentType == '6': + book = Book(prefix, lpath, title, authors, mime, date, ContentType, ImageID, size=1048576) + else: + 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 From 0fe81939ea5697b8b66863fb37ca6b5ab33ef5f6 Mon Sep 17 00:00:00 2001 From: Timothy Legge Date: Fri, 10 Sep 2010 20:53:26 -0300 Subject: [PATCH 3/4] Fix long standing bug in date shown for kobo books --- src/calibre/devices/kobo/books.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/calibre/devices/kobo/books.py b/src/calibre/devices/kobo/books.py index 9da99d75c8..496162d668 100644 --- a/src/calibre/devices/kobo/books.py +++ b/src/calibre/devices/kobo/books.py @@ -44,16 +44,17 @@ class Book(MetaInformation): self.mime = mime 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") - else: - self.datetime = time.gmtime(os.path.getctime(self.path)) - except: - self.datetime = time.gmtime() - if thumbnail_name is not None: - self.thumbnail = ImageWrapper(thumbnail_name) + if ContentType == '6': + self.datetime = time.strptime(date, "%Y-%m-%dT%H:%M:%S.%f") + else: + try: + self.datetime = time.gmtime(os.path.getctime(self.path)) + except: + self.datetime = time.gmtime() + + if thumbnail_name is not None: + self.thumbnail = ImageWrapper(thumbnail_name) self.tags = [] if other: self.smart_update(other) From fd7f23f7c2d6d2ec2594f48d02922ba7a00d01c7 Mon Sep 17 00:00:00 2001 From: Timothy Legge Date: Fri, 10 Sep 2010 22:13:52 -0300 Subject: [PATCH 4/4] Update book.device_collections before add_book is called --- src/calibre/devices/kobo/driver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index 9bed6bf0bf..f24e00143b 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -111,9 +111,9 @@ class KOBO(USBMS): else: book = self.book_from_path(prefix, lpath, title, authors, mime, date, ContentType, ImageID) # print 'Update booklist' + book.device_collections = playlist_map.get(book.lpath, []) if bl.add_book(book, replace_metadata=False): changed = True - book.device_collections = playlist_map.get(book.lpath, []) except: # Probably a path encoding error import traceback traceback.print_exc()