mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Store: ebook download, fix all unicode decode errors.
This commit is contained in:
parent
7a75239843
commit
d0c500703d
@ -17,7 +17,6 @@ from calibre.constants import (iswindows, isosx, islinux, isfrozen,
|
||||
win32event, win32api, winerror, fcntl,
|
||||
filesystem_encoding, plugins, config_dir)
|
||||
from calibre.startup import winutil, winutilerror
|
||||
from calibre.utils.filenames import ascii_filename
|
||||
|
||||
if False and islinux and not getattr(sys, 'frozen', False):
|
||||
# Imported before PyQt4 to workaround PyQt4 util-linux conflict discovered on gentoo
|
||||
@ -649,10 +648,7 @@ def get_download_filename(url, cookie_file=None):
|
||||
if not filename:
|
||||
filename = last_part_name
|
||||
|
||||
filename, ext = os.path.splitext(filename)
|
||||
filename = filename[:60] + ext
|
||||
|
||||
return ascii_filename(filename)
|
||||
return filename
|
||||
|
||||
def human_readable(size):
|
||||
""" Convert a size in bytes into a human readable form """
|
||||
|
@ -16,6 +16,7 @@ from calibre.ebooks import BOOK_EXTENSIONS
|
||||
from calibre.gui2 import Dispatcher
|
||||
from calibre.gui2.threaded_jobs import ThreadedJob
|
||||
from calibre.ptempfile import PersistentTemporaryFile
|
||||
from calibre.utils.filenames import ascii_filename
|
||||
|
||||
class EbookDownload(object):
|
||||
|
||||
@ -45,6 +46,9 @@ class EbookDownload(object):
|
||||
|
||||
if not filename:
|
||||
filename = get_download_filename(url, cookie_file)
|
||||
filename, ext = os.path.splitext(filename)
|
||||
filename = filename[:60] + ext
|
||||
filename = ascii_filename(filename)
|
||||
|
||||
br = browser()
|
||||
if cookie_file:
|
||||
@ -84,7 +88,7 @@ class EbookDownload(object):
|
||||
gui_ebook_download = EbookDownload()
|
||||
|
||||
def start_ebook_download(callback, job_manager, gui, cookie_file=None, url='', filename='', save_loc='', add_to_lib=True, tags=[]):
|
||||
description = _('Downloading %s') % filename if filename else url
|
||||
description = _('Downloading %s') % filename.decode('utf-8', 'ignore') if filename else url.decode('utf-8', 'ignore')
|
||||
job = ThreadedJob('ebook_download', description, gui_ebook_download, (gui, cookie_file, url, filename, save_loc, add_to_lib, tags), {}, callback, max_concurrent_count=2, killable=False)
|
||||
job_manager.run_threaded_job(job)
|
||||
|
||||
@ -96,7 +100,7 @@ class EbookDownloadMixin(object):
|
||||
if isinstance(tags, basestring):
|
||||
tags = tags.split(',')
|
||||
start_ebook_download(Dispatcher(self.downloaded_ebook), self.job_manager, self, cookie_file, url, filename, save_loc, add_to_lib, tags)
|
||||
self.status_bar.show_message(_('Downloading') + ' ' + filename if filename else url, 3000)
|
||||
self.status_bar.show_message(_('Downloading') + ' ' + filename.decode('utf-8', 'ignore') if filename else url.decode('utf-8', 'ignore'), 3000)
|
||||
|
||||
def downloaded_ebook(self, job):
|
||||
if job.failed:
|
||||
|
Loading…
x
Reference in New Issue
Block a user