mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Pull from trunk
This commit is contained in:
commit
53757285e3
@ -49,7 +49,11 @@ class Danas(BasicNewsRecipe):
|
||||
, 'language' : language
|
||||
}
|
||||
|
||||
preprocess_regexps = [(re.compile(u'\u0110'), lambda match: u'\u00D0')]
|
||||
preprocess_regexps = [
|
||||
(re.compile(u'\u0110'), lambda match: u'\u00D0')
|
||||
,(re.compile(u'\u201c'), lambda match: '"')
|
||||
,(re.compile(u'\u201e'), lambda match: '"')
|
||||
]
|
||||
|
||||
keep_only_tags = [dict(name='div', attrs={'id':'left'})]
|
||||
remove_tags = [
|
||||
|
@ -29,7 +29,9 @@ class ANDROID(USBMS):
|
||||
# Sony Ericsson
|
||||
0xfce : { 0xd12e : [0x0100]},
|
||||
|
||||
0x18d1 : { 0x4e11 : [0x0100, 0x226], 0x4e12: [0x0100, 0x226]},
|
||||
# Google
|
||||
0x18d1 : { 0x4e11 : [0x0100, 0x226, 0x227], 0x4e12: [0x0100, 0x226,
|
||||
0x227]},
|
||||
|
||||
# Samsung
|
||||
0x04e8 : { 0x681d : [0x0222, 0x0400],
|
||||
|
@ -11,6 +11,10 @@ import re
|
||||
|
||||
from calibre.devices.usbms.driver import USBMS
|
||||
|
||||
def is_alex(device_info):
|
||||
return device_info[3] == u'Linux 2.6.28 with pxa3xx_u2d' and \
|
||||
device_info[4] == u'Seleucia Disk'
|
||||
|
||||
class N516(USBMS):
|
||||
|
||||
name = 'N516 driver'
|
||||
@ -34,6 +38,9 @@ class N516(USBMS):
|
||||
EBOOK_DIR_MAIN = 'e_book'
|
||||
SUPPORTS_SUB_DIRS = True
|
||||
|
||||
def can_handle(self, device_info, debug=False):
|
||||
return not is_alex(device_info)
|
||||
|
||||
class THEBOOK(N516):
|
||||
name = 'The Book driver'
|
||||
gui_name = 'The Book'
|
||||
@ -61,6 +68,9 @@ class ALEX(N516):
|
||||
EBOOK_DIR_MAIN = 'eBooks'
|
||||
SUPPORTS_SUB_DIRS = True
|
||||
|
||||
def can_handle(self, device_info, debug=False):
|
||||
return is_alex(device_info)
|
||||
|
||||
class AZBOOKA(ALEX):
|
||||
|
||||
name = 'Azbooka driver'
|
||||
@ -74,6 +84,9 @@ class AZBOOKA(ALEX):
|
||||
|
||||
EBOOK_DIR_MAIN = ''
|
||||
|
||||
def can_handle(self, device_info, debug=False):
|
||||
return not is_alex(device_info)
|
||||
|
||||
|
||||
class EB511(USBMS):
|
||||
name = 'Elonex EB 511 driver'
|
||||
|
@ -1574,14 +1574,15 @@ class MobiWriter(object):
|
||||
id = unicode(oeb.metadata.cover[0])
|
||||
item = oeb.manifest.ids[id]
|
||||
href = item.href
|
||||
index = self._images[href] - 1
|
||||
exth.write(pack('>III', 0xc9, 0x0c, index))
|
||||
exth.write(pack('>III', 0xcb, 0x0c, 0))
|
||||
nrecs += 2
|
||||
index = self._add_thumbnail(item)
|
||||
if index is not None:
|
||||
exth.write(pack('>III', 0xca, 0x0c, index - 1))
|
||||
nrecs += 1
|
||||
if href in self._images:
|
||||
index = self._images[href] - 1
|
||||
exth.write(pack('>III', 0xc9, 0x0c, index))
|
||||
exth.write(pack('>III', 0xcb, 0x0c, 0))
|
||||
nrecs += 2
|
||||
index = self._add_thumbnail(item)
|
||||
if index is not None:
|
||||
exth.write(pack('>III', 0xca, 0x0c, index - 1))
|
||||
nrecs += 1
|
||||
|
||||
exth = exth.getvalue()
|
||||
trail = len(exth) % 4
|
||||
|
@ -60,15 +60,15 @@ def identify(path):
|
||||
data = open(path, 'rb').read()
|
||||
return identify_data(data)
|
||||
|
||||
def add_borders_to_image(path_to_image, left=0, top=0, right=0, bottom=0,
|
||||
border_color='#ffffff'):
|
||||
def add_borders_to_image(img_data, left=0, top=0, right=0, bottom=0,
|
||||
border_color='#ffffff', fmt='jpg'):
|
||||
img = Image()
|
||||
img.open(path_to_image)
|
||||
img.load(img_data)
|
||||
lwidth, lheight = img.size
|
||||
canvas = create_canvas(lwidth+left+right, lheight+top+bottom,
|
||||
border_color)
|
||||
canvas.compose(img, left, top)
|
||||
canvas.save(path_to_image)
|
||||
return canvas.export(fmt)
|
||||
|
||||
def create_text_wand(font_size, font_path=None):
|
||||
if font_path is None:
|
||||
|
@ -7,7 +7,7 @@ Defines various abstract base classes that can be subclassed to create powerful
|
||||
__docformat__ = "restructuredtext en"
|
||||
|
||||
|
||||
import os, time, traceback, re, urlparse, sys
|
||||
import os, time, traceback, re, urlparse, sys, cStringIO
|
||||
from collections import defaultdict
|
||||
from functools import partial
|
||||
from contextlib import nested, closing
|
||||
@ -27,6 +27,7 @@ from calibre.web.fetch.simple import RecursiveFetcher
|
||||
from calibre.utils.threadpool import WorkRequest, ThreadPool, NoResultsPending
|
||||
from calibre.ptempfile import PersistentTemporaryFile
|
||||
from calibre.utils.date import now as nowf
|
||||
from calibre.utils.magick.draw import save_cover_data_to, add_borders_to_image
|
||||
|
||||
class LoginFailed(ValueError):
|
||||
pass
|
||||
@ -948,38 +949,36 @@ class BasicNewsRecipe(Recipe):
|
||||
try:
|
||||
cu = self.get_cover_url()
|
||||
except Exception, err:
|
||||
cu = None
|
||||
self.log.error(_('Could not download cover: %s')%str(err))
|
||||
self.log.debug(traceback.format_exc())
|
||||
if cu is not None:
|
||||
ext = cu.split('/')[-1].rpartition('.')[-1]
|
||||
if '?' in ext:
|
||||
ext = ''
|
||||
ext = ext.lower() if ext and '/' not in ext else 'jpg'
|
||||
cpath = os.path.join(self.output_dir, 'cover.'+ext)
|
||||
else:
|
||||
cdata = None
|
||||
if os.access(cu, os.R_OK):
|
||||
with open(cpath, 'wb') as cfile:
|
||||
cfile.write(open(cu, 'rb').read())
|
||||
cdata = open(cu, 'rb').read()
|
||||
else:
|
||||
self.report_progress(1, _('Downloading cover from %s')%cu)
|
||||
with nested(open(cpath, 'wb'), closing(self.browser.open(cu))) as (cfile, r):
|
||||
cfile.write(r.read())
|
||||
if self.cover_margins[0] or self.cover_margins[1]:
|
||||
from calibre.utils.magick.draw import add_borders_to_image
|
||||
add_borders_to_image(cpath,
|
||||
left=self.cover_margins[0],right=self.cover_margins[0],
|
||||
top=self.cover_margins[1],bottom=self.cover_margins[1],
|
||||
border_color=self.cover_margins[2])
|
||||
if ext.lower() == 'pdf':
|
||||
with closing(self.browser.open(cu)) as r:
|
||||
cdata = r.read()
|
||||
if not cdata:
|
||||
return
|
||||
ext = cu.split('/')[-1].rpartition('.')[-1].lower().strip()
|
||||
if ext == 'pdf':
|
||||
from calibre.ebooks.metadata.pdf import get_metadata
|
||||
stream = open(cpath, 'rb')
|
||||
stream = cStringIO.StringIO(cdata)
|
||||
cdata = None
|
||||
mi = get_metadata(stream)
|
||||
cpath = None
|
||||
if mi.cover_data and mi.cover_data[1]:
|
||||
cpath = os.path.join(self.output_dir,
|
||||
'cover.'+mi.cover_data[0])
|
||||
with open(cpath, 'wb') as f:
|
||||
f.write(mi.cover_data[1])
|
||||
cdata = mi.cover_data[1]
|
||||
if not cdata:
|
||||
return
|
||||
if self.cover_margins[0] or self.cover_margins[1]:
|
||||
cdata = add_borders_to_image(cdata,
|
||||
left=self.cover_margins[0],right=self.cover_margins[0],
|
||||
top=self.cover_margins[1],bottom=self.cover_margins[1],
|
||||
border_color=self.cover_margins[2])
|
||||
|
||||
cpath = os.path.join(self.output_dir, 'cover.jpg')
|
||||
save_cover_data_to(cdata, cpath)
|
||||
self.cover_path = cpath
|
||||
|
||||
def download_cover(self):
|
||||
@ -1422,7 +1421,6 @@ class CalibrePeriodical(BasicNewsRecipe):
|
||||
return br
|
||||
|
||||
def download(self):
|
||||
import cStringIO
|
||||
self.log('Fetching downloaded recipe')
|
||||
try:
|
||||
raw = self.browser.open_novisit(
|
||||
|
Loading…
x
Reference in New Issue
Block a user