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