mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Kobo driver: Fix the ondevice status for some books getting lost. Fixes #1069403 (kobo glo syncronize problem)
This commit is contained in:
parent
7e50d7b6bf
commit
7442abf298
@ -20,7 +20,7 @@ class Book(Book_):
|
|||||||
def __init__(self, prefix, lpath, title=None, authors=None, mime=None, date=None, ContentType=None,
|
def __init__(self, prefix, lpath, title=None, authors=None, mime=None, date=None, ContentType=None,
|
||||||
thumbnail_name=None, size=0, other=None):
|
thumbnail_name=None, size=0, other=None):
|
||||||
# debug_print('Book::__init__ - title=', title)
|
# debug_print('Book::__init__ - title=', title)
|
||||||
show_debug = title is not None and title.lower().find("magic kingdom") >= 0
|
show_debug = title is not None and title.lower().find("xxxxx") >= 0
|
||||||
if show_debug:
|
if show_debug:
|
||||||
debug_print("Book::__init__ - title=", title, 'authors=', authors)
|
debug_print("Book::__init__ - title=", title, 'authors=', authors)
|
||||||
debug_print("Book::__init__ - other=", other)
|
debug_print("Book::__init__ - other=", other)
|
||||||
@ -31,8 +31,8 @@ class Book(Book_):
|
|||||||
|
|
||||||
if authors is not None and len(authors) > 0:
|
if authors is not None and len(authors) > 0:
|
||||||
self.authors_from_string(authors)
|
self.authors_from_string(authors)
|
||||||
if self.author_sort is None or self.author_sort == "Unknown":
|
if self.author_sort is None or self.author_sort == "Unknown":
|
||||||
self.author_sort = author_to_author_sort(self.authors)
|
self.author_sort = author_to_author_sort(authors)
|
||||||
|
|
||||||
self.mime = mime
|
self.mime = mime
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ class Book(Book_):
|
|||||||
self.datetime = time.gmtime()
|
self.datetime = time.gmtime()
|
||||||
|
|
||||||
self.contentID = None
|
self.contentID = None
|
||||||
self.current_collections = []
|
self.current_shelves = []
|
||||||
|
|
||||||
if thumbnail_name is not None:
|
if thumbnail_name is not None:
|
||||||
self.thumbnail = ImageWrapper(thumbnail_name)
|
self.thumbnail = ImageWrapper(thumbnail_name)
|
||||||
|
@ -850,7 +850,7 @@ class KOBO(USBMS):
|
|||||||
return collections
|
return collections
|
||||||
|
|
||||||
def sync_booklists(self, booklists, end_session=True):
|
def sync_booklists(self, booklists, end_session=True):
|
||||||
# debug_print('KOBO: started sync_booklists')
|
debug_print('KOBO: started sync_booklists')
|
||||||
paths = self.get_device_paths()
|
paths = self.get_device_paths()
|
||||||
|
|
||||||
blists = {}
|
blists = {}
|
||||||
@ -872,7 +872,7 @@ class KOBO(USBMS):
|
|||||||
self.update_device_database_collections(blist, collections, oncard)
|
self.update_device_database_collections(blist, collections, oncard)
|
||||||
|
|
||||||
USBMS.sync_booklists(self, booklists, end_session=end_session)
|
USBMS.sync_booklists(self, booklists, end_session=end_session)
|
||||||
#debug_print('KOBO: finished sync_booklists')
|
debug_print('KOBO: finished sync_booklists')
|
||||||
|
|
||||||
def rebuild_collections(self, booklist, oncard):
|
def rebuild_collections(self, booklist, oncard):
|
||||||
collections_attributes = []
|
collections_attributes = []
|
||||||
@ -1199,7 +1199,7 @@ class KOBOTOUCH(KOBO):
|
|||||||
author = 'David Forrester'
|
author = 'David Forrester'
|
||||||
description = 'Communicate with the Kobo Touch, Glo and Mini firmware. Based on the existing Kobo driver by %s.' % (KOBO.author)
|
description = 'Communicate with the Kobo Touch, Glo and Mini firmware. Based on the existing Kobo driver by %s.' % (KOBO.author)
|
||||||
|
|
||||||
supported_dbversion = 62
|
supported_dbversion = 65
|
||||||
min_supported_dbversion = 53
|
min_supported_dbversion = 53
|
||||||
|
|
||||||
booklist_class = KTCollectionsBookList
|
booklist_class = KTCollectionsBookList
|
||||||
@ -1285,13 +1285,21 @@ class KOBOTOUCH(KOBO):
|
|||||||
|
|
||||||
# Image file name endings. Made up of: image size, min_dbversion, max_dbversion,
|
# Image file name endings. Made up of: image size, min_dbversion, max_dbversion,
|
||||||
COVER_FILE_ENDINGS = {
|
COVER_FILE_ENDINGS = {
|
||||||
' - N3_LIBRARY_FULL.parsed':[(355,530),0, 99,],
|
' - N3_LIBRARY_FULL.parsed':[(355,473),0, 99,], # Used for Details screen
|
||||||
# ' - N3_LIBRARY_FULL.parsed':[(600,800),0, 99,],
|
' - N3_LIBRARY_GRID.parsed':[(149,198),0, 99,], # Used for library lists
|
||||||
' - N3_LIBRARY_GRID.parsed':[(149,233),0, 99,],
|
' - N3_LIBRARY_LIST.parsed':[(60,90),0, 53,],
|
||||||
' - N3_LIBRARY_LIST.parsed':[(60,90),0, 99,],
|
# ' - N3_LIBRARY_SHELF.parsed': [(40,60),0, 52,],
|
||||||
' - N3_LIBRARY_SHELF.parsed': [(40,60),0, 52,],
|
' - N3_FULL.parsed':[(600,800),0, 99,], # Used for screensaver, home screen
|
||||||
' - N3_FULL.parsed':[(600,800),0, 52,],
|
|
||||||
}
|
}
|
||||||
|
#Following are the sizes used with pre2.1.4 firmware
|
||||||
|
# COVER_FILE_ENDINGS = {
|
||||||
|
# ' - N3_LIBRARY_FULL.parsed':[(355,530),0, 99,], # Used for Details screen
|
||||||
|
## ' - N3_LIBRARY_FULL.parsed':[(600,800),0, 99,],
|
||||||
|
# ' - N3_LIBRARY_GRID.parsed':[(149,233),0, 99,], # Used for library lists
|
||||||
|
# ' - N3_LIBRARY_LIST.parsed':[(60,90),0, 53,],
|
||||||
|
# ' - N3_LIBRARY_SHELF.parsed': [(40,60),0, 52,],
|
||||||
|
# ' - N3_FULL.parsed':[(600,800),0, 99,], # Used for screensaver if "Full screen" is checked.
|
||||||
|
# }
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
super(KOBOTOUCH, self).initialize()
|
super(KOBOTOUCH, self).initialize()
|
||||||
@ -1422,6 +1430,7 @@ class KOBOTOUCH(KOBO):
|
|||||||
debug_print('KoboTouch:update_booklist - bookshelves=', bookshelves)
|
debug_print('KoboTouch:update_booklist - bookshelves=', bookshelves)
|
||||||
debug_print('KoboTouch:update_booklist - series="%s"' % bl[idx].series)
|
debug_print('KoboTouch:update_booklist - series="%s"' % bl[idx].series)
|
||||||
debug_print('KoboTouch:update_booklist - the book=', bl[idx])
|
debug_print('KoboTouch:update_booklist - the book=', bl[idx])
|
||||||
|
debug_print('KoboTouch:update_booklist - the authors=', bl[idx].authors)
|
||||||
debug_print('KoboTouch:update_booklist - application_id=', bl[idx].application_id)
|
debug_print('KoboTouch:update_booklist - application_id=', bl[idx].application_id)
|
||||||
bl_cache[lpath] = None
|
bl_cache[lpath] = None
|
||||||
if bl[idx].title_sort is not None:
|
if bl[idx].title_sort is not None:
|
||||||
@ -1438,20 +1447,15 @@ class KOBOTOUCH(KOBO):
|
|||||||
else:
|
else:
|
||||||
debug_print(" Strange: The file: ", prefix, lpath, " does not exist!")
|
debug_print(" Strange: The file: ", prefix, lpath, " does not exist!")
|
||||||
debug_print("KoboTouch:update_booklist - book size=", bl[idx].size)
|
debug_print("KoboTouch:update_booklist - book size=", bl[idx].size)
|
||||||
# if lpath in playlist_map and \
|
|
||||||
# playlist_map[lpath] not in bl[idx].device_collections:
|
|
||||||
# bl[idx].device_collections = playlist_map.get(lpath,[])
|
|
||||||
# changed = True
|
|
||||||
|
|
||||||
|
|
||||||
if show_debug:
|
if show_debug:
|
||||||
debug_print("KoboTouch:update_booklist - ContentID='%s'"%ContentID)
|
debug_print("KoboTouch:update_booklist - ContentID='%s'"%ContentID)
|
||||||
bl[idx].contentID = ContentID
|
bl[idx].contentID = ContentID
|
||||||
|
|
||||||
if lpath in playlist_map:
|
if lpath in playlist_map:
|
||||||
bl[idx].device_collections = playlist_map.get(lpath,[])
|
bl[idx].device_collections = playlist_map.get(lpath,[])
|
||||||
bl[idx].current_collections = bl[idx].device_collections
|
|
||||||
changed = True
|
changed = True
|
||||||
|
bl[idx].current_shelves = bookshelves
|
||||||
|
|
||||||
if show_debug:
|
if show_debug:
|
||||||
debug_print('KoboTouch:update_booklist - updated bl[idx].device_collections=', bl[idx].device_collections)
|
debug_print('KoboTouch:update_booklist - updated bl[idx].device_collections=', bl[idx].device_collections)
|
||||||
@ -1482,12 +1486,14 @@ class KOBOTOUCH(KOBO):
|
|||||||
debug_print('KoboTouch:update_booklist - class:', book.__class__)
|
debug_print('KoboTouch:update_booklist - class:', book.__class__)
|
||||||
# debug_print(' resolution:', book.__class__.__mro__)
|
# debug_print(' resolution:', book.__class__.__mro__)
|
||||||
debug_print(" contentid:'%s'"%book.contentID)
|
debug_print(" contentid:'%s'"%book.contentID)
|
||||||
debug_print(book)
|
debug_print(" title:'%s'"%book.title)
|
||||||
|
debug_print(" the book:", book)
|
||||||
debug_print(" author_sort:'%s'"%book.author_sort)
|
debug_print(" author_sort:'%s'"%book.author_sort)
|
||||||
|
debug_print(" bookshelves:", bookshelves)
|
||||||
|
|
||||||
# print 'Update booklist'
|
# print 'Update booklist'
|
||||||
book.device_collections = playlist_map.get(lpath,[])# if lpath in playlist_map else []
|
book.device_collections = playlist_map.get(lpath,[])# if lpath in playlist_map else []
|
||||||
book.current_collections = bl[idx].device_collections
|
book.current_shelves = bookshelves
|
||||||
book.contentID = ContentID
|
book.contentID = ContentID
|
||||||
# debug_print('KoboTouch:update_booklist - title=', title, 'book.device_collections', book.device_collections)
|
# debug_print('KoboTouch:update_booklist - title=', title, 'book.device_collections', book.device_collections)
|
||||||
|
|
||||||
@ -1526,16 +1532,16 @@ class KOBOTOUCH(KOBO):
|
|||||||
# return bytestrings if the content cannot the decoded as unicode
|
# return bytestrings if the content cannot the decoded as unicode
|
||||||
connection.text_factory = lambda x: unicode(x, "utf-8", "ignore")
|
connection.text_factory = lambda x: unicode(x, "utf-8", "ignore")
|
||||||
|
|
||||||
self.bookshelvelist = self.get_bookshelflist(connection)
|
|
||||||
|
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
|
||||||
cursor.execute('select version from dbversion')
|
cursor.execute('select version from dbversion')
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
self.dbversion = result[0]
|
self.dbversion = result[0]
|
||||||
|
|
||||||
debug_print("Database Version=%d"%self.dbversion)
|
debug_print("Database Version=%d"%self.dbversion)
|
||||||
|
|
||||||
|
self.bookshelvelist = self.get_bookshelflist(connection)
|
||||||
|
debug_print("KoboTouch:books - shelf list:", self.bookshelvelist)
|
||||||
|
|
||||||
opts = self.settings()
|
opts = self.settings()
|
||||||
if self.dbversion >= 33:
|
if self.dbversion >= 33:
|
||||||
query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, ' \
|
query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, ' \
|
||||||
@ -1623,14 +1629,15 @@ class KOBOTOUCH(KOBO):
|
|||||||
|
|
||||||
#print "count found in cache: %d, count of files in metadata: %d, need_sync: %s" % \
|
#print "count found in cache: %d, count of files in metadata: %d, need_sync: %s" % \
|
||||||
# (len(bl_cache), len(bl), need_sync)
|
# (len(bl_cache), len(bl), need_sync)
|
||||||
|
# Bypassing the KOBO sync_booklists as that does things we don't need to do
|
||||||
if need_sync: #self.count_found_in_bl != len(bl) or need_sync:
|
if need_sync: #self.count_found_in_bl != len(bl) or need_sync:
|
||||||
debug_print("KoboTouch:books - about to sync_booklists")
|
debug_print("KoboTouch:books - about to sync_booklists")
|
||||||
if oncard == 'cardb':
|
if oncard == 'cardb':
|
||||||
self.sync_booklists((None, None, bl))
|
USBMS.sync_booklists(self, (None, None, bl))
|
||||||
elif oncard == 'carda':
|
elif oncard == 'carda':
|
||||||
self.sync_booklists((None, bl, None))
|
USBMS.sync_booklists(self, (None, bl, None))
|
||||||
else:
|
else:
|
||||||
self.sync_booklists((bl, None, None))
|
USBMS.sync_booklists(self, (bl, None, None))
|
||||||
|
|
||||||
self.report_progress(1.0, _('Getting list of books on device...'))
|
self.report_progress(1.0, _('Getting list of books on device...'))
|
||||||
debug_print("KoboTouch:books - end - oncard='%s'"%oncard)
|
debug_print("KoboTouch:books - end - oncard='%s'"%oncard)
|
||||||
@ -2088,13 +2095,14 @@ class KOBOTOUCH(KOBO):
|
|||||||
|
|
||||||
def remove_book_from_device_bookshelves(self, connection, book):
|
def remove_book_from_device_bookshelves(self, connection, book):
|
||||||
show_debug = self.is_debugging_title(book.title)# or True
|
show_debug = self.is_debugging_title(book.title)# or True
|
||||||
|
|
||||||
remove_shelf_list = set(book.current_collections) - set(book.device_collections) - set(["Im_Reading", "Read", "Closed"])
|
remove_shelf_list = set(book.current_shelves) - set(book.device_collections)# - set(["Im_Reading", "Read", "Closed"])
|
||||||
|
|
||||||
if show_debug:
|
if show_debug:
|
||||||
debug_print('KoboTouch:remove_book_from_device_bookshelves - book.application_id="%s"'%book.application_id)
|
debug_print('KoboTouch:remove_book_from_device_bookshelves - book.application_id="%s"'%book.application_id)
|
||||||
debug_print('KoboTouch:remove_book_from_device_bookshelves - book.contentID="%s"'%book.contentID)
|
debug_print('KoboTouch:remove_book_from_device_bookshelves - book.contentID="%s"'%book.contentID)
|
||||||
debug_print('KoboTouch:remove_book_from_device_bookshelves - book.device_collections=', book.device_collections)
|
debug_print('KoboTouch:remove_book_from_device_bookshelves - book.device_collections=', book.device_collections)
|
||||||
|
debug_print('KoboTouch:remove_book_from_device_bookshelves - book.current_shelves=', book.current_shelves)
|
||||||
debug_print('KoboTouch:remove_book_from_device_bookshelves - remove_shelf_list=', remove_shelf_list)
|
debug_print('KoboTouch:remove_book_from_device_bookshelves - remove_shelf_list=', remove_shelf_list)
|
||||||
|
|
||||||
if len(remove_shelf_list) == 0:
|
if len(remove_shelf_list) == 0:
|
||||||
@ -2155,14 +2163,14 @@ class KOBOTOUCH(KOBO):
|
|||||||
if not self.supports_bookshelves():
|
if not self.supports_bookshelves():
|
||||||
return bookshelves
|
return bookshelves
|
||||||
|
|
||||||
query = 'SELECT Name FROM Shelf'
|
query = 'SELECT Name FROM Shelf WHERE _IsDeleted = "false"'
|
||||||
|
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
# count_bookshelves = 0
|
# count_bookshelves = 0
|
||||||
for i, row in enumerate(cursor):
|
for i, row in enumerate(cursor):
|
||||||
bookshelves.append(row[0])
|
bookshelves.append(row[0])
|
||||||
# count_bookshelves = i + 1
|
# count_bookshelves = i + 1
|
||||||
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
# debug_print("KoboTouch:get_bookshelflist - count bookshelves=" + unicode(count_bookshelves))
|
# debug_print("KoboTouch:get_bookshelflist - count bookshelves=" + unicode(count_bookshelves))
|
||||||
@ -2232,6 +2240,7 @@ class KOBOTOUCH(KOBO):
|
|||||||
connection.commit()
|
connection.commit()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
|
# Update the bookshelf list.
|
||||||
self.bookshelvelist = self.get_bookshelflist(connection)
|
self.bookshelvelist = self.get_bookshelflist(connection)
|
||||||
|
|
||||||
# debug_print("KoboTouch:set_bookshelf - end")
|
# debug_print("KoboTouch:set_bookshelf - end")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user