Skip to content

Commit 44605c4

Browse files
committed
Move mirrors to TXT file
1 parent 4e76bd8 commit 44605c4

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

MIRRORS.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
libgen.is
2+
gen.lib.rus.ec
3+
93.174.95.27
4+
5+
# Do not use:
6+
# libgen.lc (has the old-style search)

libgen_client.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import urllib
44

55

6-
76
def xpath(node, path):
87
tree = node.getroottree()
98
base_xpath = tree.getpath(node)
109

1110
return tree.xpath(base_xpath + path)
1211

12+
1313
class 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+
2627
class LibgenBook:
2728
def __init__(self, title, authors, series, md5, mirrors, language,
2829
image_url):
@@ -101,18 +102,26 @@ def parse(node):
101102
class 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

Comments
 (0)