mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Generate thumbnails when adding books to the Cybook
This commit is contained in:
commit
42861e9b36
@ -4,9 +4,11 @@ __copyright__ = '2009, John Schember <john at nachtimwald.com>'
|
|||||||
Device driver for Bookeen's Cybook Gen 3
|
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
|
from calibre.devices.usbms.driver import USBMS
|
||||||
|
import calibre.devices.cybookg3.t2b as t2b
|
||||||
|
|
||||||
class CYBOOKG3(USBMS):
|
class CYBOOKG3(USBMS):
|
||||||
# Ordered list of supported formats
|
# Ordered list of supported formats
|
||||||
@ -29,6 +31,76 @@ class CYBOOKG3(USBMS):
|
|||||||
|
|
||||||
EBOOK_DIR_MAIN = "eBooks"
|
EBOOK_DIR_MAIN = "eBooks"
|
||||||
SUPPORTS_SUB_DIRS = True
|
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):
|
def delete_books(self, paths, end_session=True):
|
||||||
for path in paths:
|
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
@ -18,34 +18,33 @@ class Clarin(BasicNewsRecipe):
|
|||||||
use_embedded_content = False
|
use_embedded_content = False
|
||||||
no_stylesheets = True
|
no_stylesheets = True
|
||||||
cover_url = strftime('http://www.clarin.com/diario/%Y/%m/%d/portada.jpg')
|
cover_url = strftime('http://www.clarin.com/diario/%Y/%m/%d/portada.jpg')
|
||||||
|
|
||||||
html2lrf_options = [
|
html2lrf_options = [
|
||||||
'--comment', description
|
'--comment', description
|
||||||
, '--base-font-size', '10'
|
, '--base-font-size', '10'
|
||||||
, '--category', 'news, Argentina'
|
, '--category', 'news, Argentina'
|
||||||
, '--publisher', 'Grupo Clarin'
|
, '--publisher', 'Grupo Clarin'
|
||||||
]
|
]
|
||||||
|
|
||||||
remove_tags = [
|
remove_tags = [
|
||||||
dict(name='a' , attrs={'class':'Imp' })
|
dict(name='a' , attrs={'class':'Imp' })
|
||||||
,dict(name='div' , attrs={'class':'Perma' })
|
,dict(name='div' , attrs={'class':'Perma' })
|
||||||
,dict(name='h1' , text='Imprimir' )
|
,dict(name='h1' , text='Imprimir' )
|
||||||
]
|
]
|
||||||
|
|
||||||
feeds = [
|
feeds = [
|
||||||
(u'Ultimo Momento', u'http://www.clarin.com/diario/hoy/um/sumariorss.xml')
|
(u'Ultimo Momento', u'http://www.clarin.com/diario/hoy/um/sumariorss.xml')
|
||||||
,(u'El Pais' , u'http://www.clarin.com/diario/hoy/elpais.xml' )
|
,(u'El Pais' , u'http://www.clarin.com/diario/hoy/elpais.xml' )
|
||||||
,(u'Opinion' , u'http://www.clarin.com/diario/hoy/opinion.xml' )
|
,(u'Opinion' , u'http://www.clarin.com/diario/hoy/opinion.xml' )
|
||||||
,(u'El Mundo' , u'http://www.clarin.com/diario/hoy/elmundo.xml' )
|
,(u'El Mundo' , u'http://www.clarin.com/diario/hoy/elmundo.xml' )
|
||||||
,(u'Sociedad' , u'http://www.clarin.com/diario/hoy/sociedad.xml' )
|
,(u'Sociedad' , u'http://www.clarin.com/diario/hoy/sociedad.xml' )
|
||||||
,(u'La Ciudad' , u'http://www.clarin.com/diario/hoy/laciudad.xml' )
|
,(u'La Ciudad' , u'http://www.clarin.com/diario/hoy/laciudad.xml' )
|
||||||
,(u'Policiales' , u'http://www.clarin.com/diario/hoy/policiales.xml' )
|
,(u'Policiales' , u'http://www.clarin.com/diario/hoy/policiales.xml' )
|
||||||
,(u'Deportes' , u'http://www.clarin.com/diario/hoy/deportes.xml' )
|
,(u'Deportes' , u'http://www.clarin.com/diario/hoy/deportes.xml' )
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_article_url(self, article):
|
def get_article_url(self, article):
|
||||||
artl = article.get('link', None)
|
artl = article.get('link', None)
|
||||||
rest = artl.partition('-0')[-1]
|
rest = artl.partition('-0')[-1]
|
||||||
lmain = rest.partition('.')[0]
|
lmain = rest.partition('.')[0]
|
||||||
return 'http://www.servicios.clarin.com/notas/jsp/clarin/v9/notas/imprimir.jsp?pagid=' + lmain
|
return 'http://www.servicios.clarin.com/notas/jsp/clarin/v9/notas/imprimir.jsp?pagid=' + lmain
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user