From 609c2de0e42a77612577aad96b7a58978c00c317 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 10 Dec 2014 08:37:04 +0530 Subject: [PATCH] Small performance improvements for the content server kepub patch --- src/calibre/library/server/content.py | 2 +- src/calibre/library/server/mobile.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/calibre/library/server/content.py b/src/calibre/library/server/content.py index c9ffe83f45..7e2f22d9f2 100644 --- a/src/calibre/library/server/content.py +++ b/src/calibre/library/server/content.py @@ -254,7 +254,7 @@ class ContentServer(object): ua = cherrypy.request.headers.get('User-Agent', '').strip() have_kobo_browser = self.is_kobo_browser(ua) - file_extension = "kepub.epub" if format.lower() == "kepub" and have_kobo_browser else format + file_extension = "kepub.epub" if have_kobo_browser and format.lower() == "kepub" else format au = authors_to_string(newmi.authors if newmi.authors else [_('Unknown')]) diff --git a/src/calibre/library/server/mobile.py b/src/calibre/library/server/mobile.py index b4590b2d3d..8b880ce12a 100644 --- a/src/calibre/library/server/mobile.py +++ b/src/calibre/library/server/mobile.py @@ -122,7 +122,7 @@ def build_index(books, num, search, sort, order, start, total, url_base, CKEYS, for fmt in book['formats'].split(','): if not fmt or fmt.lower().startswith('original_'): continue - file_extension = "kepub.epub" if fmt.lower() == "kepub" and have_kobo_browser else fmt + file_extension = "kepub.epub" if have_kobo_browser and fmt.lower() == "kepub" else fmt a = quote(ascii_filename(book['authors'])) t = quote(ascii_filename(book['title'])) s = SPAN( @@ -183,15 +183,13 @@ class MobileServer(object): 'A view optimized for browsers in mobile devices' MOBILE_UA = re.compile('(?i)(?:iPhone|Opera Mini|NetFront|webOS|Mobile|Android|imode|DoCoMo|Minimo|Blackberry|MIDP|Symbian|HD2|Kindle)') - KOBO_UA = re.compile('(?i)(?:Kobo Touch)') def is_mobile_browser(self, ua): match = self.MOBILE_UA.search(ua) return match is not None and 'iPad' not in ua def is_kobo_browser(self, ua): - match = self.KOBO_UA.search(ua) - return match is not None + return 'Kobo Touch' in ua def add_routes(self, connect): connect('mobile', '/mobile', self.mobile)