mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-07 09:01:38 -04:00
Kindle driver: Add option to not overwrite existing page number (apnx) files on the device when sending books to the device
Kindle driver: Add option to allow customization of the page number (apnx) generation algorithm based on values in a custom column Merge branch 'apnxfiles' of https://github.com/rpspringuel/calibre
This commit is contained in:
commit
57641e03dc
@ -323,16 +323,33 @@ class KINDLE2(KINDLE):
|
|||||||
' store the page count of books, you can have calibre use that'
|
' store the page count of books, you can have calibre use that'
|
||||||
' information, instead of calculating a page count. Specify the'
|
' information, instead of calculating a page count. Specify the'
|
||||||
' name of the custom column here, for example, #pages.'),
|
' name of the custom column here, for example, #pages.'),
|
||||||
|
_('Custom column name to retrieve calculation method from') + ':::' + _(
|
||||||
|
'If you have a custom column in your library that you use to'
|
||||||
|
' store the preferred method for calculating the number of pages'
|
||||||
|
' for a book, you can have calibre use that method instead of the'
|
||||||
|
' default one selected above. Specify the name of the custom'
|
||||||
|
' column here, for example, #pagemethod.'),
|
||||||
|
_('Overwrite existing apnx on device') + ':::' + _(
|
||||||
|
'Uncheck this option to allow an apnx file existing on the device'
|
||||||
|
' to have priority over the version which calibre would send.'
|
||||||
|
' Since apnx files are usually deleted when a book is removed from'
|
||||||
|
' the Kindle, this is mostly useful when resending a book to the'
|
||||||
|
' device which is already on the device (e.g. after making a'
|
||||||
|
' modification.)'),
|
||||||
|
|
||||||
]
|
]
|
||||||
EXTRA_CUSTOMIZATION_DEFAULT = [
|
EXTRA_CUSTOMIZATION_DEFAULT = [
|
||||||
True,
|
True,
|
||||||
'fast',
|
'fast',
|
||||||
'',
|
'',
|
||||||
|
'',
|
||||||
|
True,
|
||||||
]
|
]
|
||||||
OPT_APNX = 0
|
OPT_APNX = 0
|
||||||
OPT_APNX_METHOD = 1
|
OPT_APNX_METHOD = 1
|
||||||
OPT_APNX_CUST_COL = 2
|
OPT_APNX_CUST_COL = 2
|
||||||
|
OPT_APNX_METHOD_COL = 3
|
||||||
|
OPT_APNX_OVERWRITE = 4
|
||||||
EXTRA_CUSTOMIZATION_CHOICES = {OPT_APNX_METHOD:{'fast', 'accurate', 'pagebreak'}}
|
EXTRA_CUSTOMIZATION_CHOICES = {OPT_APNX_METHOD:{'fast', 'accurate', 'pagebreak'}}
|
||||||
|
|
||||||
# x330 on the PaperWhite
|
# x330 on the PaperWhite
|
||||||
@ -456,13 +473,26 @@ class KINDLE2(KINDLE):
|
|||||||
|
|
||||||
apnx_path = '%s.apnx' % os.path.join(path, filename)
|
apnx_path = '%s.apnx' % os.path.join(path, filename)
|
||||||
apnx_builder = APNXBuilder()
|
apnx_builder = APNXBuilder()
|
||||||
try:
|
# ## Check to see if there is an existing apnx file on Kindle we should keep.
|
||||||
method = opts.extra_customization[self.OPT_APNX_METHOD]
|
if opts.extra_customization[self.OPT_APNX_OVERWRITE] or not os.path.exists(apnx_path):
|
||||||
apnx_builder.write_apnx(filepath, apnx_path, method=method, page_count=custom_page_count)
|
try:
|
||||||
except:
|
method = opts.extra_customization[self.OPT_APNX_METHOD]
|
||||||
print 'Failed to generate APNX'
|
cust_col_name = opts.extra_customization[self.OPT_APNX_METHOD_COL]
|
||||||
import traceback
|
if cust_col_name:
|
||||||
traceback.print_exc()
|
try:
|
||||||
|
temp = unicode(metadata.get(cust_col_name, 0))
|
||||||
|
if temp in self.EXTRA_CUSTOMIZATION_CHOICES[self.OPT_APNX_METHOD]:
|
||||||
|
method = temp
|
||||||
|
else:
|
||||||
|
print "Invalid method choice for this book, reverting to default."
|
||||||
|
except:
|
||||||
|
print 'Could not retrieve override method choice, reverting to default.'
|
||||||
|
print 'Generating apnx with', method
|
||||||
|
apnx_builder.write_apnx(filepath, apnx_path, method=method, page_count=custom_page_count)
|
||||||
|
except:
|
||||||
|
print 'Failed to generate APNX'
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
|
||||||
class KINDLE_DX(KINDLE2):
|
class KINDLE_DX(KINDLE2):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user