mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Get Books: Update the Project Gutenberg plugin for the changes to the PG site
This commit is contained in:
parent
23e620a0d5
commit
74e0716c27
@ -22,10 +22,10 @@ from calibre.gui2.store.search_result import SearchResult
|
|||||||
from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
||||||
|
|
||||||
class GutenbergStore(BasicStoreConfig, StorePlugin):
|
class GutenbergStore(BasicStoreConfig, StorePlugin):
|
||||||
|
|
||||||
def open(self, parent=None, detail_item=None, external=False):
|
def open(self, parent=None, detail_item=None, external=False):
|
||||||
url = 'http://gutenberg.org/'
|
url = 'http://gutenberg.org/'
|
||||||
|
|
||||||
if detail_item:
|
if detail_item:
|
||||||
detail_item = url_slash_cleaner(url + detail_item)
|
detail_item = url_slash_cleaner(url + detail_item)
|
||||||
|
|
||||||
@ -39,46 +39,46 @@ class GutenbergStore(BasicStoreConfig, StorePlugin):
|
|||||||
|
|
||||||
def search(self, query, max_results=10, timeout=60):
|
def search(self, query, max_results=10, timeout=60):
|
||||||
url = 'http://m.gutenberg.org/ebooks/search.mobile/?default_prefix=all&sort_order=title&query=' + urllib.quote_plus(query)
|
url = 'http://m.gutenberg.org/ebooks/search.mobile/?default_prefix=all&sort_order=title&query=' + urllib.quote_plus(query)
|
||||||
|
|
||||||
br = browser()
|
br = browser()
|
||||||
|
|
||||||
counter = max_results
|
counter = max_results
|
||||||
with closing(br.open(url, timeout=timeout)) as f:
|
with closing(br.open(url, timeout=timeout)) as f:
|
||||||
doc = html.fromstring(f.read())
|
doc = html.fromstring(f.read())
|
||||||
for data in doc.xpath('//ol[@class="results"]//li[contains(@class, "icon_title") and not(contains(@class, "toplink"))]'):
|
for data in doc.xpath('//ol[@class="results"]/li[@class="booklink"]'):
|
||||||
if counter <= 0:
|
if counter <= 0:
|
||||||
break
|
break
|
||||||
|
|
||||||
id = ''.join(data.xpath('./a/@href'))
|
id = ''.join(data.xpath('./a/@href'))
|
||||||
id = id.split('.mobile')[0]
|
id = id.split('.mobile')[0]
|
||||||
|
|
||||||
title = ''.join(data.xpath('.//span[@class="title"]/text()'))
|
title = ''.join(data.xpath('.//span[@class="title"]/text()'))
|
||||||
author = ''.join(data.xpath('.//span[@class="subtitle"]/text()'))
|
author = ''.join(data.xpath('.//span[@class="subtitle"]/text()'))
|
||||||
|
|
||||||
counter -= 1
|
counter -= 1
|
||||||
|
|
||||||
s = SearchResult()
|
s = SearchResult()
|
||||||
s.cover_url = ''
|
s.cover_url = ''
|
||||||
|
|
||||||
s.detail_item = id.strip()
|
s.detail_item = id.strip()
|
||||||
s.title = title.strip()
|
s.title = title.strip()
|
||||||
s.author = author.strip()
|
s.author = author.strip()
|
||||||
s.price = '$0.00'
|
s.price = '$0.00'
|
||||||
s.drm = SearchResult.DRM_UNLOCKED
|
s.drm = SearchResult.DRM_UNLOCKED
|
||||||
|
|
||||||
yield s
|
yield s
|
||||||
|
|
||||||
def get_details(self, search_result, timeout):
|
def get_details(self, search_result, timeout):
|
||||||
url = url_slash_cleaner('http://m.gutenberg.org/' + search_result.detail_item)
|
url = url_slash_cleaner('http://m.gutenberg.org/' + search_result.detail_item)
|
||||||
|
|
||||||
br = browser()
|
br = browser()
|
||||||
with closing(br.open(url, timeout=timeout)) as nf:
|
with closing(br.open(url, timeout=timeout)) as nf:
|
||||||
doc = html.fromstring(nf.read())
|
doc = html.fromstring(nf.read())
|
||||||
|
|
||||||
for save_item in doc.xpath('//li[contains(@class, "icon_save")]/a'):
|
for save_item in doc.xpath('//li[contains(@class, "icon_save")]/a'):
|
||||||
type = save_item.get('type')
|
type = save_item.get('type')
|
||||||
href = save_item.get('href')
|
href = save_item.get('href')
|
||||||
|
|
||||||
if type:
|
if type:
|
||||||
ext = mimetypes.guess_extension(type)
|
ext = mimetypes.guess_extension(type)
|
||||||
if ext:
|
if ext:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user