From 7fc7d7487c65522c2dbc09f4a8c2a7cffa2085fa Mon Sep 17 00:00:00 2001 From: John Schember Date: Tue, 20 Sep 2011 20:07:41 -0400 Subject: [PATCH 1/5] Store: MobileRead plugin, Fix issue with searching with unicode characters. --- .../gui2/store/stores/mobileread/mobileread_plugin.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/store/stores/mobileread/mobileread_plugin.py b/src/calibre/gui2/store/stores/mobileread/mobileread_plugin.py index 3ffb5c36a1..1aabe86c50 100644 --- a/src/calibre/gui2/store/stores/mobileread/mobileread_plugin.py +++ b/src/calibre/gui2/store/stores/mobileread/mobileread_plugin.py @@ -44,9 +44,12 @@ class MobileReadStore(BasicStoreConfig, StorePlugin): def search(self, query, max_results=10, timeout=60): books = self.get_book_list() + + if not books: + return sf = SearchFilter(books) - matches = sf.parse(query) + matches = sf.parse(query.decode('utf-8', 'replace')) for book in matches: book.price = '$0.00' From 64729ef1ab796561ac71dd6efdecdd8847dfde61 Mon Sep 17 00:00:00 2001 From: John Schember Date: Tue, 20 Sep 2011 20:13:18 -0400 Subject: [PATCH 2/5] Store: Shorten filename to prevent errors where the download name is to long. --- src/calibre/gui2/ebook_download.py | 2 +- src/calibre/gui2/store/search/search.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/ebook_download.py b/src/calibre/gui2/ebook_download.py index d39ea47e52..df44b52af2 100644 --- a/src/calibre/gui2/ebook_download.py +++ b/src/calibre/gui2/ebook_download.py @@ -44,7 +44,7 @@ class EbookDownload(object): return dfilename if not filename: - filename = get_download_filename(url, cookie_file) + filename = get_download_filename(url, cookie_file)[:60] br = browser() if cookie_file: diff --git a/src/calibre/gui2/store/search/search.py b/src/calibre/gui2/store/search/search.py index 9e78f75b4a..9413c51a6e 100644 --- a/src/calibre/gui2/store/search/search.py +++ b/src/calibre/gui2/store/search/search.py @@ -350,7 +350,7 @@ class SearchDialog(QDialog, Ui_Dialog): d = ChooseFormatDialog(self, _('Choose format to download to your library.'), result.downloads.keys()) if d.exec_() == d.Accepted: ext = d.format() - fname = result.title + '.' + ext.lower() + fname = result.title[:60] + '.' + ext.lower() fname = ascii_filename(fname) self.gui.download_ebook(result.downloads[ext], filename=fname) From 7a75239843716d1bf0ff9d0e571d6e7dd35e8926 Mon Sep 17 00:00:00 2001 From: John Schember Date: Tue, 20 Sep 2011 20:17:49 -0400 Subject: [PATCH 3/5] Store: Download, ensure download filename is ascii. --- src/calibre/__init__.py | 6 +++++- src/calibre/gui2/ebook_download.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/calibre/__init__.py b/src/calibre/__init__.py index 358a7ee4bf..ef6a383925 100644 --- a/src/calibre/__init__.py +++ b/src/calibre/__init__.py @@ -17,6 +17,7 @@ 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 @@ -648,7 +649,10 @@ def get_download_filename(url, cookie_file=None): if not filename: filename = last_part_name - return filename + filename, ext = os.path.splitext(filename) + filename = filename[:60] + ext + + return ascii_filename(filename) def human_readable(size): """ Convert a size in bytes into a human readable form """ diff --git a/src/calibre/gui2/ebook_download.py b/src/calibre/gui2/ebook_download.py index df44b52af2..d39ea47e52 100644 --- a/src/calibre/gui2/ebook_download.py +++ b/src/calibre/gui2/ebook_download.py @@ -44,7 +44,7 @@ class EbookDownload(object): return dfilename if not filename: - filename = get_download_filename(url, cookie_file)[:60] + filename = get_download_filename(url, cookie_file) br = browser() if cookie_file: From d0c500703d5866240273e7f629b7fbcd2b0f2f28 Mon Sep 17 00:00:00 2001 From: John Schember Date: Tue, 20 Sep 2011 20:31:38 -0400 Subject: [PATCH 4/5] Store: ebook download, fix all unicode decode errors. --- src/calibre/__init__.py | 6 +----- src/calibre/gui2/ebook_download.py | 8 ++++++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/calibre/__init__.py b/src/calibre/__init__.py index ef6a383925..358a7ee4bf 100644 --- a/src/calibre/__init__.py +++ b/src/calibre/__init__.py @@ -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 """ diff --git a/src/calibre/gui2/ebook_download.py b/src/calibre/gui2/ebook_download.py index d39ea47e52..1b2f8b38d0 100644 --- a/src/calibre/gui2/ebook_download.py +++ b/src/calibre/gui2/ebook_download.py @@ -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: From a628dce0f149fb924d4fdd25d4ede0733ade8863 Mon Sep 17 00:00:00 2001 From: John Schember Date: Tue, 20 Sep 2011 20:37:41 -0400 Subject: [PATCH 5/5] Store: ebook download, More shortening work. --- src/calibre/gui2/store/web_control.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calibre/gui2/store/web_control.py b/src/calibre/gui2/store/web_control.py index 17b42c5643..5b4d197503 100644 --- a/src/calibre/gui2/store/web_control.py +++ b/src/calibre/gui2/store/web_control.py @@ -15,6 +15,7 @@ from PyQt4.QtWebKit import QWebView, QWebPage from calibre import USER_AGENT, get_proxies, get_download_filename from calibre.ebooks import BOOK_EXTENSIONS from calibre.ptempfile import PersistentTemporaryFile +from calibre.utils.filenames import ascii_filename class NPWebView(QWebView): @@ -67,6 +68,7 @@ class NPWebView(QWebView): filename = get_download_filename(url, cf) ext = os.path.splitext(filename)[1][1:].lower() + filename = ascii_filename(filename[:60] + '.' + ext) if ext not in BOOK_EXTENSIONS: if ext == 'acsm': from calibre.gui2.dialogs.confirm_delete import confirm