mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Store: Fix B&N plugin. Fix cleaning of query.
This commit is contained in:
parent
efb7b33a58
commit
0fa9719375
@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import urllib2
|
import urllib
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
|
|
||||||
from lxml import html
|
from lxml import html
|
||||||
@ -48,7 +48,7 @@ class BNStore(BasicStoreConfig, StorePlugin):
|
|||||||
|
|
||||||
def search(self, query, max_results=10, timeout=60):
|
def search(self, query, max_results=10, timeout=60):
|
||||||
url = 'http://productsearch.barnesandnoble.com/search/results.aspx?STORE=EBOOK&SZE=%s&WRD=' % max_results
|
url = 'http://productsearch.barnesandnoble.com/search/results.aspx?STORE=EBOOK&SZE=%s&WRD=' % max_results
|
||||||
url += urllib2.quote(query)
|
url += urllib.quote_plus(query)
|
||||||
|
|
||||||
br = browser()
|
br = browser()
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ from threading import Thread
|
|||||||
from Queue import Queue
|
from Queue import Queue
|
||||||
|
|
||||||
from calibre import browser
|
from calibre import browser
|
||||||
|
from calibre.constants import DEBUG
|
||||||
from calibre.utils.magick.draw import thumbnail
|
from calibre.utils.magick.draw import thumbnail
|
||||||
|
|
||||||
class GenericDownloadThreadPool(object):
|
class GenericDownloadThreadPool(object):
|
||||||
@ -119,7 +120,8 @@ class SearchThread(Thread):
|
|||||||
self.results.put((res, store_plugin))
|
self.results.put((res, store_plugin))
|
||||||
self.tasks.task_done()
|
self.tasks.task_done()
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
if DEBUG:
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
|
||||||
class CoverThreadPool(GenericDownloadThreadPool):
|
class CoverThreadPool(GenericDownloadThreadPool):
|
||||||
@ -157,7 +159,8 @@ class CoverThread(Thread):
|
|||||||
callback()
|
callback()
|
||||||
self.tasks.task_done()
|
self.tasks.task_done()
|
||||||
except:
|
except:
|
||||||
continue
|
if DEBUG:
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
|
||||||
class DetailsThreadPool(GenericDownloadThreadPool):
|
class DetailsThreadPool(GenericDownloadThreadPool):
|
||||||
@ -191,7 +194,8 @@ class DetailsThread(Thread):
|
|||||||
callback(result)
|
callback(result)
|
||||||
self.tasks.task_done()
|
self.tasks.task_done()
|
||||||
except:
|
except:
|
||||||
continue
|
if DEBUG:
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
|
||||||
class CacheUpdateThreadPool(GenericDownloadThreadPool):
|
class CacheUpdateThreadPool(GenericDownloadThreadPool):
|
||||||
@ -221,4 +225,5 @@ class CacheUpdateThread(Thread):
|
|||||||
store_plugin, timeout = self.tasks.get()
|
store_plugin, timeout = self.tasks.get()
|
||||||
store_plugin.update_cache(timeout=timeout, suppress_progress=True)
|
store_plugin.update_cache(timeout=timeout, suppress_progress=True)
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
if DEBUG:
|
||||||
|
traceback.print_exc()
|
||||||
|
@ -139,14 +139,17 @@ class SearchDialog(QDialog, Ui_Dialog):
|
|||||||
query = query.replace('>', '')
|
query = query.replace('>', '')
|
||||||
query = query.replace('<', '')
|
query = query.replace('<', '')
|
||||||
# Remove the prefix.
|
# Remove the prefix.
|
||||||
for loc in ( 'all', 'author', 'authors', 'title'):
|
for loc in ('all', 'author', 'authors', 'title'):
|
||||||
query = re.sub(r'%s:"?(?P<a>[^\s"]+)"?' % loc, '\g<a>', query)
|
query = re.sub(r'%s:"(?P<a>[^\s"]+)"' % loc, '\g<a>', query)
|
||||||
|
query = query.replace('%s:' % loc, '')
|
||||||
# Remove the prefix and search text.
|
# Remove the prefix and search text.
|
||||||
for loc in ('cover', 'drm', 'format', 'formats', 'price', 'store'):
|
for loc in ('cover', 'drm', 'format', 'formats', 'price', 'store'):
|
||||||
query = re.sub(r'%s:"[^"]"' % loc, '', query)
|
query = re.sub(r'%s:"[^"]"' % loc, '', query)
|
||||||
query = re.sub(r'%s:[^\s]*' % loc, '', query)
|
query = re.sub(r'%s:[^\s]*' % loc, '', query)
|
||||||
# Remove logic.
|
# Remove logic.
|
||||||
query = re.sub(r'(^|\s)(and|not|or)(\s|$)', ' ', query)
|
query = re.sub(r'(^|\s)(and|not|or|a|the|is|of)(\s|$)', ' ', query)
|
||||||
|
# Remove "
|
||||||
|
query = query.replace('"', '')
|
||||||
# Remove excess whitespace.
|
# Remove excess whitespace.
|
||||||
query = re.sub(r'\s{2,}', ' ', query)
|
query = re.sub(r'\s{2,}', ' ', query)
|
||||||
query = query.strip()
|
query = query.strip()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user