Quote:
Originally Posted by chaley
Sorry, I didn't notice this edit.
Depending on when you subclassed the driver and depending on what methods you overloaded, you might be missing some of the CC/calibre "feature negotiation". The two programs converse about what each is capable of doing and pick the common subset.
In particular I suspect that the canSupportLpathChanges options introduced somewhere around calibre 2.30 might be missing in your version, especially if you overloaded _put_file.
|
I'm tempted to say 'forget about it'. For personal consumption (I only ever use WiFi to transfer) my hack seems to work just as well as it ever has. I've chosen
Settings - Filenames - Use CC template everywhere/Replace existing book files as my new standard setting.
I just retested with v5.0.1.1 beta and calibre v2.51 (32bit). All is well with file- naming & renaming when using CC-WiFi with hacked driver.
If you want to know more - and I won't blame you if you don't - I mean, you could be doing useful stuff for thousands of paying customers who aren't trying to be a bit too clever for their own good

...
As far as I can tell the only smart_device_app method affected would be
upload_books. But even there, my hack only does 2 minor edits to an epub's CSS files (using the official calibre container) before handing back to the official smart_device_app upload_books method.
This is the whole of the hacked driver, it's very small. Its purpose is to allow fully working custom fonts in epubs, without embedding. Many Android reader apps claim to do this, unfortunately most of them make a holy mess of it (IMO). At least with the hack I can get Mantano and Pocketbook to display reg/ital/bold/boldital correctly without sacrificing sans-serif/monospace along the way.
Spoiler:
Code:
import os
from calibre.devices.smart_device_app.driver import SMART_DEVICE_APP
from calibre.devices.usbms.driver import debug_print
from calibre.ebooks.oeb.polish.container import get_container
EPUB_EXT = '.epub'
SMART_DEVICE_APP_IMPRULE = '@import url(res:///../mantano.css);'
SMART_DEVICE_APP_ADDRULE = 'body {font-family: serif}'
class SMART_DEVICE_APP_CSSADD(SMART_DEVICE_APP):
''' Tweaked driver for Calibre Companion Android device.
This driver automatically modifies ePub files by inserting a
CSS import rule as 1st rule of each css file. E.g.
@import url(res:///../external_sd/ebooks/mantano.css);
Then all files are transferred as normal '''
name = 'Smart_Device_App_CSSAdd'
author = 'jackie_w'
description = 'Communicate with Calibre Companion Android device. Based on the existing SMART_DEVICE_APP driver by chaley. Inserts CSS import rule to epub existing CSS file(s).'
minimum_calibre_version = (0, 9, 29)
version = (0, 0, 3)
def initialize(self):
super(SMART_DEVICE_APP_CSSADD, self).initialize()
def _modify_epub(self, file, metadata):
debug_print("Smart_Device_App_CSSAdd:_modify_epub:Processing {0} - {1}".format(metadata.author_sort, metadata.title))
container = get_container(file)
cssnames = [n for n in container.name_path_map if n.endswith('.css')]
for cssname in cssnames:
newsheet = container.parsed(cssname)
oldrules = len(newsheet.cssRules)
# insert @import rule as first rule
newsheet.insertRule(SMART_DEVICE_APP_IMPRULE, 0)
# append constant rule as last rule
newsheet.insertRule(SMART_DEVICE_APP_ADDRULE, len(newsheet.cssRules))
debug_print("Smart_Device_App_CSSAdd:_modify_epub:CSS rules {0} -> {1} ({2})".format(oldrules, len(newsheet.cssRules), cssname))
container.dirty(cssname)
container.commit()
return True
def upload_books(self, files, names, on_card = None, end_session = True, metadata = None):
new_files = []
new_names = []
new_metadata = []
i = 0
for file, n, mi in zip(files, names, metadata):
self.report_progress(i / float(len(files)), "Processing book: {0} by {1}".format(mi.title, " and ".join(mi.authors)))
ext = file[file.rfind('.'):]
if ext == EPUB_EXT:
self._modify_epub(file, mi)
new_files.append(file)
new_names.append(n)
new_metadata.append(mi)
else:
new_files.append(file)
new_names.append(n)
new_metadata.append(mi)
i += 1
self.report_progress(0, 'Working...')
result = super(SMART_DEVICE_APP_CSSADD, self).upload_books(new_files, new_names, on_card, end_session, new_metadata)
return result