mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
MTP: Implement format routing
This commit is contained in:
parent
d26bf70d54
commit
4b8933f9fb
@ -274,9 +274,12 @@ class MTP_DEVICE(BASE):
|
|||||||
self.plugboards = plugboards
|
self.plugboards = plugboards
|
||||||
self.plugboard_func = pb_func
|
self.plugboard_func = pb_func
|
||||||
|
|
||||||
def create_upload_path(self, path, mdata, fname):
|
def create_upload_path(self, path, mdata, fname, routing):
|
||||||
from calibre.devices.utils import create_upload_path
|
from calibre.devices.utils import create_upload_path
|
||||||
from calibre.utils.filenames import ascii_filename as sanitize
|
from calibre.utils.filenames import ascii_filename as sanitize
|
||||||
|
ext = fname.rpartition('.')[-1].lower()
|
||||||
|
path = routing.get(ext, path)
|
||||||
|
|
||||||
filepath = create_upload_path(mdata, fname, self.save_template, sanitize,
|
filepath = create_upload_path(mdata, fname, self.save_template, sanitize,
|
||||||
prefix_path=path,
|
prefix_path=path,
|
||||||
path_type=posixpath,
|
path_type=posixpath,
|
||||||
@ -330,8 +333,10 @@ class MTP_DEVICE(BASE):
|
|||||||
self.report_progress(0, _('Transferring books to device...'))
|
self.report_progress(0, _('Transferring books to device...'))
|
||||||
i, total = 0, len(files)
|
i, total = 0, len(files)
|
||||||
|
|
||||||
|
routing = {fmt:dest for fmt,dest in self.get_pref('rules')}
|
||||||
|
|
||||||
for infile, fname, mi in izip(files, names, metadata):
|
for infile, fname, mi in izip(files, names, metadata):
|
||||||
path = self.create_upload_path(prefix, mi, fname)
|
path = self.create_upload_path(prefix, mi, fname, routing)
|
||||||
parent = self.ensure_parent(storage, path)
|
parent = self.ensure_parent(storage, path)
|
||||||
if hasattr(infile, 'read'):
|
if hasattr(infile, 'read'):
|
||||||
pos = infile.tell()
|
pos = infile.tell()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user