mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Working cover upload for the Nook.
This commit is contained in:
parent
80ce4c5b4d
commit
170e579673
@ -47,8 +47,11 @@ class CYBOOKG3(USBMS):
|
||||
DELETE_EXTS = ['.mbp', '.dat', '_6090.t2b']
|
||||
SUPPORTS_SUB_DIRS = True
|
||||
|
||||
def upload_cover(self, path, name, coverdata, metadata):
|
||||
with open('%s_6090.t2b' % os.path.join(path, name), 'wb') as t2bfile:
|
||||
def upload_cover(self, path, filename, metadata):
|
||||
coverdata = metadata.get('cover', None)
|
||||
if coverdata:
|
||||
coverdata = coverdata[2]
|
||||
with open('%s_6090.t2b' % os.path.join(path, filename), 'wb') as t2bfile:
|
||||
t2b.write_t2b(t2bfile, coverdata)
|
||||
|
||||
@classmethod
|
||||
|
@ -10,9 +10,8 @@ Device driver for Barns and Nobel's Nook
|
||||
|
||||
try:
|
||||
from PIL import Image, ImageDraw
|
||||
Image
|
||||
except ImportError:
|
||||
import Image
|
||||
import Image, ImageDraw
|
||||
|
||||
import cStringIO
|
||||
|
||||
@ -46,23 +45,30 @@ class NOOK(USBMS):
|
||||
EBOOK_DIR_MAIN = 'my documents'
|
||||
SUPPORTS_SUB_DIRS = True
|
||||
|
||||
def upload_cover(self, path, name, coverdata, metadata):
|
||||
if not coverdata:
|
||||
def upload_cover(self, path, filename, metadata):
|
||||
coverdata = metadata.get('cover', None)
|
||||
if coverdata:
|
||||
cover = Image.open(cStringIO.StringIO(coverdata[2]))
|
||||
cover.thumbnail((96, 144), Image.ANTIALIAS)
|
||||
else:
|
||||
coverdata = open(I('library.png'), 'rb').read()
|
||||
|
||||
im = Image.open(cStringIO.StringIO(coverdata))
|
||||
im.thumbnail((96, 144), Image.ANTIALIAS)
|
||||
cover = Image.new('RGB', (96, 144), 'black')
|
||||
im = Image.open(cStringIO.StringIO(coverdata))
|
||||
im.thumbnail((96, 144), Image.ANTIALIAS)
|
||||
|
||||
if not coverdata:
|
||||
draw = ImageDraw.Draw(im)
|
||||
draw.text((0, 29), metadata.title)
|
||||
draw.text((0, 115), ', '.join(metadata.authors))
|
||||
x, y = im.size
|
||||
cover.paste(im, ((96-x)/2, (144-y)/2))
|
||||
|
||||
draw = ImageDraw.Draw(cover)
|
||||
draw.text((1, 15), metadata.title)
|
||||
draw.text((1, 115), ', '.join(metadata.authors))
|
||||
|
||||
data = cStringIO.StringIO()
|
||||
im.save(data, 'JPG')
|
||||
cover.save(data, 'JPEG')
|
||||
coverdata = data.getvalue()
|
||||
|
||||
with open('%s.jpg' % os.path.join(path, name), 'wb') as coverfile:
|
||||
with open('%s.jpg' % os.path.join(path, filename), 'wb') as coverfile:
|
||||
coverfile.write(coverdata)
|
||||
|
||||
def windows_sort_drives(self, drives):
|
||||
|
@ -111,11 +111,7 @@ class USBMS(CLI, Device):
|
||||
paths.append(filepath)
|
||||
|
||||
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, mdata)
|
||||
self.upload_cover(os.path.dirname(filepath), os.path.splitext(os.path.basename(filepath))[0], mdata)
|
||||
|
||||
self.report_progress((i+1) / float(len(files)), _('Transferring books to device...'))
|
||||
|
||||
@ -123,11 +119,11 @@ class USBMS(CLI, Device):
|
||||
|
||||
return zip(paths, cycle([on_card]))
|
||||
|
||||
def upload_cover(self, path, name, coverdata):
|
||||
def upload_cover(self, path, filename, metadata):
|
||||
'''
|
||||
: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.
|
||||
:filename: the name of the book file without the extension.
|
||||
:metatdata: metadata belonging to the book. metadata.cover[2] for coverdata.
|
||||
'''
|
||||
pass
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user