Skip to content

Commit b0176b0

Browse files
Moves to using gross python2 stuff so calibre will work
1 parent c174ff6 commit b0176b0

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

libgen_client.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@
88

99
ID_REGEX = "\?id=[0-9]+"
1010

11-
import requests
12-
import json
13-
from collections import namedtuple
1411
from lxml import etree
15-
1612
import re
13+
import urllib
14+
import urllib2
15+
16+
DEFAULT_FIELDS = "Title,Author,ID,MD5"
17+
18+
LIBGEN_URL = "http://libgen.io/foreignfiction/"
19+
20+
BOOK_ENDPOINT = "json.php?ids={0}&fields={1}"
21+
DOWNLOAD_URL = "get.php?md5={0}"
22+
SEARCH_URL = "index.php"
23+
24+
ID_REGEX = "\?id=[0-9]+"
1725

1826

1927
def _json_object_hook(d): return namedtuple('X', d.keys())(*d.values())
@@ -103,14 +111,16 @@ def search(self, query):
103111
'f_group': 1
104112
}
105113

106-
response = requests.get(url, params=query_params)
114+
query_string = urllib.urlencode(query_params)
115+
request = urllib2.request(url + '?' + query_string)
116+
html = request.read()
107117

108118
parser = etree.HTMLParser()
109-
tree = etree.fromstring(response.text, parser)
119+
tree = etree.fromstring(params, parser)
110120

111121
return LibgenSearchResults.parse(tree)
112122

113123

114124
if __name__ == "__main__":
115-
client = LibgenClient()
125+
client = LibgenFictionClient()
116126
result = client.search("Stormlight Archive")

0 commit comments

Comments
 (0)