mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Cybook: Generate thumbnail file when adding books to device.
This commit is contained in:
parent
46911ad711
commit
df1c2911af
@ -4,9 +4,11 @@ __copyright__ = '2009, John Schember <john at nachtimwald.com>'
|
||||
Device driver for Bookeen's Cybook Gen 3
|
||||
'''
|
||||
|
||||
import os, fnmatch
|
||||
import os, shutil
|
||||
from itertools import cycle
|
||||
|
||||
from calibre.devices.usbms.driver import USBMS
|
||||
import calibre.devices.cybookg3.t2b as t2b
|
||||
|
||||
class CYBOOKG3(USBMS):
|
||||
# Ordered list of supported formats
|
||||
@ -29,6 +31,76 @@ class CYBOOKG3(USBMS):
|
||||
|
||||
EBOOK_DIR_MAIN = "eBooks"
|
||||
SUPPORTS_SUB_DIRS = True
|
||||
|
||||
def upload_books(self, files, names, on_card=False, end_session=True,
|
||||
metadata=None):
|
||||
if on_card and not self._card_prefix:
|
||||
raise ValueError(_('The reader has no storage card connected.'))
|
||||
|
||||
if not on_card:
|
||||
path = os.path.join(self._main_prefix, self.EBOOK_DIR_MAIN)
|
||||
else:
|
||||
path = os.path.join(self._card_prefix, self.EBOOK_DIR_CARD)
|
||||
|
||||
def get_size(obj):
|
||||
if hasattr(obj, 'seek'):
|
||||
obj.seek(0, os.SEEK_END)
|
||||
size = obj.tell()
|
||||
obj.seek(0)
|
||||
return size
|
||||
return os.path.getsize(obj)
|
||||
|
||||
sizes = map(get_size, files)
|
||||
size = sum(sizes)
|
||||
|
||||
if on_card and size > self.free_space()[2] - 1024*1024:
|
||||
raise FreeSpaceError(_("There is insufficient free space on the storage card"))
|
||||
if not on_card and size > self.free_space()[0] - 2*1024*1024:
|
||||
raise FreeSpaceError(_("There is insufficient free space in main memory"))
|
||||
|
||||
paths = []
|
||||
names = iter(names)
|
||||
metadata = iter(metadata)
|
||||
|
||||
for infile in files:
|
||||
newpath = path
|
||||
mdata = metadata.next()
|
||||
|
||||
if self.SUPPORTS_SUB_DIRS:
|
||||
if 'tags' in mdata.keys():
|
||||
for tag in mdata['tags']:
|
||||
if tag.startswith('/'):
|
||||
newpath += tag
|
||||
newpath = os.path.normpath(newpath)
|
||||
break
|
||||
|
||||
if not os.path.exists(newpath):
|
||||
os.makedirs(newpath)
|
||||
|
||||
filepath = os.path.join(newpath, names.next())
|
||||
paths.append(filepath)
|
||||
|
||||
if hasattr(infile, 'read'):
|
||||
infile.seek(0)
|
||||
|
||||
dest = open(filepath, 'wb')
|
||||
shutil.copyfileobj(infile, dest, 10*1024*1024)
|
||||
|
||||
dest.flush()
|
||||
dest.close()
|
||||
else:
|
||||
shutil.copy2(infile, filepath)
|
||||
|
||||
coverdata = None
|
||||
if 'cover' in mdata.keys():
|
||||
if mdata['cover'] != None:
|
||||
coverdata = mdata['cover'][2]
|
||||
|
||||
t2bfile = open('%s_6090.t2b' % (os.path.splitext(filepath)[0]), 'wb')
|
||||
t2b.write_t2b(t2bfile, coverdata)
|
||||
t2bfile.close()
|
||||
|
||||
return zip(paths, cycle([on_card]))
|
||||
|
||||
def delete_books(self, paths, end_session=True):
|
||||
for path in paths:
|
||||
|
48
src/calibre/devices/cybookg3/t2b.py
Normal file
48
src/calibre/devices/cybookg3/t2b.py
Normal file
File diff suppressed because one or more lines are too long
@ -7,6 +7,7 @@ clarin.com
|
||||
'''
|
||||
|
||||
from calibre import strftime
|
||||
from calibre.web.feeds.news import BasicNewsRecipe
|
||||
|
||||
class Clarin(BasicNewsRecipe):
|
||||
title = 'Clarin'
|
||||
@ -47,4 +48,4 @@ class Clarin(BasicNewsRecipe):
|
||||
rest = artl.partition('-0')[-1]
|
||||
lmain = rest.partition('.')[0]
|
||||
return 'http://www.servicios.clarin.com/notas/jsp/clarin/v9/notas/imprimir.jsp?pagid=' + lmain
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user