mirror of
https://github.com/vikstrous/pirate-get
synced 2025-01-10 10:04:21 +01:00
Fix encoding errors
This commit is contained in:
parent
62703bbf7d
commit
c817681748
@ -67,7 +67,11 @@ class MyHTMLParser(HTMLParser):
|
|||||||
else:
|
else:
|
||||||
self.state = 'looking'
|
self.state = 'looking'
|
||||||
if self.state == 'magnet':
|
if self.state == 'magnet':
|
||||||
self.results.append(['magnet:?xt=urn:btih:' + urllib.quote(data) + '&dn=' + urllib.quote(self.title), '?', '?'])
|
self.results.append([
|
||||||
|
'magnet:?xt=urn:btih:' +
|
||||||
|
parse.quote(data) +
|
||||||
|
'&dn=' +
|
||||||
|
parse.quote(self.title), '?', '?'])
|
||||||
self.state = 'looking'
|
self.state = 'looking'
|
||||||
|
|
||||||
|
|
||||||
@ -216,7 +220,7 @@ def main():
|
|||||||
"""Print with colors"""
|
"""Print with colors"""
|
||||||
try:
|
try:
|
||||||
c = color_dict[kwargs.pop("color")]
|
c = color_dict[kwargs.pop("color")]
|
||||||
args = (c + str(args[0].encode('utf-8')),) + args[1:] + (colorama.Style.RESET_ALL,)
|
args = (c + args[0],) + args[1:] + (colorama.Style.RESET_ALL,)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
pass
|
pass
|
||||||
except IndexError as e:
|
except IndexError as e:
|
||||||
@ -269,8 +273,8 @@ def main():
|
|||||||
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.")
|
||||||
res = f.read()
|
res = f.read().decode('utf8')
|
||||||
mirrors += res.split("\n")[3:]
|
mirrors.append(res.split("\n")[3:])
|
||||||
except:
|
except:
|
||||||
print("Could not fetch additional mirrors", color="WARN")
|
print("Could not fetch additional mirrors", color="WARN")
|
||||||
for mirror in mirrors:
|
for mirror in mirrors:
|
||||||
@ -306,8 +310,7 @@ def main():
|
|||||||
# Alternate between colors
|
# Alternate between colors
|
||||||
cur_color = "zebra_0" if (cur_color == "zebra_1") else "zebra_1"
|
cur_color = "zebra_0" if (cur_color == "zebra_1") else "zebra_1"
|
||||||
|
|
||||||
torrent_name = urllib.unquote(name.group(1).encode('ascii')) \
|
torrent_name = parse.unquote(name.group(1)).replace("+", " ")
|
||||||
.decode('utf-8').replace("+", " ")
|
|
||||||
# enhanced print output with justified columns
|
# enhanced print output with justified columns
|
||||||
print ("%5d %6d %6d %5.1f %-11s %-11s %s" % (
|
print ("%5d %6d %6d %5.1f %-11s %-11s %s" % (
|
||||||
m, no_seeders, no_leechers, ratio ,sizes[m],
|
m, no_seeders, no_leechers, ratio ,sizes[m],
|
||||||
@ -320,8 +323,8 @@ def main():
|
|||||||
f = request.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()
|
res = f.read()
|
||||||
name = re.search("dn=([^\&]*)", mags[int(link)][0])
|
name = re.search("dn=([^\&]*)", mags[int(link)][0])
|
||||||
torrent_name = parse.unquote(name.group(1)).replace("+", " ")
|
torrent_name = parse.unquote(name.group(1)).replace("+", " ")
|
||||||
@ -347,9 +350,9 @@ def main():
|
|||||||
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])
|
||||||
torrent_name = urllib.unquote(name.group(1).encode('ascii')) \
|
torrent_name = parse.unquote(name.group(1)).replace("+", " ")
|
||||||
.decode('utf-8').replace("+", " ")
|
|
||||||
print ('Files in "' + torrent_name + '":', color="zebra_1")
|
print('Files in "' + torrent_name + '":', color="zebra_1")
|
||||||
cur_color = "zebra_0"
|
cur_color = "zebra_0"
|
||||||
for f in files:
|
for f in files:
|
||||||
print ("%-11s %s" % (f[1], f[0]), color=cur_color)
|
print ("%-11s %s" % (f[1], f[0]), color=cur_color)
|
||||||
|
Loading…
Reference in New Issue
Block a user