mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Get Books: Update Kobo plugin for website changes
This commit is contained in:
parent
7a06376268
commit
200964c4be
@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
store_version = 5 # Needed for dynamic plugin loading
|
store_version = 6 # Needed for dynamic plugin loading
|
||||||
|
|
||||||
__license__ = 'GPL 3'
|
__license__ = 'GPL 3'
|
||||||
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
||||||
@ -12,8 +12,6 @@ from contextlib import closing
|
|||||||
|
|
||||||
from lxml import html, etree
|
from lxml import html, etree
|
||||||
|
|
||||||
from PyQt5.Qt import QUrl
|
|
||||||
|
|
||||||
from calibre import browser, url_slash_cleaner
|
from calibre import browser, url_slash_cleaner
|
||||||
from calibre.ebooks.metadata import authors_to_string
|
from calibre.ebooks.metadata import authors_to_string
|
||||||
from calibre.gui2 import open_url
|
from calibre.gui2 import open_url
|
||||||
@ -25,7 +23,7 @@ from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
|||||||
|
|
||||||
def search_kobo(query, max_results=10, timeout=60, write_html_to=None):
|
def search_kobo(query, max_results=10, timeout=60, write_html_to=None):
|
||||||
from css_selectors import Select
|
from css_selectors import Select
|
||||||
url = 'http://www.kobobooks.com/search/search.html?q=' + urllib.quote_plus(query)
|
url = 'https://www.kobobooks.com/search/search.html?q=' + urllib.quote_plus(query)
|
||||||
|
|
||||||
br = browser()
|
br = browser()
|
||||||
|
|
||||||
@ -42,7 +40,7 @@ def search_kobo(query, max_results=10, timeout=60, write_html_to=None):
|
|||||||
for img in select('.item-image img[src]', item):
|
for img in select('.item-image img[src]', item):
|
||||||
cover_url = img.get('src')
|
cover_url = img.get('src')
|
||||||
if cover_url.startswith('//'):
|
if cover_url.startswith('//'):
|
||||||
cover_url = 'http:' + cover_url
|
cover_url = 'https:' + cover_url
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
cover_url = None
|
cover_url = None
|
||||||
@ -50,7 +48,7 @@ def search_kobo(query, max_results=10, timeout=60, write_html_to=None):
|
|||||||
for p in select('p.title', item):
|
for p in select('p.title', item):
|
||||||
title = etree.tostring(p, method='text', encoding=unicode).strip()
|
title = etree.tostring(p, method='text', encoding=unicode).strip()
|
||||||
for a in select('a[href]', p):
|
for a in select('a[href]', p):
|
||||||
url = 'http://store.kobobooks.com' + a.get('href')
|
url = a.get('href')
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
url = None
|
url = None
|
||||||
@ -59,7 +57,7 @@ def search_kobo(query, max_results=10, timeout=60, write_html_to=None):
|
|||||||
title = None
|
title = None
|
||||||
|
|
||||||
authors = []
|
authors = []
|
||||||
for a in select('p.author a.contributor', item):
|
for a in select('p.contributor-list a.contributor-name', item):
|
||||||
authors.append(etree.tostring(a, method='text', encoding=unicode).strip())
|
authors.append(etree.tostring(a, method='text', encoding=unicode).strip())
|
||||||
authors = authors_to_string(authors)
|
authors = authors_to_string(authors)
|
||||||
|
|
||||||
@ -79,7 +77,7 @@ def search_kobo(query, max_results=10, timeout=60, write_html_to=None):
|
|||||||
s.formats = 'EPUB'
|
s.formats = 'EPUB'
|
||||||
s.drm = SearchResult.DRM_UNKNOWN
|
s.drm = SearchResult.DRM_UNKNOWN
|
||||||
|
|
||||||
yield s
|
yield s
|
||||||
|
|
||||||
|
|
||||||
class KoboStore(BasicStoreConfig, StorePlugin):
|
class KoboStore(BasicStoreConfig, StorePlugin):
|
||||||
@ -88,17 +86,17 @@ class KoboStore(BasicStoreConfig, StorePlugin):
|
|||||||
|
|
||||||
def open(self, parent=None, detail_item=None, external=False):
|
def open(self, parent=None, detail_item=None, external=False):
|
||||||
pub_id = '0dsO3kDu/AU'
|
pub_id = '0dsO3kDu/AU'
|
||||||
murl = 'http://click.linksynergy.com/fs-bin/click?id=%s&subid=&offerid=280046.1&type=10&tmpid=9310&RD_PARM1=http%%3A%%2F%%2Fkobo.com' % pub_id
|
murl = 'https://click.linksynergy.com/fs-bin/click?id=%s&subid=&offerid=280046.1&type=10&tmpid=9310&RD_PARM1=http%%3A%%2F%%2Fkobo.com' % pub_id
|
||||||
|
|
||||||
if detail_item:
|
if detail_item:
|
||||||
purl = 'http://click.linksynergy.com/link?id=%s&offerid=280046&type=2&murl=%s' % (pub_id, urllib.quote_plus(detail_item))
|
purl = 'https://click.linksynergy.com/link?id=%s&offerid=280046&type=2&murl=%s' % (pub_id, urllib.quote_plus(detail_item))
|
||||||
url = purl
|
url = purl
|
||||||
else:
|
else:
|
||||||
purl = None
|
purl = None
|
||||||
url = murl
|
url = murl
|
||||||
|
|
||||||
if external or self.config.get('open_external', False):
|
if external or self.config.get('open_external', False):
|
||||||
open_url(QUrl(url_slash_cleaner(url)))
|
open_url(url_slash_cleaner(url))
|
||||||
else:
|
else:
|
||||||
d = WebStoreDialog(self.gui, murl, parent, purl)
|
d = WebStoreDialog(self.gui, murl, parent, purl)
|
||||||
d.setWindowTitle(self.name)
|
d.setWindowTitle(self.name)
|
||||||
@ -116,6 +114,7 @@ class KoboStore(BasicStoreConfig, StorePlugin):
|
|||||||
search_result.author = ', '.join(idata.xpath('.//h2[contains(@class, "author")]//a/text()'))
|
search_result.author = ', '.join(idata.xpath('.//h2[contains(@class, "author")]//a/text()'))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
for result in search_kobo(' '.join(sys.argv[1:]), write_html_to='/t/kobo.html'):
|
for result in search_kobo(' '.join(sys.argv[1:]), write_html_to='/t/kobo.html'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user