mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
News download: Add support for <img> tags that link to SVG images. Fixes #1031553 (web2disk doesn't support SVG images)
This commit is contained in:
parent
0d843a89ea
commit
2848314bf9
@ -7,7 +7,7 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
Fetch a webpage and its links recursively. The webpages are saved to disk in
|
Fetch a webpage and its links recursively. The webpages are saved to disk in
|
||||||
UTF-8 encoding with any charset declarations removed.
|
UTF-8 encoding with any charset declarations removed.
|
||||||
'''
|
'''
|
||||||
import sys, socket, os, urlparse, re, time, copy, urllib2, threading, traceback
|
import sys, socket, os, urlparse, re, time, copy, urllib2, threading, traceback, imghdr
|
||||||
from urllib import url2pathname, quote
|
from urllib import url2pathname, quote
|
||||||
from httplib import responses
|
from httplib import responses
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
@ -375,6 +375,15 @@ class RecursiveFetcher(object):
|
|||||||
if isinstance(fname, unicode):
|
if isinstance(fname, unicode):
|
||||||
fname = fname.encode('ascii', 'replace')
|
fname = fname.encode('ascii', 'replace')
|
||||||
imgpath = os.path.join(diskpath, fname+'.jpg')
|
imgpath = os.path.join(diskpath, fname+'.jpg')
|
||||||
|
if (imghdr.what(None, data) is None and b'<svg' in data[:1024]):
|
||||||
|
# SVG image
|
||||||
|
imgpath = os.path.join(diskpath, fname+'.svg')
|
||||||
|
with self.imagemap_lock:
|
||||||
|
self.imagemap[iurl] = imgpath
|
||||||
|
with open(imgpath, 'wb') as x:
|
||||||
|
x.write(data)
|
||||||
|
tag['src'] = imgpath
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
im = Image.open(StringIO(data)).convert('RGBA')
|
im = Image.open(StringIO(data)).convert('RGBA')
|
||||||
with self.imagemap_lock:
|
with self.imagemap_lock:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user