Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
harmtemolder committed Nov 28, 2020
2 parents c935903 + 2f5dd4d commit e34d44e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ calibre
# PyCharm
.idea

# VSCode
.vscode/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
A Libgen Fiction store plugin for Calibre

## Installation

Download a release from [here](https://github.com/fallaciousreasoning/CalibreLibgenStore/releases) and follow the instructions to add the plugin to Calibre.
- Download the latest release from [here](https://github.com/fallaciousreasoning/CalibreLibgenStore/releases)
- Open Calibre
- Navigate to Preferences -> Plugins (in the advanced section) -> Load Plugin from File and select the zip file you downloaded.
- Restart Calibre

## Usage
- Click the 'Get Books' menu in Calibre
- Ensure that 'Libgen Fiction' is selected in the search providers menu

![image](https://cloud.githubusercontent.com/assets/7678024/26022030/fefe8b24-37dc-11e7-8373-16c6069fa538.png)
- Search!

## Testing & development

Expand Down
11 changes: 9 additions & 2 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 All @@ -13,12 +14,12 @@
store_version = 5 # Needed for dynamic plugin loading

__license__ = 'MIT'
__copyright__ = 'Fallacious Reasoning'
__copyright__ = 'fallaciousreasoning'
__docformat__ = 'restructuredtext en'

PLUGIN_NAME = 'Libgen Fiction'
PLUGIN_DESCRIPTION = 'Adds a Libgen Fiction search provider to Calibre'
PLUGIN_AUTHORS = "Fallacious Reasoning (https://github.com/fallaciousreasoning/CalibreLibgenStore)"
PLUGIN_AUTHORS = "fallaciousreasoning (https://github.com/fallaciousreasoning/CalibreLibgenStore)"
PLUGIN_VERSION = (0, 2, 0)

class LibgenStore(StorePlugin):
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 e34d44e

Please sign in to comment.