mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
Wireless driver: Always replace file when resending a previously sent book to the device, even if the title/author have changed.
This commit is contained in:
commit
2f3dde257e
@ -300,19 +300,21 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
||||
'particular IP address. The driver will listen only on the '
|
||||
'entered address, and this address will be the one advertized '
|
||||
'over mDNS (bonjour).') + '</p>',
|
||||
_('Replace books with the same calibre identifier') + ':::<p>' +
|
||||
_('Use this option to overwrite a book on the device if that book '
|
||||
'has the same calibre identifier as the book being sent. The file name of the '
|
||||
'book will not change even if the save template produces a '
|
||||
'different result. Using this option in most cases prevents '
|
||||
'having multiple copies of a book on the device.') + '</p>',
|
||||
]
|
||||
EXTRA_CUSTOMIZATION_DEFAULT = [
|
||||
False,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
False, '',
|
||||
'', '',
|
||||
False, '9090',
|
||||
False,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
True,
|
||||
''
|
||||
False, '',
|
||||
'', '',
|
||||
True, '',
|
||||
True
|
||||
]
|
||||
OPT_AUTOSTART = 0
|
||||
OPT_PASSWORD = 2
|
||||
@ -322,6 +324,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
||||
OPT_COLLECTIONS = 8
|
||||
OPT_AUTODISCONNECT = 10
|
||||
OPT_FORCE_IP_ADDRESS = 11
|
||||
OPT_OVERWRITE_BOOKS_UUID = 12
|
||||
|
||||
|
||||
def __init__(self, path):
|
||||
@ -386,8 +389,14 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
||||
ext = os.path.splitext(fname)[1]
|
||||
|
||||
try:
|
||||
# If we have already seen this book's UUID, use the existing path
|
||||
if self.settings().extra_customization[self.OPT_OVERWRITE_BOOKS_UUID]:
|
||||
existing_book = self._uuid_already_on_device(mdata.uuid)
|
||||
if existing_book and existing_book.lpath:
|
||||
return existing_book.lpath
|
||||
|
||||
# If the device asked for it, try to use the UUID as the file name.
|
||||
# Fall back to the template if the UUID doesn't exist.
|
||||
# Fall back to the ch if the UUID doesn't exist.
|
||||
if self.client_wants_uuid_file_names and mdata.uuid:
|
||||
return (mdata.uuid + ext)
|
||||
except:
|
||||
@ -679,12 +688,20 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
||||
return not v_thumb or v_thumb[1] == b_thumb[1]
|
||||
return False
|
||||
|
||||
def _uuid_already_on_device(self, uuid):
|
||||
return self.known_uuids.get(uuid, None)
|
||||
|
||||
def _set_known_metadata(self, book, remove=False):
|
||||
lpath = book.lpath
|
||||
uuid = book.get('uuid', None)
|
||||
if remove:
|
||||
self.known_metadata.pop(lpath, None)
|
||||
if uuid:
|
||||
self.known_uuids.pop(uuid, None)
|
||||
else:
|
||||
self.known_metadata[lpath] = book.deepcopy()
|
||||
new_book = self.known_metadata[lpath] = book.deepcopy()
|
||||
if uuid:
|
||||
self.known_uuids[uuid] = new_book
|
||||
|
||||
def _close_device_socket(self):
|
||||
if self.device_socket is not None:
|
||||
@ -1097,6 +1114,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
||||
for i, infile in enumerate(files):
|
||||
mdata, fname = metadata.next(), names.next()
|
||||
lpath = self._create_upload_path(mdata, fname, create_dirs=False)
|
||||
self._debug('lpath', lpath)
|
||||
if not hasattr(infile, 'read'):
|
||||
infile = USBMS.normalize_path(infile)
|
||||
book = SDBook(self.PREFIX, lpath, other=mdata)
|
||||
@ -1258,6 +1276,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
||||
self.device_socket = None
|
||||
self.json_codec = JsonCodec()
|
||||
self.known_metadata = {}
|
||||
self.known_uuids = {}
|
||||
self.debug_time = time.time()
|
||||
self.debug_start_time = time.time()
|
||||
self.max_book_packet_len = 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user