mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Get the device path for matched books - the kobo stores kepubs in its own directory structure. This lays the groundwork for adding annotations support to the Kobo driver
This commit is contained in:
parent
8e7a444ae3
commit
05275a3098
@ -77,6 +77,11 @@ class KOBO(USBMS):
|
|||||||
self.book_class = Book
|
self.book_class = Book
|
||||||
self.dbversion = 7
|
self.dbversion = 7
|
||||||
|
|
||||||
|
def create_annotations_path(self, mdata, device_path=None):
|
||||||
|
if device_path:
|
||||||
|
return device_path
|
||||||
|
return USBMS.create_annotations_path(self, mdata)
|
||||||
|
|
||||||
def books(self, oncard=None, end_session=True):
|
def books(self, oncard=None, end_session=True):
|
||||||
from calibre.ebooks.metadata.meta import path_to_ext
|
from calibre.ebooks.metadata.meta import path_to_ext
|
||||||
|
|
||||||
|
@ -1147,3 +1147,6 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
os.makedirs(filedir)
|
os.makedirs(filedir)
|
||||||
|
|
||||||
return filepath
|
return filepath
|
||||||
|
|
||||||
|
def create_annotations_path(self, mdata, device_path=None):
|
||||||
|
return self.create_upload_path(os.path.abspath('/<storage>'), mdata, 'x.bookmark', create_dirs=False)
|
||||||
|
@ -41,13 +41,21 @@ class FetchAnnotationsAction(InterfaceAction):
|
|||||||
fmts.append(format.lower())
|
fmts.append(format.lower())
|
||||||
return fmts
|
return fmts
|
||||||
|
|
||||||
|
def get_device_path_from_id(id_):
|
||||||
|
paths = []
|
||||||
|
for x in ('memory', 'card_a', 'card_b'):
|
||||||
|
x = getattr(self.gui, x+'_view').model()
|
||||||
|
paths += x.paths_for_db_ids(set([id_]), as_map=True)[id_]
|
||||||
|
return paths[0].path if paths else None
|
||||||
|
|
||||||
def generate_annotation_paths(ids, db, device):
|
def generate_annotation_paths(ids, db, device):
|
||||||
# Generate path templates
|
# Generate path templates
|
||||||
# Individual storage mount points scanned/resolved in driver.get_annotations()
|
# Individual storage mount points scanned/resolved in driver.get_annotations()
|
||||||
path_map = {}
|
path_map = {}
|
||||||
for id in ids:
|
for id in ids:
|
||||||
|
path = get_device_path_from_id(id)
|
||||||
mi = db.get_metadata(id, index_is_id=True)
|
mi = db.get_metadata(id, index_is_id=True)
|
||||||
a_path = device.create_upload_path(os.path.abspath('/<storage>'), mi, 'x.bookmark', create_dirs=False)
|
a_path = device.create_annotations_path(mi, path)
|
||||||
path_map[id] = dict(path=a_path, fmts=get_formats(id))
|
path_map[id] = dict(path=a_path, fmts=get_formats(id))
|
||||||
return path_map
|
return path_map
|
||||||
|
|
||||||
|
@ -1239,11 +1239,14 @@ class DeviceBooksModel(BooksModel): # {{{
|
|||||||
def paths(self, rows):
|
def paths(self, rows):
|
||||||
return [self.db[self.map[r.row()]].path for r in rows ]
|
return [self.db[self.map[r.row()]].path for r in rows ]
|
||||||
|
|
||||||
def paths_for_db_ids(self, db_ids):
|
def paths_for_db_ids(self, db_ids, as_map=False):
|
||||||
res = []
|
res = defaultdict(list) if as_map else []
|
||||||
for r,b in enumerate(self.db):
|
for r,b in enumerate(self.db):
|
||||||
if b.application_id in db_ids:
|
if b.application_id in db_ids:
|
||||||
res.append((r,b))
|
if as_map:
|
||||||
|
res[b.application_id].append(b)
|
||||||
|
else:
|
||||||
|
res.append((r,b))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def get_collections_with_ids(self):
|
def get_collections_with_ids(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user