mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Moved db_id addition to USBMS. Added db_ids to Jetbook and Kindle overrides. Refactored index_is_id out, since it was always True. Implemented db_id lookup in the on_library cache.
This commit is contained in:
parent
83447f533c
commit
27635f58f9
@ -55,7 +55,13 @@ class JETBOOK(USBMS):
|
|||||||
au = mi.format_authors()
|
au = mi.format_authors()
|
||||||
if not au:
|
if not au:
|
||||||
au = 'Unknown'
|
au = 'Unknown'
|
||||||
return '%s#%s%s' % (au, title, fileext)
|
suffix = ''
|
||||||
|
if getattr(mi, 'application_id', None) is not None:
|
||||||
|
base = fname.rpartition('.')[0]
|
||||||
|
suffix = '_%s'%mi.application_id
|
||||||
|
if base.endswith(suffix):
|
||||||
|
suffix = ''
|
||||||
|
return '%s#%s%s%s' % (au, title, fileext, suffix)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def metadata_from_path(cls, path):
|
def metadata_from_path(cls, path):
|
||||||
|
@ -61,6 +61,11 @@ class KINDLE(USBMS):
|
|||||||
return mi
|
return mi
|
||||||
|
|
||||||
def filename_callback(self, fname, mi):
|
def filename_callback(self, fname, mi):
|
||||||
|
if getattr(mi, 'application_id', None) is not None:
|
||||||
|
base = fname.rpartition('.')[0]
|
||||||
|
suffix = '_%s'%mi.application_id
|
||||||
|
if not base.endswith(suffix):
|
||||||
|
fname = base + suffix + '.' + fname.rpartition('.')[-1]
|
||||||
if fname.startswith('.'):
|
if fname.startswith('.'):
|
||||||
return 'x'+fname[1:]
|
return 'x'+fname[1:]
|
||||||
return fname
|
return fname
|
||||||
|
@ -121,14 +121,6 @@ class PRS505(CLI, Device):
|
|||||||
self.report_progress(1.0, _('Getting list of books on device...'))
|
self.report_progress(1.0, _('Getting list of books on device...'))
|
||||||
return bl
|
return bl
|
||||||
|
|
||||||
def filename_callback(self, fname, mi):
|
|
||||||
if getattr(mi, 'application_id', None) is not None:
|
|
||||||
base = fname.rpartition('.')[0]
|
|
||||||
suffix = '_%s'%mi.application_id
|
|
||||||
if not base.endswith(suffix):
|
|
||||||
fname = base + suffix + '.' + fname.rpartition('.')[-1]
|
|
||||||
return fname
|
|
||||||
|
|
||||||
def upload_books(self, files, names, on_card=None, end_session=True,
|
def upload_books(self, files, names, on_card=None, end_session=True,
|
||||||
metadata=None):
|
metadata=None):
|
||||||
|
|
||||||
|
@ -784,8 +784,14 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
def filename_callback(self, default, mi):
|
def filename_callback(self, default, mi):
|
||||||
'''
|
'''
|
||||||
Callback to allow drivers to change the default file name
|
Callback to allow drivers to change the default file name
|
||||||
set by :method:`create_upload_path`.
|
set by :method:`create_upload_path`. By default, add the DB_ID
|
||||||
|
to the end of the string. Helps with ondevice doc matching
|
||||||
'''
|
'''
|
||||||
|
if getattr(mi, 'application_id', None) is not None:
|
||||||
|
base = default.rpartition('.')[0]
|
||||||
|
suffix = '_%s'%mi.application_id
|
||||||
|
if not base.endswith(suffix):
|
||||||
|
default = base + suffix + '.' + default.rpartition('.')[-1]
|
||||||
return default
|
return default
|
||||||
|
|
||||||
def sanitize_path_components(self, components):
|
def sanitize_path_components(self, components):
|
||||||
|
@ -979,7 +979,7 @@ class DeviceGUI(object):
|
|||||||
if memory and memory[1]:
|
if memory and memory[1]:
|
||||||
self.library_view.model().delete_books_by_id(memory[1])
|
self.library_view.model().delete_books_by_id(memory[1])
|
||||||
|
|
||||||
def book_on_device(self, index, index_is_id=False, format=None, reset=False):
|
def book_on_device(self, index, format=None, reset=False):
|
||||||
loc = [None, None, None]
|
loc = [None, None, None]
|
||||||
|
|
||||||
if reset:
|
if reset:
|
||||||
@ -1001,9 +1001,9 @@ class DeviceGUI(object):
|
|||||||
self.book_on_device_cache[i][book_title]['authors'].add(book_authors)
|
self.book_on_device_cache[i][book_title]['authors'].add(book_authors)
|
||||||
self.book_on_device_cache[i][book_title]['db_ids'].add(book.db_id)
|
self.book_on_device_cache[i][book_title]['db_ids'].add(book.db_id)
|
||||||
|
|
||||||
db_title = self.library_view.model().db.title(index, index_is_id).lower()
|
db_title = self.library_view.model().db.title(index, index_is_id=True).lower()
|
||||||
db_title = re.sub('(?u)\W|[_]', '', db_title)
|
db_title = re.sub('(?u)\W|[_]', '', db_title)
|
||||||
au = self.library_view.model().db.authors(index, index_is_id)
|
au = self.library_view.model().db.authors(index, index_is_id=True)
|
||||||
db_authors = au.lower() if au else ''
|
db_authors = au.lower() if au else ''
|
||||||
db_authors = re.sub('(?u)\W|[_]', '', db_authors)
|
db_authors = re.sub('(?u)\W|[_]', '', db_authors)
|
||||||
for i, l in enumerate(self.booklists()):
|
for i, l in enumerate(self.booklists()):
|
||||||
@ -1022,19 +1022,25 @@ class DeviceGUI(object):
|
|||||||
cache = {}
|
cache = {}
|
||||||
for id, title in self.library_view.model().db.all_titles():
|
for id, title in self.library_view.model().db.all_titles():
|
||||||
title = re.sub('(?u)\W|[_]', '', title.lower())
|
title = re.sub('(?u)\W|[_]', '', title.lower())
|
||||||
|
if title not in cache:
|
||||||
|
cache[title] = {'authors':set(), 'db_ids':set()}
|
||||||
au = self.library_view.model().db.authors(id, index_is_id=True)
|
au = self.library_view.model().db.authors(id, index_is_id=True)
|
||||||
authors = au.lower() if au else ''
|
authors = au.lower() if au else ''
|
||||||
authors = re.sub('(?u)\W|[_]', '', authors)
|
authors = re.sub('(?u)\W|[_]', '', authors)
|
||||||
cache[title+authors] = id
|
cache[title]['authors'].add(authors)
|
||||||
|
cache[title]['db_ids'].add(id)
|
||||||
|
|
||||||
# Now iterate through all the books on the device, setting the in_library field
|
# Now iterate through all the books on the device, setting the in_library field
|
||||||
for book in booklist:
|
for book in booklist:
|
||||||
book_title = book.title.lower() if book.title else ''
|
book_title = book.title.lower() if book.title else ''
|
||||||
book_title = re.sub('(?u)\W|[_]', '', book_title)
|
book_title = re.sub('(?u)\W|[_]', '', book_title)
|
||||||
book_authors = authors_to_string(book.authors).lower() if book.authors else ''
|
book.in_library = False
|
||||||
book_authors = re.sub('(?u)\W|[_]', '', book_authors)
|
d = cache.get(book_title, None)
|
||||||
|
if d is not None:
|
||||||
if cache.get(book_title + book_authors, None) is not None:
|
if book.db_id in d['db_ids']:
|
||||||
book.in_library = True
|
book.in_library = True
|
||||||
else:
|
continue
|
||||||
book.in_library = False
|
book_authors = authors_to_string(book.authors).lower() if book.authors else ''
|
||||||
|
book_authors = re.sub('(?u)\W|[_]', '', book_authors)
|
||||||
|
if book_authors in d['authors']:
|
||||||
|
book.in_library = True
|
||||||
|
@ -518,7 +518,7 @@ class ResultCache(SearchQueryParser):
|
|||||||
try:
|
try:
|
||||||
self._data[id] = db.conn.get('SELECT * from meta2 WHERE id=?', (id,))[0]
|
self._data[id] = db.conn.get('SELECT * from meta2 WHERE id=?', (id,))[0]
|
||||||
self._data[id].append(db.has_cover(id, index_is_id=True))
|
self._data[id].append(db.has_cover(id, index_is_id=True))
|
||||||
self._data[id].append(db.book_on_device_string(id, index_is_id=True))
|
self._data[id].append(db.book_on_device_string(id))
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
@ -534,7 +534,7 @@ class ResultCache(SearchQueryParser):
|
|||||||
for id in ids:
|
for id in ids:
|
||||||
self._data[id] = db.conn.get('SELECT * from meta2 WHERE id=?', (id,))[0]
|
self._data[id] = db.conn.get('SELECT * from meta2 WHERE id=?', (id,))[0]
|
||||||
self._data[id].append(db.has_cover(id, index_is_id=True))
|
self._data[id].append(db.has_cover(id, index_is_id=True))
|
||||||
self._data[id].append(db.book_on_device_string(id, index_is_id=True))
|
self._data[id].append(db.book_on_device_string(id))
|
||||||
self._map[0:0] = ids
|
self._map[0:0] = ids
|
||||||
self._map_filtered[0:0] = ids
|
self._map_filtered[0:0] = ids
|
||||||
|
|
||||||
@ -555,7 +555,7 @@ class ResultCache(SearchQueryParser):
|
|||||||
for item in self._data:
|
for item in self._data:
|
||||||
if item is not None:
|
if item is not None:
|
||||||
item.append(db.has_cover(item[0], index_is_id=True))
|
item.append(db.has_cover(item[0], index_is_id=True))
|
||||||
item.append(db.book_on_device_string(item[0], index_is_id=True))
|
item.append(db.book_on_device_string(item[0]))
|
||||||
self._map = [i[0] for i in self._data if i is not None]
|
self._map = [i[0] for i in self._data if i is not None]
|
||||||
if field is not None:
|
if field is not None:
|
||||||
self.sort(field, ascending)
|
self.sort(field, ascending)
|
||||||
|
@ -470,14 +470,14 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
im = PILImage.open(f)
|
im = PILImage.open(f)
|
||||||
im.convert('RGB').save(path, 'JPEG')
|
im.convert('RGB').save(path, 'JPEG')
|
||||||
|
|
||||||
def book_on_device(self, index, index_is_id=False):
|
def book_on_device(self, index):
|
||||||
if self.book_on_device_func:
|
if self.book_on_device_func:
|
||||||
return self.book_on_device_func(index, index_is_id)
|
return self.book_on_device_func(index)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def book_on_device_string(self, index, index_is_id=False):
|
def book_on_device_string(self, index):
|
||||||
loc = []
|
loc = []
|
||||||
on = self.book_on_device(index, index_is_id)
|
on = self.book_on_device(index)
|
||||||
if on is not None:
|
if on is not None:
|
||||||
m, a, b = on
|
m, a, b = on
|
||||||
if m is not None:
|
if m is not None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user