1- from __future__ import ( unicode_literals , division , absolute_import , print_function )
1+ #!/usr/bin/env python3
22
3- from calibre import browser
3+ from functools import partial
4+
5+ from calibre .constants import numeric_version
46from calibre .customize import StoreBase
5- from calibre .devices .usbms .driver import debug_print
7+ from calibre .devices .usbms .driver import debug_print as root_debug_print
68from calibre .gui2 import open_url
79from calibre .gui2 .store import StorePlugin
810from calibre .gui2 .store .search_result import SearchResult
911from calibre .gui2 .store .web_store_dialog import WebStoreDialog
1012from PyQt5 .Qt import QUrl
1113
12- from .libgen_client import LibgenFictionClient
14+ from calibre_plugins . libgen_fiction .libgen_client import LibgenFictionClient
1315
14- store_version = 5 # Needed for dynamic plugin loading
16+ if numeric_version >= (5 , 5 , 0 ):
17+ module_debug_print = partial (root_debug_print , ' the_eye:__init__:' , sep = '' )
18+ else :
19+ module_debug_print = partial (root_debug_print , 'the_eye:__init__:' )
1520
16- __license__ = 'MIT'
17- __copyright__ = 'fallaciousreasoning'
18- __docformat__ = 'restructuredtext en'
21+ __license__ = 'MIT'
22+ __copyright__ = 'fallaciousreasoning'
23+ __docformat__ = 'restructuredtext en'
1924
20- PLUGIN_NAME = 'Libgen Fiction'
21- PLUGIN_DESCRIPTION = 'Adds a Libgen Fiction search provider to Calibre '
22- PLUGIN_AUTHORS = " fallaciousreasoning (https://github.com/fallaciousreasoning/CalibreLibgenStore)"
23- PLUGIN_VERSION = (0 , 2 , 0 )
25+ PLUGIN_NAME = 'Libgen Fiction'
26+ PLUGIN_DESCRIPTION = 'Adds a Libgen Fiction search provider to calibre '
27+ PLUGIN_AUTHORS = ' fallaciousreasoning (https://github.com/fallaciousreasoning/CalibreLibgenStore)'
28+ PLUGIN_VERSION = (0 , 4 , 0 )
2429
2530class LibgenStore (StorePlugin ):
2631 def genesis (self ):
27- '''
28- Initialize the Libgen Client
29- '''
30- debug_print ('Libgen Fiction::__init__.py:LibgenStore:genesis ' )
32+ """Initialize the Libgen Client
33+ """
34+ debug_print = partial ( module_debug_print , 'LibgenStore:genesis:' )
35+ debug_print ('start ' )
3136
3237 self .libgen = LibgenFictionClient ()
3338
3439 def search (self , query , max_results = 10 , timeout = 60 ):
35- '''
36- Searches LibGen for Books. Since the mirror links are not direct
40+ """Searches LibGen for Books. Since the mirror links are not direct
3741 downloads, it should not provide these as `s.downloads`.
38- '''
39-
40- debug_print ('Libgen Fiction::__init__.py:LibgenStore:search:query =' ,
41- query )
42+ """
43+ debug_print = partial (module_debug_print , 'LibgenStore:search:' )
44+ debug_print ('search:query = ' , query )
4245
4346 libgen_results = self .libgen .search (query )
4447
4548 for result in libgen_results .results [:min (max_results , len (libgen_results .results ))]:
46- debug_print ('Libgen Fiction::__init__.py:LibgenStore:search:'
47- 'result.title =' ,
48- result .title )
49+ debug_print ('result.title = ' , result .title )
4950
5051 for mirror in result .mirrors [0 :1 ]: # Calibre only shows 1 anyway
51- debug_print ('Libgen Fiction::__init__.py:LibgenStore:search:'
52- 'result.mirror.url =' , mirror .url )
52+ debug_print ('result.mirror.url = ' , mirror .url )
5353
5454 s = SearchResult ()
5555
@@ -64,27 +64,23 @@ def search(self, query, max_results=10, timeout=60):
6464 s .formats = mirror .format
6565 s .plugin_author = PLUGIN_AUTHORS
6666
67- debug_print ('Libgen Fiction::__init__.py:LibgenStore:search:s =' ,
68- s )
67+ debug_print ('s = ' , s )
6968
7069 yield s
7170
7271 def open (self , parent = None , detail_item = None , external = False ):
73- '''
74- Open the specified item in the external, or Calibre's browser
75- '''
76-
77- debug_print ('Libgen Fiction::__init__.py:LibgenStore:open:locals() =' ,
78- locals ())
72+ """Open the specified item in the external, or Calibre's browser
73+ """
74+ debug_print = partial (module_debug_print , 'LibgenStore:open:' )
75+ debug_print ('locals() = ' , locals ())
7976
8077 detail_url = (
8178 self .libgen .get_detail_url (detail_item )
8279 if detail_item
8380 else self .libgen .base_url
8481 )
8582
86- debug_print ('Libgen Fiction::__init__.py:LibgenStore:open:detail_url =' ,
87- detail_url )
83+ debug_print ('detail_url = ' , detail_url )
8884
8985 if external or self .config .get ('open_external' , False ):
9086 open_url (QUrl (detail_url ))
@@ -97,23 +93,20 @@ def open(self, parent=None, detail_item=None, external=False):
9793
9894 def get_details (self , search_result , details ):
9995 url = self .libgen .get_detail_url (search_result .detail_item )
100-
10196 download = self .libgen .get_download_url (search_result .detail_item )
10297 search_result .downloads [search_result .formats ] = download
103-
98+
10499class LibgenStoreWrapper (StoreBase ):
105100 name = PLUGIN_NAME
106101 description = PLUGIN_DESCRIPTION
107- supported_platforms = ['windows' , 'osx' , 'linux' ]
108102 author = PLUGIN_AUTHORS
109103 version = PLUGIN_VERSION
110- minimum_calibre_version = (1 , 0 , 0 )
104+ minimum_calibre_version = (5 , 0 , 1 ) # Because Python 3
111105 affiliate = False
112106 drm_free_only = True
113107
114108 def load_actual_plugin (self , gui ):
115- '''
116- This method must return the actual interface action plugin object.
117- '''
109+ """This method must return the actual interface action plugin object.
110+ """
118111 self .actual_plugin_object = LibgenStore (gui , self .name )
119112 return self .actual_plugin_object
0 commit comments