mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update ebooks.com plugin for website changes.
Fixes #2109433 [affiliate link not working](https://bugs.launchpad.net/calibre/+bug/2109433)
This commit is contained in:
parent
b786d44c21
commit
aafa372468
@ -2,7 +2,7 @@
|
|||||||
# License: GPLv3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPLv3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
store_version = 4 # Needed for dynamic plugin loading
|
store_version = 5 # Needed for dynamic plugin loading
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
@ -12,14 +12,11 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from urllib import quote_plus
|
from urllib import quote_plus
|
||||||
|
|
||||||
from qt.core import QUrl
|
|
||||||
|
|
||||||
from calibre import browser, url_slash_cleaner
|
from calibre import browser
|
||||||
from calibre.gui2 import open_url
|
|
||||||
from calibre.gui2.store import StorePlugin
|
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.search_result import SearchResult
|
from calibre.gui2.store.search_result import SearchResult
|
||||||
from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
|
||||||
|
|
||||||
|
|
||||||
def absolutize(url):
|
def absolutize(url):
|
||||||
@ -63,13 +60,23 @@ def search_ec(query, max_results=10, timeout=60, write_html_to=''):
|
|||||||
yield s
|
yield s
|
||||||
|
|
||||||
|
|
||||||
|
storage = []
|
||||||
|
|
||||||
|
|
||||||
def ec_details(search_result, timeout=30, write_data_to=''):
|
def ec_details(search_result, timeout=30, write_data_to=''):
|
||||||
import json
|
import json
|
||||||
br = browser()
|
|
||||||
with closing(br.open(search_result.ebooks_com_api_url, timeout=timeout)) as f:
|
from calibre.scraper.simple import read_url
|
||||||
raw = f.read()
|
# cloudflared endpoint, sigh
|
||||||
|
# https://www.ebooks.com/api/book/?bookId=362956&countryCode=IN
|
||||||
|
raw = read_url(storage, search_result.ebooks_com_api_url)
|
||||||
|
# rq = Request(search_result.ebooks_com_api_url, headers={'Content-Type': 'application/json'})
|
||||||
|
# br = browser()
|
||||||
|
# br.set_debug_http(True)
|
||||||
|
# with closing(br.open(rq, timeout=timeout)) as f:
|
||||||
|
# raw = f.read()
|
||||||
if write_data_to:
|
if write_data_to:
|
||||||
with open(write_data_to, 'wb') as d:
|
with open(write_data_to, 'w') as d:
|
||||||
d.write(raw)
|
d.write(raw)
|
||||||
data = json.loads(raw)
|
data = json.loads(raw)
|
||||||
if 'drm' in data and 'drm_free' in data['drm']:
|
if 'drm' in data and 'drm_free' in data['drm']:
|
||||||
@ -84,24 +91,6 @@ def ec_details(search_result, timeout=30, write_data_to=''):
|
|||||||
|
|
||||||
class EbookscomStore(BasicStoreConfig, StorePlugin):
|
class EbookscomStore(BasicStoreConfig, StorePlugin):
|
||||||
|
|
||||||
def open(self, parent=None, detail_item=None, external=False):
|
|
||||||
m_url = 'http://www.dpbolvw.net/'
|
|
||||||
h_click = 'click-4913808-10364500'
|
|
||||||
d_click = 'click-4913808-10281551'
|
|
||||||
|
|
||||||
url = m_url + h_click
|
|
||||||
detail_url = None
|
|
||||||
if detail_item:
|
|
||||||
detail_url = m_url + d_click + detail_item
|
|
||||||
|
|
||||||
if external or self.config.get('open_external', False):
|
|
||||||
open_url(QUrl(url_slash_cleaner(detail_url if detail_url else url)))
|
|
||||||
else:
|
|
||||||
d = WebStoreDialog(self.gui, url, parent, detail_url)
|
|
||||||
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):
|
||||||
yield from search_ec(query, max_results, timeout)
|
yield from search_ec(query, max_results, timeout)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user