Skip to content

Commit

Permalink
Revert "Move mirrors to TXT file"
Browse files Browse the repository at this point in the history
This reverts commit 44605c4.
  • Loading branch information
harmtemolder committed Aug 8, 2020
1 parent 44605c4 commit 6f79edb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
6 changes: 0 additions & 6 deletions MIRRORS.txt

This file was deleted.

27 changes: 9 additions & 18 deletions libgen_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import urllib



def xpath(node, path):
tree = node.getroottree()
base_xpath = tree.getpath(node)

return tree.xpath(base_xpath + path)


class LibgenMirror:
def __init__(self, url, format, size, unit):
self.url = url
Expand All @@ -23,7 +23,6 @@ def parse(node, file_type, file_size, file_size_unit):

return LibgenMirror(url, file_type, file_size, file_size_unit)


class LibgenBook:
def __init__(self, title, authors, series, md5, mirrors, language,
image_url):
Expand Down Expand Up @@ -102,26 +101,18 @@ def parse(node):
class LibgenFictionClient:
def __init__(self, mirror=None):

MIRRORS = [
"libgen.is",
# "libgen.lc", # Still has the old-style search
"gen.lib.rus.ec",
"93.174.95.27",
]

if mirror is None:
mirrors = self.get_mirrors_from_txt('MIRRORS.txt')
self.base_url = "http://{}/fiction/".format(random.choice(mirrors))
self.base_url = "http://{}/fiction/".format(random.choice(MIRRORS))
else:
self.base_url = "http://{}/fiction/".format(mirror)

def get_mirrors_from_txt(self, txt):
mirrors = []

with open(txt, mode='r') as mirrors_txt:
for line in mirrors_txt.readlines():
line = line.strip()

if len(line) == 0 or line[0] == '#':
continue

mirrors.append(line)

return mirrors

def search(self, query):
url = self.base_url
query_params = {
Expand Down

0 comments on commit 6f79edb

Please sign in to comment.