Store: ebook download, fix all unicode decode errors.

This commit is contained in:
John Schember 2011-09-20 20:31:38 -04:00
parent 7a75239843
commit d0c500703d
2 changed files with 7 additions and 7 deletions

View File

@ -17,7 +17,6 @@ from calibre.constants import (iswindows, isosx, islinux, isfrozen,
win32event, win32api, winerror, fcntl, win32event, win32api, winerror, fcntl,
filesystem_encoding, plugins, config_dir) filesystem_encoding, plugins, config_dir)
from calibre.startup import winutil, winutilerror from calibre.startup import winutil, winutilerror
from calibre.utils.filenames import ascii_filename
if False and islinux and not getattr(sys, 'frozen', False): if False and islinux and not getattr(sys, 'frozen', False):
# Imported before PyQt4 to workaround PyQt4 util-linux conflict discovered on gentoo # 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: if not filename:
filename = last_part_name filename = last_part_name
filename, ext = os.path.splitext(filename) return filename
filename = filename[:60] + ext
return ascii_filename(filename)
def human_readable(size): def human_readable(size):
""" Convert a size in bytes into a human readable form """ """ Convert a size in bytes into a human readable form """

View File

@ -16,6 +16,7 @@ from calibre.ebooks import BOOK_EXTENSIONS
from calibre.gui2 import Dispatcher from calibre.gui2 import Dispatcher
from calibre.gui2.threaded_jobs import ThreadedJob from calibre.gui2.threaded_jobs import ThreadedJob
from calibre.ptempfile import PersistentTemporaryFile from calibre.ptempfile import PersistentTemporaryFile
from calibre.utils.filenames import ascii_filename
class EbookDownload(object): class EbookDownload(object):
@ -45,6 +46,9 @@ class EbookDownload(object):
if not filename: if not filename:
filename = get_download_filename(url, cookie_file) filename = get_download_filename(url, cookie_file)
filename, ext = os.path.splitext(filename)
filename = filename[:60] + ext
filename = ascii_filename(filename)
br = browser() br = browser()
if cookie_file: if cookie_file:
@ -84,7 +88,7 @@ class EbookDownload(object):
gui_ebook_download = EbookDownload() gui_ebook_download = EbookDownload()
def start_ebook_download(callback, job_manager, gui, cookie_file=None, url='', filename='', save_loc='', add_to_lib=True, tags=[]): 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 = 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) job_manager.run_threaded_job(job)
@ -96,7 +100,7 @@ class EbookDownloadMixin(object):
if isinstance(tags, basestring): if isinstance(tags, basestring):
tags = tags.split(',') tags = tags.split(',')
start_ebook_download(Dispatcher(self.downloaded_ebook), self.job_manager, self, cookie_file, url, filename, save_loc, add_to_lib, tags) 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): def downloaded_ebook(self, job):
if job.failed: if job.failed: