mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Refactor sending cover to device. Nook: Send cover with book to device.
This commit is contained in:
parent
86afb92057
commit
2debc774d9
@ -47,36 +47,9 @@ class CYBOOKG3(USBMS):
|
||||
DELETE_EXTS = ['.mbp', '.dat', '_6090.t2b']
|
||||
SUPPORTS_SUB_DIRS = True
|
||||
|
||||
def upload_books(self, files, names, on_card=None, end_session=True,
|
||||
metadata=None):
|
||||
|
||||
path = self._sanity_check(on_card, files)
|
||||
|
||||
paths = []
|
||||
names = iter(names)
|
||||
metadata = iter(metadata)
|
||||
|
||||
for i, infile in enumerate(files):
|
||||
mdata, fname = metadata.next(), names.next()
|
||||
filepath = self.create_upload_path(path, mdata, fname)
|
||||
paths.append(filepath)
|
||||
|
||||
self.put_file(infile, filepath, replace_file=True)
|
||||
|
||||
coverdata = None
|
||||
cover = mdata.get('cover', None)
|
||||
if cover:
|
||||
coverdata = cover[2]
|
||||
|
||||
t2bfile = open('%s_6090.t2b' % (os.path.splitext(filepath)[0]), 'wb')
|
||||
def upload_cover(self, path, name, coverdata):
|
||||
with open('%s_6090.t2b' % os.path.join(path, name), 'wb') as t2bfile:
|
||||
t2b.write_t2b(t2bfile, coverdata)
|
||||
t2bfile.close()
|
||||
|
||||
self.report_progress(i / float(len(files)), _('Transferring books to device...'))
|
||||
|
||||
self.report_progress(1.0, _('Transferring books to device...'))
|
||||
|
||||
return zip(paths, cycle([on_card]))
|
||||
|
||||
@classmethod
|
||||
def can_handle(cls, device_info, debug=False):
|
||||
|
@ -38,6 +38,11 @@ class NOOK(USBMS):
|
||||
EBOOK_DIR_MAIN = 'my documents'
|
||||
SUPPORTS_SUB_DIRS = True
|
||||
|
||||
def upload_cover(self, path, name, coverdata):
|
||||
if coverdata:
|
||||
with open('%s.jpg' % os.path.join(path, name), 'wb') as coverfile:
|
||||
coverfile.write(coverdata)
|
||||
|
||||
def windows_sort_drives(self, drives):
|
||||
main = drives.get('main', None)
|
||||
card = drives.get('carda', None)
|
||||
|
@ -112,12 +112,25 @@ class USBMS(CLI, Device):
|
||||
|
||||
self.put_file(infile, filepath, replace_file=True)
|
||||
|
||||
coverdata = mdata.get('cover', None)
|
||||
if coverdata:
|
||||
coverdata = coverdata[2]
|
||||
self.upload_cover(os.path.dirname(filepath), os.path.splitext(os.path.basename(filepath))[0], coverdata)
|
||||
|
||||
self.report_progress((i+1) / float(len(files)), _('Transferring books to device...'))
|
||||
|
||||
self.report_progress(1.0, _('Transferring books to device...'))
|
||||
|
||||
return zip(paths, cycle([on_card]))
|
||||
|
||||
def upload_cover(self, path, name, coverdata):
|
||||
'''
|
||||
:path: the full path were the associated book is located.
|
||||
:name: the name of the book file without the extension.
|
||||
:coverdata: cover data in jpeg format.
|
||||
'''
|
||||
pass
|
||||
|
||||
def add_books_to_metadata(self, locations, metadata, booklists):
|
||||
for i, location in enumerate(locations):
|
||||
self.report_progress((i+1) / float(len(locations)), _('Adding books to device metadata listing...'))
|
||||
|
Loading…
x
Reference in New Issue
Block a user