From 2f5dd4da1b1aac2348e7d47c05f9b67ca324f096 Mon Sep 17 00:00:00 2001 From: Jay Harris Date: Sun, 23 Aug 2020 17:19:18 +1200 Subject: [PATCH] Gets downloads working --- __init__.py | 7 +++++++ libgen_client.py | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/__init__.py b/__init__.py index 3a8d6f2..c6d6297 100644 --- a/__init__.py +++ b/__init__.py @@ -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 @@ -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 diff --git a/libgen_client.py b/libgen_client.py index 63ad3ff..ce8b5ad 100644 --- a/libgen_client.py +++ b/libgen_client.py @@ -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()