Merge pull request #32 from karimknaebel/feat-upload-template

Add configurable upload template
This commit is contained in:
Justin Mitchell
2026-07-15 11:00:51 -04:00
committed by GitHub
3 changed files with 14 additions and 4 deletions
+1
View File
@@ -15,6 +15,7 @@ Default settings:
- Host fallback: 192.168.4.1
- Port: 81
- Upload path: /
- Upload template: blank, which uses Calibre's send-to-device template
- Upload reliability: 3 retries, 2s retry delay, 1s delay between books,
30s socket timeout
+8 -1
View File
@@ -27,6 +27,7 @@ PREFS.defaults['chunk_size'] = 2048
PREFS.defaults['debug'] = False
PREFS.defaults['fetch_metadata'] = False
PREFS.defaults['send_to_root'] = False
PREFS.defaults['upload_template'] = ''
PREFS.defaults['upload_retries'] = 3
PREFS.defaults['retry_delay'] = 2
PREFS.defaults['book_cooldown'] = 1
@@ -43,10 +44,12 @@ class CrossPointConfigWidget(QWidget):
def __init__(self):
super().__init__()
layout = QFormLayout(self)
layout.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.ExpandingFieldsGrow)
self.host = QLineEdit(self)
self.port = QSpinBox(self)
self.port.setRange(1, 65535)
self.path = QLineEdit(self)
self.upload_template = QLineEdit(self)
self.chunk_size = QSpinBox(self)
self.chunk_size.setRange(512, 65536)
self.upload_retries = QSpinBox(self)
@@ -62,7 +65,7 @@ class CrossPointConfigWidget(QWidget):
self.socket_timeout.setSuffix(' s')
self.debug = QCheckBox('Enable debug logging', self)
self.fetch_metadata = QCheckBox('Fetch metadata for side-loaded books (downloads each once on connect)', self)
self.send_to_root = QCheckBox('Send to root (ignore folder template)', self)
self.send_to_root = QCheckBox('Send to root (ignore any template)', self)
# Optimizer controls.
self.optimize = QCheckBox('Optimize EPUBs before transfer', self)
@@ -79,6 +82,8 @@ class CrossPointConfigWidget(QWidget):
self.host.setText(PREFS['host'])
self.port.setValue(PREFS['port'])
self.path.setText(PREFS['path'])
self.upload_template.setText(PREFS['upload_template'])
self.upload_template.setPlaceholderText("Leave blank to use Calibre's send-to-device template")
self.chunk_size.setValue(PREFS['chunk_size'])
self.upload_retries.setValue(PREFS['upload_retries'])
self.retry_delay.setValue(PREFS['retry_delay'])
@@ -103,6 +108,7 @@ class CrossPointConfigWidget(QWidget):
layout.addRow('', notice)
layout.addRow('Upload path', self.path)
layout.addRow('Upload template', self.upload_template)
layout.addRow('Chunk size', self.chunk_size)
reliability_heading = QLabel('<b>Upload reliability</b>')
@@ -159,6 +165,7 @@ class CrossPointConfigWidget(QWidget):
PREFS['host'] = self.host.text().strip() or PREFS.defaults['host']
PREFS['port'] = int(self.port.value())
PREFS['path'] = self.path.text().strip() or PREFS.defaults['path']
PREFS['upload_template'] = self.upload_template.text().strip()
PREFS['chunk_size'] = int(self.chunk_size.value())
PREFS['upload_retries'] = int(self.upload_retries.value())
PREFS['retry_delay'] = int(self.retry_delay.value())
+5 -3
View File
@@ -269,7 +269,7 @@ class CrossPointDevice(DeviceConfig, DevicePlugin):
return 10 * 1024 * 1024 * 1024, 0, 0
def _format_upload_path(self, mi, original_name):
"""Format an upload path using the send-to-device template.
"""Format an upload path using the configured upload template.
Returns (subdirs, filename) where subdirs is a list of directory
components from the template (may be empty for flat templates).
@@ -278,9 +278,11 @@ class CrossPointDevice(DeviceConfig, DevicePlugin):
from calibre.library.save_to_disk import config as sconfig, get_components
from calibre.utils.filenames import ascii_filename
template = self.save_template()
template = PREFS['upload_template']
if not template:
template = sconfig().parse().send_template
template = self.save_template()
if not template:
template = sconfig().parse().send_template
# get_component_metadata sets format_args['id'] = str(book_id),
# so we must pass the actual Calibre database ID instead of -1.