Skip to content

Commit 2f5dd4d

Browse files
Gets downloads working
1 parent 2365806 commit 2f5dd4d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import (unicode_literals, division, absolute_import, print_function)
22

3+
from calibre import browser
34
from calibre.customize import StoreBase
45
from calibre.devices.usbms.driver import debug_print
56
from calibre.gui2 import open_url
@@ -94,6 +95,12 @@ def open(self, parent=None, detail_item=None, external=False):
9495
d.set_tags(self.config.get('tags', ''))
9596
d.exec_()
9697

98+
def get_details(self, search_result, details):
99+
url = self.libgen.get_detail_url(search_result.detail_item)
100+
101+
download = self.libgen.get_download_url(search_result.detail_item)
102+
search_result.downloads[search_result.formats] = download
103+
97104
class LibgenStoreWrapper(StoreBase):
98105
name = PLUGIN_NAME
99106
description = PLUGIN_DESCRIPTION

libgen_client.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,25 @@ def get_detail_url(self, md5):
136136

137137
return detail_url
138138

139+
def get_download_url(self, md5):
140+
download_urls = [
141+
'http://93.174.95.29/fiction/{}'.format(md5),
142+
'https://libgen.lc/foreignfiction/ads.php?md5={}'.format(md5)
143+
]
144+
145+
for url in download_urls:
146+
try:
147+
request = urllib.urlopen(url)
148+
html = request.read()
149+
150+
parser = etree.HTMLParser()
151+
tree = etree.fromstring(html, parser)
152+
153+
SELECTOR = "//h2/a[contains(., 'GET')]"
154+
link = tree.xpath(SELECTOR)
155+
return link[0].get('href')
156+
except:
157+
continue
139158

140159
if __name__ == "__main__":
141160
client = LibgenFictionClient()

0 commit comments

Comments
 (0)