mirror of
https://github.com/vikstrous/pirate-get
synced 2025-01-10 10:04:21 +01:00
rename new modules
This commit is contained in:
parent
0ed859a1b0
commit
62703bbf7d
@ -36,6 +36,7 @@ from io import StringIO, BytesIO
|
|||||||
|
|
||||||
class NoRedirection(urllib2.HTTPErrorProcessor):
|
class NoRedirection(urllib2.HTTPErrorProcessor):
|
||||||
|
|
||||||
|
class NoRedirection(request.HTTPErrorProcessor):
|
||||||
def http_response(self, request, response):
|
def http_response(self, request, response):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@ -73,7 +74,7 @@ class MyHTMLParser(HTMLParser):
|
|||||||
def main():
|
def main():
|
||||||
|
|
||||||
# new ConfigParser
|
# new ConfigParser
|
||||||
config = ConfigParser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
|
||||||
# default options so we dont die later
|
# default options so we dont die later
|
||||||
config.add_section('SaveToFile')
|
config.add_section('SaveToFile')
|
||||||
@ -220,12 +221,12 @@ def main():
|
|||||||
pass
|
pass
|
||||||
except IndexError as e:
|
except IndexError as e:
|
||||||
pass
|
pass
|
||||||
return __builtin__.print(*args, **kwargs)
|
return builtins.print(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
def n_print(*args, **kwargs):
|
def n_print(*args, **kwargs):
|
||||||
if("color" in kwargs):
|
if("color" in kwargs):
|
||||||
kwargs.pop('color')
|
kwargs.pop('color')
|
||||||
return __builtin__.print(*args, **kwargs)
|
return builtins.print(*args, **kwargs)
|
||||||
return n_print
|
return n_print
|
||||||
|
|
||||||
print=make_print()
|
print=make_print()
|
||||||
@ -264,7 +265,7 @@ def main():
|
|||||||
else:
|
else:
|
||||||
mirrors = ["http://thepiratebay.se"]
|
mirrors = ["http://thepiratebay.se"]
|
||||||
try:
|
try:
|
||||||
opener = urllib2.build_opener(NoRedirection)
|
opener = request.build_opener(NoRedirection)
|
||||||
f = opener.open("https://proxybay.info/list.txt")
|
f = opener.open("https://proxybay.info/list.txt")
|
||||||
if f.getcode() != 200:
|
if f.getcode() != 200:
|
||||||
raise Exception("The pirate bay responded with an error.")
|
raise Exception("The pirate bay responded with an error.")
|
||||||
@ -316,15 +317,17 @@ def main():
|
|||||||
path = '/torrent/' + identifiers[int(link)] + '/'
|
path = '/torrent/' + identifiers[int(link)] + '/'
|
||||||
request = urllib2.Request(mirror + path)
|
request = urllib2.Request(mirror + path)
|
||||||
request.add_header('Accept-encoding', 'gzip')
|
request.add_header('Accept-encoding', 'gzip')
|
||||||
f = urllib2.urlopen(request)
|
f = request.urlopen(request)
|
||||||
|
|
||||||
if f.info().get('Content-Encoding') == 'gzip':
|
if f.info().get('Content-Encoding') == 'gzip':
|
||||||
buf = StringIO(f.read())
|
buf = StringIO(f.read())
|
||||||
f = gzip.GzipFile(fileobj=buf)
|
f = gzip.GzipFile(fileobj=buf)
|
||||||
res = f.read()
|
res = f.read()
|
||||||
name = re.search("dn=([^\&]*)", mags[int(link)][0])
|
name = re.search("dn=([^\&]*)", mags[int(link)][0])
|
||||||
torrent_name = urllib.unquote(name.group(1).encode('ascii')) \
|
torrent_name = parse.unquote(name.group(1)).replace("+", " ")
|
||||||
.decode('utf-8').replace("+", " ")
|
desc = re.search(r"<div class=\"nfo\">\s*<pre>(.+?)(?=</pre>)",
|
||||||
desc = re.search(r"<div class=\"nfo\">\s*<pre>(.+?)(?=</pre>)", res, re.DOTALL).group(1)
|
res, re.DOTALL).group(1)
|
||||||
|
|
||||||
# Replace HTML links with markdown style versions
|
# Replace HTML links with markdown style versions
|
||||||
desc = re.sub(r"<a href=\"\s*([^\"]+?)\s*\"[^>]*>(\s*)([^<]+?)(\s*)</a>", r"\2[\3](\1)\4", desc)
|
desc = re.sub(r"<a href=\"\s*([^\"]+?)\s*\"[^>]*>(\s*)([^<]+?)(\s*)</a>", r"\2[\3](\1)\4", desc)
|
||||||
print ('Description for "' + torrent_name + '":', color="zebra_1")
|
print ('Description for "' + torrent_name + '":', color="zebra_1")
|
||||||
@ -334,12 +337,13 @@ def main():
|
|||||||
for link in chosen_links:
|
for link in chosen_links:
|
||||||
path = '/ajax_details_filelist.php'
|
path = '/ajax_details_filelist.php'
|
||||||
query = '?id=' + identifiers[int(link)]
|
query = '?id=' + identifiers[int(link)]
|
||||||
request = urllib2.Request(mirror + path + query)
|
request = request.Request(mirror + path + query)
|
||||||
request.add_header('Accept-encoding', 'gzip')
|
request.add_header('Accept-encoding', 'gzip')
|
||||||
f = urllib2.urlopen(request)
|
f = request.urlopen(request)
|
||||||
|
|
||||||
if f.info().get('Content-Encoding') == 'gzip':
|
if f.info().get('Content-Encoding') == 'gzip':
|
||||||
buf = StringIO(f.read())
|
f = gzip.GzipFile(fileobj=BytesIO(f.read()))
|
||||||
f = gzip.GzipFile(fileobj=buf)
|
|
||||||
res = f.read().replace(" ", " ")
|
res = f.read().replace(" ", " ")
|
||||||
files = re.findall(r"<td align=\"left\">\s*([^<]+?)\s*</td><td align=\"right\">\s*([^<]+?)\s*</tr>", res)
|
files = re.findall(r"<td align=\"left\">\s*([^<]+?)\s*</td><td align=\"right\">\s*([^<]+?)\s*</tr>", res)
|
||||||
name = re.search("dn=([^\&]*)", mags[int(link)][0])
|
name = re.search("dn=([^\&]*)", mags[int(link)][0])
|
||||||
|
Loading…
Reference in New Issue
Block a user