mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
APNX generation for MTP devices
This commit is contained in:
parent
4515dfbc85
commit
8a2b027e39
@ -544,6 +544,8 @@ class MTP_DEVICE(BASE):
|
|||||||
mtp_file = self.put_file(parent, path[-1], stream, sz)
|
mtp_file = self.put_file(parent, path[-1], stream, sz)
|
||||||
try:
|
try:
|
||||||
self.upload_cover(parent, relpath, storage, mi, stream)
|
self.upload_cover(parent, relpath, storage, mi, stream)
|
||||||
|
# Upload the apnx file
|
||||||
|
self.upload_apnx(parent, fname, storage, mi, infile)
|
||||||
except Exception:
|
except Exception:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
@ -632,6 +634,37 @@ class MTP_DEVICE(BASE):
|
|||||||
debug(f'Restored {count} cover thumbnails that were destroyed by Amazon')
|
debug(f'Restored {count} cover thumbnails that were destroyed by Amazon')
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
def upload_apnx(self, parent, filename, storage, mi, filepath):
|
||||||
|
from calibre.devices.kindle.apnx import APNXBuilder
|
||||||
|
apnx_builder = APNXBuilder()
|
||||||
|
|
||||||
|
name = filename.rpartition('.')[0]
|
||||||
|
apnx_filename = f'{name[:-2]}.apnx'
|
||||||
|
apnx_local_path = f'{os.path.join('/tmp', apnx_filename)}'
|
||||||
|
|
||||||
|
try:
|
||||||
|
# TODO
|
||||||
|
method = None
|
||||||
|
custom_page_count = 100
|
||||||
|
|
||||||
|
apnx_builder.write_apnx(filepath, apnx_local_path, method=method, page_count=custom_page_count)
|
||||||
|
|
||||||
|
apnx_size = os.path.getsize(apnx_local_path)
|
||||||
|
apnx_stream = open(apnx_local_path, 'rb')
|
||||||
|
|
||||||
|
try:
|
||||||
|
apnx_path = parent.name, f'{name[:-2]}.sdr', apnx_filename
|
||||||
|
sdr_parent = self.ensure_parent(storage, apnx_path)
|
||||||
|
self.put_file(sdr_parent, apnx_filename, apnx_stream, apnx_size)
|
||||||
|
finally:
|
||||||
|
apnx_stream.close()
|
||||||
|
except:
|
||||||
|
print('Failed to generate APNX')
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
finally:
|
||||||
|
os.remove(apnx_local_path)
|
||||||
|
|
||||||
def add_books_to_metadata(self, mtp_files, metadata, booklists):
|
def add_books_to_metadata(self, mtp_files, metadata, booklists):
|
||||||
debug('add_books_to_metadata() called')
|
debug('add_books_to_metadata() called')
|
||||||
from calibre.devices.mtp.books import Book
|
from calibre.devices.mtp.books import Book
|
||||||
|
Loading…
x
Reference in New Issue
Block a user