Skip to content

Commit

Permalink
Gets downloads working
Browse files Browse the repository at this point in the history
  • Loading branch information
fallaciousreasoning committed Aug 23, 2020
1 parent 2365806 commit 2f5dd4d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import (unicode_literals, division, absolute_import, print_function)

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

def get_details(self, search_result, details):
url = self.libgen.get_detail_url(search_result.detail_item)

download = self.libgen.get_download_url(search_result.detail_item)
search_result.downloads[search_result.formats] = download

class LibgenStoreWrapper(StoreBase):
name = PLUGIN_NAME
description = PLUGIN_DESCRIPTION
Expand Down
19 changes: 19 additions & 0 deletions libgen_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,25 @@ def get_detail_url(self, md5):

return detail_url

def get_download_url(self, md5):
download_urls = [
'http://93.174.95.29/fiction/{}'.format(md5),
'https://libgen.lc/foreignfiction/ads.php?md5={}'.format(md5)
]

for url in download_urls:
try:
request = urllib.urlopen(url)
html = request.read()

parser = etree.HTMLParser()
tree = etree.fromstring(html, parser)

SELECTOR = "//h2/a[contains(., 'GET')]"
link = tree.xpath(SELECTOR)
return link[0].get('href')
except:
continue

if __name__ == "__main__":
client = LibgenFictionClient()
Expand Down

0 comments on commit 2f5dd4d

Please sign in to comment.