mirror of
https://github.com/vikstrous/pirate-get
synced 2025-01-10 10:04:21 +01:00
use try-else and bring back thepiratebay.se
This commit is contained in:
parent
0bee36746e
commit
69f165ea90
@ -150,6 +150,9 @@ def print(*args, **kwargs):
|
|||||||
if kwargs.get('color', False) and colored_output:
|
if kwargs.get('color', False) and colored_output:
|
||||||
try:
|
try:
|
||||||
import colorama
|
import colorama
|
||||||
|
except (ImportError):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
colorama.init()
|
colorama.init()
|
||||||
color_dict = {
|
color_dict = {
|
||||||
'default': '',
|
'default': '',
|
||||||
@ -162,8 +165,6 @@ def print(*args, **kwargs):
|
|||||||
|
|
||||||
c = color_dict[kwargs.pop('color')]
|
c = color_dict[kwargs.pop('color')]
|
||||||
args = (c + args[0],) + args[1:] + (colorama.Style.RESET_ALL,)
|
args = (c + args[0],) + args[1:] + (colorama.Style.RESET_ALL,)
|
||||||
except (KeyError, IndexError, ImportError):
|
|
||||||
pass
|
|
||||||
kwargs.pop('color', None)
|
kwargs.pop('color', None)
|
||||||
return builtins.print(*args, **kwargs)
|
return builtins.print(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
@ -430,10 +431,11 @@ def save_torrents(chosen_links, mags, folder):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
torrent = get_torrent(info_hash)
|
torrent = get_torrent(info_hash)
|
||||||
open(file,'wb').write(torrent)
|
|
||||||
print('Saved {:X} in {}'.format(info_hash, file))
|
|
||||||
except HTTPError:
|
except HTTPError:
|
||||||
print('There is no cached file for this torrent :(', color='ERROR')
|
print('There is no cached file for this torrent :(', color='ERROR')
|
||||||
|
else:
|
||||||
|
open(file,'wb').write(torrent)
|
||||||
|
print('Saved {:X} in {}'.format(info_hash, file))
|
||||||
|
|
||||||
|
|
||||||
def save_magnets(chosen_links, mags, folder):
|
def save_magnets(chosen_links, mags, folder):
|
||||||
@ -544,26 +546,29 @@ def main():
|
|||||||
sizes, uploaded = [], []
|
sizes, uploaded = [], []
|
||||||
|
|
||||||
else:
|
else:
|
||||||
mags, mirrors = [], []
|
mags, mirrors = [], set(['https://thepiratebay.se'])
|
||||||
try:
|
try:
|
||||||
opener = request.build_opener(NoRedirection)
|
opener = request.build_opener(NoRedirection)
|
||||||
f = opener.open('https://proxybay.info/list.txt',
|
f = opener.open('https://proxybay.info/list.txt',
|
||||||
timeout=default_timeout)
|
timeout=default_timeout)
|
||||||
if f.getcode() != 200:
|
|
||||||
raise IOError('The pirate bay responded with an error.')
|
|
||||||
mirrors.extend([i.decode('utf-8').strip()
|
|
||||||
for i in f.readlines()][3:])
|
|
||||||
except IOError:
|
except IOError:
|
||||||
print('Could not fetch additional mirrors', color='WARN')
|
print('Could not fetch additional mirrors', color='WARN')
|
||||||
|
else:
|
||||||
|
if f.getcode() != 200:
|
||||||
|
raise IOError('The pirate bay responded with an error.')
|
||||||
|
mirrors.union([i.decode('utf-8').strip()
|
||||||
|
for i in f.readlines()][3:])
|
||||||
|
|
||||||
for mirror in mirrors:
|
for mirror in mirrors:
|
||||||
try:
|
try:
|
||||||
print('Trying', mirror, end='... ')
|
print('Trying', mirror, end='... ')
|
||||||
mags, sizes, uploaded, identifiers = remote(args, mirror)
|
mags, sizes, uploaded, identifiers = remote(args, mirror)
|
||||||
|
except (URLError, IOError, ValueError, timeout) as e:
|
||||||
|
print('Failed', color='WARN')
|
||||||
|
else:
|
||||||
site = mirror
|
site = mirror
|
||||||
print('Ok', color='alt')
|
print('Ok', color='alt')
|
||||||
break
|
break
|
||||||
except (URLError, IOError, ValueError, timeout) as e:
|
|
||||||
print('Failed', color='WARN')
|
|
||||||
else:
|
else:
|
||||||
print('No available mirrors :(', color='WARN')
|
print('No available mirrors :(', color='WARN')
|
||||||
return
|
return
|
||||||
@ -583,9 +588,9 @@ def main():
|
|||||||
else:
|
else:
|
||||||
# New input loop to support different link options
|
# New input loop to support different link options
|
||||||
while True:
|
while True:
|
||||||
try:
|
|
||||||
print("\nSelect links (Type 'h' for more options"
|
print("\nSelect links (Type 'h' for more options"
|
||||||
", 'q' to quit)", end='\b', color='alt')
|
", 'q' to quit)", end='\b', color='alt')
|
||||||
|
try:
|
||||||
l=input(': ')
|
l=input(': ')
|
||||||
except KeyboardInterrupt :
|
except KeyboardInterrupt :
|
||||||
print('\nCancelled.')
|
print('\nCancelled.')
|
||||||
|
Loading…
Reference in New Issue
Block a user