mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Store: Convert EpubBud to use new OpenSearchStore class.
This commit is contained in:
parent
5570a17ee0
commit
85a4cca822
@ -6,73 +6,20 @@ __license__ = 'GPL 3'
|
|||||||
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import urllib
|
|
||||||
from contextlib import closing
|
|
||||||
|
|
||||||
from lxml import html
|
|
||||||
|
|
||||||
from PyQt4.Qt import QUrl
|
|
||||||
|
|
||||||
from calibre import browser, url_slash_cleaner
|
|
||||||
from calibre.gui2 import open_url
|
|
||||||
from calibre.gui2.store import StorePlugin
|
|
||||||
from calibre.gui2.store.basic_config import BasicStoreConfig
|
from calibre.gui2.store.basic_config import BasicStoreConfig
|
||||||
|
from calibre.gui2.store.opensearch_store import OpenSearchStore
|
||||||
from calibre.gui2.store.search_result import SearchResult
|
from calibre.gui2.store.search_result import SearchResult
|
||||||
from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
|
||||||
|
|
||||||
class EpubBudStore(BasicStoreConfig, StorePlugin):
|
class EpubBudStore(BasicStoreConfig, OpenSearchStore):
|
||||||
|
|
||||||
def open(self, parent=None, detail_item=None, external=False):
|
open_search_url = 'http://www.epubbud.com/feeds/opensearch.xml'
|
||||||
url = 'http://epubbud.com/'
|
web_url = 'http://www.epubbud.com/'
|
||||||
|
|
||||||
if external or self.config.get('open_external', False):
|
# http://www.epubbud.com/feeds/catalog.atom
|
||||||
open_url(QUrl(url_slash_cleaner(detail_item if detail_item else url)))
|
|
||||||
else:
|
|
||||||
d = WebStoreDialog(self.gui, url, parent, detail_item)
|
|
||||||
d.setWindowTitle(self.name)
|
|
||||||
d.set_tags(self.config.get('tags', ''))
|
|
||||||
d.exec_()
|
|
||||||
|
|
||||||
def search(self, query, max_results=10, timeout=60):
|
def search(self, query, max_results=10, timeout=60):
|
||||||
'''
|
for s in OpenSearchStore.search(self, query, max_results, timeout):
|
||||||
OPDS based search.
|
s.price = '$0.00'
|
||||||
|
s.drm = SearchResult.DRM_UNLOCKED
|
||||||
We really should get the catelog from http://pragprog.com/catalog.opds
|
s.formats = 'EPUB'
|
||||||
and look for the application/opensearchdescription+xml entry.
|
yield s
|
||||||
Then get the opensearch description to get the search url and
|
|
||||||
format. However, we are going to be lazy and hard code it.
|
|
||||||
'''
|
|
||||||
url = 'http://www.epubbud.com/search.php?format=atom&q=' + urllib.quote_plus(query)
|
|
||||||
|
|
||||||
br = browser()
|
|
||||||
|
|
||||||
counter = max_results
|
|
||||||
with closing(br.open(url, timeout=timeout)) as f:
|
|
||||||
# Use html instead of etree as html allows us
|
|
||||||
# to ignore the namespace easily.
|
|
||||||
doc = html.fromstring(f.read())
|
|
||||||
for data in doc.xpath('//entry'):
|
|
||||||
if counter <= 0:
|
|
||||||
break
|
|
||||||
|
|
||||||
id = ''.join(data.xpath('.//id/text()'))
|
|
||||||
if not id:
|
|
||||||
continue
|
|
||||||
|
|
||||||
cover_url = ''.join(data.xpath('.//link[@rel="http://opds-spec.org/thumbnail"]/@href'))
|
|
||||||
|
|
||||||
title = u''.join(data.xpath('.//title/text()'))
|
|
||||||
author = u''.join(data.xpath('.//author/name/text()'))
|
|
||||||
|
|
||||||
counter -= 1
|
|
||||||
|
|
||||||
s = SearchResult()
|
|
||||||
s.cover_url = cover_url
|
|
||||||
s.title = title.strip()
|
|
||||||
s.author = author.strip()
|
|
||||||
s.price = '$0.00'
|
|
||||||
s.detail_item = id.strip()
|
|
||||||
s.drm = SearchResult.DRM_UNLOCKED
|
|
||||||
s.formats = 'EPUB'
|
|
||||||
|
|
||||||
yield s
|
|
||||||
|
@ -54,7 +54,7 @@ class OpenSearchStore(StorePlugin):
|
|||||||
links = r.get('links', None)
|
links = r.get('links', None)
|
||||||
for l in links:
|
for l in links:
|
||||||
if l.get('rel', None):
|
if l.get('rel', None):
|
||||||
if l['rel'] == u'http://opds-spec.org/image/thumbnail':
|
if l['rel'] in ('http://opds-spec.org/thumbnail', 'http://opds-spec.org/image/thumbnail'):
|
||||||
s.cover_url = l.get('href', '')
|
s.cover_url = l.get('href', '')
|
||||||
elif l['rel'] == u'http://opds-spec.org/acquisition/buy':
|
elif l['rel'] == u'http://opds-spec.org/acquisition/buy':
|
||||||
s.detail_item = l.get('href', s.detail_item)
|
s.detail_item = l.get('href', s.detail_item)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user