mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update Woblink get books plugin to deal with website changes
Merge branch 'master' of https://github.com/t3d/calibre
This commit is contained in:
commit
35d3531bfc
@ -1,28 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||
store_version = 7 # Needed for dynamic plugin loading
|
||||
store_version = 8 # Needed for dynamic plugin loading
|
||||
|
||||
__license__ = 'GPL 3'
|
||||
__copyright__ = '2011-2014, Tomasz Długosz <tomek3d@gmail.com>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import re
|
||||
import urllib
|
||||
from base64 import b64encode
|
||||
from contextlib import closing
|
||||
|
||||
from lxml import html
|
||||
|
||||
from PyQt4.Qt import QUrl
|
||||
|
||||
from calibre import browser, url_slash_cleaner
|
||||
from calibre import 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.search_result import SearchResult
|
||||
from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
||||
|
||||
from calibre.ebooks.chardet import strip_encoding_declarations
|
||||
from calibre.utils.ipc.simple_worker import fork_job, WorkerError
|
||||
|
||||
js_browser = '''
|
||||
from calibre.web.jsbrowser.browser import Browser, Timeout
|
||||
import urllib
|
||||
|
||||
def get_results(url, timeout):
|
||||
browser = Browser(default_timeout=timeout)
|
||||
browser.visit(url)
|
||||
browser.wait_for_element('#nw_content_list')
|
||||
return browser.html
|
||||
'''
|
||||
|
||||
class WoblinkStore(BasicStoreConfig, StorePlugin):
|
||||
|
||||
def open(self, parent=None, detail_item=None, external=False):
|
||||
@ -51,11 +63,13 @@ class WoblinkStore(BasicStoreConfig, StorePlugin):
|
||||
else:
|
||||
url += '&limit=20'
|
||||
|
||||
br = browser()
|
||||
|
||||
counter = max_results
|
||||
with closing(br.open(url, timeout=timeout)) as f:
|
||||
doc = html.fromstring(f.read())
|
||||
|
||||
try:
|
||||
results = fork_job(js_browser,'get_results', (url, timeout,), module_is_source_code=True)
|
||||
except WorkerError as e:
|
||||
raise Exception('Could not get results: %s'%e.orig_tb)
|
||||
doc = html.fromstring(strip_encoding_declarations(results['result']))
|
||||
for data in doc.xpath('//div[@class="nw_katalog_lista_ksiazka"]'):
|
||||
if counter <= 0:
|
||||
break
|
||||
@ -67,9 +81,8 @@ class WoblinkStore(BasicStoreConfig, StorePlugin):
|
||||
cover_url = ''.join(data.xpath('.//div[@class="nw_katalog_lista_ksiazka_okladka nw_okladka"]/a[1]/img/@src'))
|
||||
title = ''.join(data.xpath('.//h2[@class="nw_katalog_lista_ksiazka_detale_tytul"]/a[1]/text()'))
|
||||
author = ', '.join(data.xpath('.//p[@class="nw_katalog_lista_ksiazka_detale_autor"]/a/text()'))
|
||||
price = ''.join(data.xpath('.//div[@class="nw_katalog_lista_ksiazka_opcjezakupu_cena"]/span/text()'))
|
||||
price = re.sub('\.', ',', price)
|
||||
formats = ', '.join(data.xpath('.//p[@class="nw_katalog_lista_ksiazka_detale_formaty"]/span/text()'))
|
||||
price = ''.join(data.xpath('.//div[@class="nw_opcjezakupu_cena"]/text()'))
|
||||
formats = ', '.join(data.xpath('.//p[@class="nw_katalog_lista_ksiazka_detale_format"]/span/text()'))
|
||||
|
||||
s = SearchResult()
|
||||
s.cover_url = 'http://woblink.com' + cover_url
|
||||
@ -79,7 +92,7 @@ class WoblinkStore(BasicStoreConfig, StorePlugin):
|
||||
s.detail_item = id.strip()
|
||||
s.formats = formats
|
||||
|
||||
if 'EPUB DRM' in formats:
|
||||
if 'DRM' in formats:
|
||||
s.drm = SearchResult.DRM_LOCKED
|
||||
|
||||
counter -= 1
|
||||
@ -89,4 +102,3 @@ class WoblinkStore(BasicStoreConfig, StorePlugin):
|
||||
|
||||
counter -= 1
|
||||
yield s
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user