Nook driver: Upload covers when sending to device. Also add Output Profile for the Nook

This commit is contained in:
Kovid Goyal 2009-12-22 17:30:19 -07:00
commit c9cf600295
6 changed files with 89 additions and 35 deletions

View File

@ -21,3 +21,4 @@ src/cssutils/css/.svn/
src/cssutils/stylesheets/.svn/
src/odf/.svn
tags
nbproject/

View File

@ -88,9 +88,9 @@ class MobipocketInput(InputProfile):
class HanlinV3Input(InputProfile):
name = 'Hanlin V3'
name = 'Hanlin V3/V5'
short_name = 'hanlinv3'
description = _('This profile is intended for the Hanlin V3 and its clones.')
description = _('This profile is intended for the Hanlin V3/V5 and its clones.')
# Screen size is a best guess
screen_size = (584, 754)
@ -159,9 +159,23 @@ class IRexDR1000Input(InputProfile):
fbase = 16
fsizes = [12, 14, 16, 18, 20, 22, 24]
class NookInput(InputProfile):
author = 'John Schember'
name = 'Nook'
short_name = 'nook'
description = _('This profile is intended for the B&N Nook.')
# Screen size is a best guess
screen_size = (600, 800)
dpi = 167
fbase = 16
fsizes = [12, 12, 14, 16, 18, 20, 22, 24]
input_profiles = [InputProfile, SonyReaderInput, MSReaderInput,
MobipocketInput, HanlinV3Input, CybookG3Input, CybookOpusInput, KindleInput,
IlliadInput, IRexDR1000Input]
IlliadInput, IRexDR1000Input, NookInput]
class OutputProfile(Plugin):
@ -248,7 +262,7 @@ class MobipocketOutput(OutputProfile):
class HanlinV3Output(OutputProfile):
name = 'Hanlin V3'
name = 'Hanlin V3/V5'
short_name = 'hanlinv3'
description = _('This profile is intended for the Hanlin V3/V5 and its clones.')
@ -341,7 +355,20 @@ class IRexDR1000Output(OutputProfile):
fbase = 16
fsizes = [12, 14, 16, 18, 20, 22, 24]
class NookOutput(OutputProfile):
author = 'John Schember'
name = 'Nook'
short_name = 'nook'
description = _('This profile is intended for the B&N Nook.')
# Screen size is a best guess
screen_size = (600, 770)
dpi = 167
fbase = 16
fsizes = [12, 12, 14, 16, 18, 20, 22, 24]
output_profiles = [OutputProfile, SonyReaderOutput, MSReaderOutput,
MobipocketOutput, HanlinV3Output, CybookG3Output, CybookOpusOutput,
KindleOutput, SonyReaderLandscapeOutput, KindleDXOutput, IlliadOutput,
IRexDR1000Output, JetBook5Output]
IRexDR1000Output, JetBook5Output, NookOutput]

View File

@ -9,7 +9,6 @@ Device driver for Bookeen's Cybook Gen 3
'''
import os
from itertools import cycle
from calibre import islinux
from calibre.devices.usbms.driver import USBMS
@ -47,36 +46,12 @@ 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, 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)
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):

View File

@ -8,6 +8,10 @@ __docformat__ = 'restructuredtext en'
Device driver for Barns and Nobel's Nook
'''
import os
import cStringIO
from calibre.devices.usbms.driver import USBMS
class NOOK(USBMS):
@ -39,6 +43,39 @@ class NOOK(USBMS):
EBOOK_DIR_MAIN = 'my documents'
SUPPORTS_SUB_DIRS = True
def upload_cover(self, path, filename, metadata):
try:
from PIL import Image, ImageDraw
Image, ImageDraw
except ImportError:
import Image, ImageDraw
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()
cover = Image.new('RGB', (96, 144), 'black')
im = Image.open(cStringIO.StringIO(coverdata))
im.thumbnail((96, 144), Image.ANTIALIAS)
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()
cover.save(data, 'JPEG')
coverdata = data.getvalue()
with open('%s.jpg' % os.path.join(path, filename), 'wb') as coverfile:
coverfile.write(coverdata)
def windows_sort_drives(self, drives):
main = drives.get('main', None)
card = drives.get('carda', None)

View File

@ -111,6 +111,11 @@ class USBMS(CLI, Device):
paths.append(filepath)
self.put_file(infile, filepath, replace_file=True)
try:
self.upload_cover(os.path.dirname(filepath), os.path.splitext(os.path.basename(filepath))[0], mdata)
except: # Failure to upload cover is not catastrophic
import traceback
traceback.print_exc()
self.report_progress((i+1) / float(len(files)), _('Transferring books to device...'))
@ -118,6 +123,14 @@ class USBMS(CLI, Device):
return zip(paths, cycle([on_card]))
def upload_cover(self, path, filename, metadata):
'''
:path: the full path were the associated book is located.
:filename: the name of the book file without the extension.
:metatdata: metadata belonging to the book. metadata.cover[2] for coverdata.
'''
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...'))

View File

@ -96,6 +96,7 @@ class Nook(Sony505):
id = 'nook'
name = 'Nook'
manufacturer = 'Barnes & Noble'
output_profile = 'nook'
class CybookG3(Device):