33import urllib
44
55
6-
76def xpath (node , path ):
87 tree = node .getroottree ()
98 base_xpath = tree .getpath (node )
109
1110 return tree .xpath (base_xpath + path )
1211
12+
1313class LibgenMirror :
1414 def __init__ (self , url , format , size , unit ):
1515 self .url = url
@@ -23,6 +23,7 @@ def parse(node, file_type, file_size, file_size_unit):
2323
2424 return LibgenMirror (url , file_type , file_size , file_size_unit )
2525
26+
2627class LibgenBook :
2728 def __init__ (self , title , authors , series , md5 , mirrors , language ,
2829 image_url ):
@@ -101,18 +102,26 @@ def parse(node):
101102class LibgenFictionClient :
102103 def __init__ (self , mirror = None ):
103104
104- MIRRORS = [
105- "libgen.is" ,
106- # "libgen.lc", # Still has the old-style search
107- "gen.lib.rus.ec" ,
108- "93.174.95.27" ,
109- ]
110-
111105 if mirror is None :
112- self .base_url = "http://{}/fiction/" .format (random .choice (MIRRORS ))
106+ mirrors = self .get_mirrors_from_txt ('MIRRORS.txt' )
107+ self .base_url = "http://{}/fiction/" .format (random .choice (mirrors ))
113108 else :
114109 self .base_url = "http://{}/fiction/" .format (mirror )
115110
111+ def get_mirrors_from_txt (self , txt ):
112+ mirrors = []
113+
114+ with open (txt , mode = 'r' ) as mirrors_txt :
115+ for line in mirrors_txt .readlines ():
116+ line = line .strip ()
117+
118+ if len (line ) == 0 or line [0 ] == '#' :
119+ continue
120+
121+ mirrors .append (line )
122+
123+ return mirrors
124+
116125 def search (self , query ):
117126 url = self .base_url
118127 query_params = {
0 commit comments