mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit book: Fix handling of file:// URLs when downloading external links
This commit is contained in:
parent
4279f12183
commit
eeb7672774
@ -17,13 +17,14 @@ from multiprocessing.dummy import Pool
|
|||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
|
|
||||||
from calibre import as_unicode, sanitize_file_name as sanitize_file_name_base
|
from calibre import as_unicode, sanitize_file_name as sanitize_file_name_base
|
||||||
|
from calibre.constants import iswindows
|
||||||
from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES, barename, iterlinks
|
from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES, barename, iterlinks
|
||||||
from calibre.ebooks.oeb.polish.utils import guess_type
|
from calibre.ebooks.oeb.polish.utils import guess_type
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
from calibre.web import get_download_filename_from_response
|
from calibre.web import get_download_filename_from_response
|
||||||
from polyglot.builtins import iteritems
|
|
||||||
from polyglot.urllib import urlopen, urlparse
|
|
||||||
from polyglot.binary import from_base64_bytes
|
from polyglot.binary import from_base64_bytes
|
||||||
|
from polyglot.builtins import iteritems
|
||||||
|
from polyglot.urllib import unquote, urlopen, urlparse
|
||||||
|
|
||||||
|
|
||||||
def is_external(url):
|
def is_external(url):
|
||||||
@ -108,8 +109,11 @@ def download_one(tdir, timeout, progress_report, data_uri_map, url):
|
|||||||
data_url_key = None
|
data_url_key = None
|
||||||
with NamedTemporaryFile(dir=tdir, delete=False) as df:
|
with NamedTemporaryFile(dir=tdir, delete=False) as df:
|
||||||
if purl.scheme == 'file':
|
if purl.scheme == 'file':
|
||||||
src = lopen(purl.path, 'rb')
|
path = unquote(purl.path)
|
||||||
filename = os.path.basename(src)
|
if iswindows and path.startswith('/'):
|
||||||
|
path = path[1:]
|
||||||
|
src = lopen(path, 'rb')
|
||||||
|
filename = os.path.basename(path)
|
||||||
sz = (src.seek(0, os.SEEK_END), src.tell(), src.seek(0))[1]
|
sz = (src.seek(0, os.SEEK_END), src.tell(), src.seek(0))[1]
|
||||||
elif purl.scheme == 'data':
|
elif purl.scheme == 'data':
|
||||||
prefix, payload = purl.path.split(',', 1)
|
prefix, payload = purl.path.split(',', 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user