mirror of
https://github.com/vikstrous/pirate-get
synced 2025-02-03 13:24:21 +01:00
Set the mirror I want in the config or on cli.
This commit is contained in:
parent
34e3c66a4f
commit
ced657b58d
17
README.md
17
README.md
@ -57,8 +57,21 @@ transmission = false
|
|||||||
colors = true
|
colors = true
|
||||||
```
|
```
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
Any command line option will override its respective setting in the config file.
|
Any command line option will override its respective setting in the config file.
|
||||||
|
|
||||||
|
## Set your pirate bay mirror
|
||||||
|
|
||||||
|
Pirate-get will try to search torrents on
|
||||||
|
`https://thepiratebay.mn`. If that fails, it will try to get a list of
|
||||||
|
mirrors from 'https://proxybay.co/list.txt'. If that fails too, you
|
||||||
|
can set a mirror that is working for you. Set it on the command line
|
||||||
|
with the option `--mirror=<url>`, or in the config file:
|
||||||
|
|
||||||
|
```
|
||||||
|
[Mirror]
|
||||||
|
url = http://tpb.today # without quotes
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Local Database
|
## Local Database
|
||||||
|
115
pirate/pirate.py
115
pirate/pirate.py
@ -24,6 +24,8 @@ import pirate.local
|
|||||||
from os.path import expanduser, expandvars
|
from os.path import expanduser, expandvars
|
||||||
from pirate.print import Printer
|
from pirate.print import Printer
|
||||||
|
|
||||||
|
MIRROR_DEFAULT = 'https://thepiratebay.mn'
|
||||||
|
MIRROR_SOURCE = 'https://proxybay.co/list.txt'
|
||||||
|
|
||||||
def parse_config_file(text):
|
def parse_config_file(text):
|
||||||
config = configparser.RawConfigParser()
|
config = configparser.RawConfigParser()
|
||||||
@ -44,6 +46,10 @@ def parse_config_file(text):
|
|||||||
config.set('Misc', 'transmission', 'false')
|
config.set('Misc', 'transmission', 'false')
|
||||||
config.set('Misc', 'colors', 'true')
|
config.set('Misc', 'colors', 'true')
|
||||||
|
|
||||||
|
# Additional mirror that work for the user.
|
||||||
|
config.add_section('Mirror')
|
||||||
|
config.set('Mirror', 'url', 'https://thepiratebay.mn')
|
||||||
|
|
||||||
config.read_string(text)
|
config.read_string(text)
|
||||||
|
|
||||||
# expand env variables
|
# expand env variables
|
||||||
@ -177,6 +183,9 @@ def parse_args(args_in):
|
|||||||
parser.add_argument('--disable-colors', dest='color',
|
parser.add_argument('--disable-colors', dest='color',
|
||||||
action='store_false',
|
action='store_false',
|
||||||
help='disable colored output')
|
help='disable colored output')
|
||||||
|
parser.add_argument('--mirror', dest='mirror',
|
||||||
|
help='url of a pirate bay mirror. It will be tried first.')
|
||||||
|
|
||||||
args = parser.parse_args(args_in)
|
args = parser.parse_args(args_in)
|
||||||
|
|
||||||
return args
|
return args
|
||||||
@ -229,53 +238,77 @@ def combine_configs(config, args):
|
|||||||
if not args.open_command:
|
if not args.open_command:
|
||||||
args.open_command = config.get('Misc', 'openCommand')
|
args.open_command = config.get('Misc', 'openCommand')
|
||||||
|
|
||||||
|
if not args.mirror and config.get('Mirror', 'url'):
|
||||||
|
args.mirror = config.get('Mirror', 'url')
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
def search_mirrors(printer, pages, category, sort, action, search):
|
def search_on_mirror(printer, pages, category, sort, action, search, mirror):
|
||||||
mirror_sources = [None, 'https://proxybay.co/list.txt']
|
|
||||||
|
try:
|
||||||
|
printer.print('Trying', mirror, end='... \n')
|
||||||
|
results = pirate.torrent.remote(
|
||||||
|
printer=printer,
|
||||||
|
pages=pages,
|
||||||
|
category=pirate.torrent.parse_category(printer, category),
|
||||||
|
sort=pirate.torrent.parse_sort(printer, sort),
|
||||||
|
mode=action,
|
||||||
|
terms=search,
|
||||||
|
mirror=mirror
|
||||||
|
)
|
||||||
|
except (urllib.error.URLError, socket.timeout,
|
||||||
|
IOError, ValueError):
|
||||||
|
printer.print('Failed', color='WARN')
|
||||||
|
else:
|
||||||
|
printer.print('Ok', color='alt')
|
||||||
|
return results, mirror
|
||||||
|
|
||||||
|
return [], None
|
||||||
|
|
||||||
|
def search_mirrors(printer, pages, category, sort, action, search, mirror):
|
||||||
|
"""Search on our mirror first. If not, get a mirror list and try again.
|
||||||
|
Return a tuple results, url of the working mirror.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Search on our mirror, or the default one.
|
||||||
|
if not mirror:
|
||||||
|
mirror = MIRROR_DEFAULT
|
||||||
|
|
||||||
|
results, mirror = search_on_mirror(printer, pages, category, sort, action, search, mirror)
|
||||||
|
if results:
|
||||||
|
return results, mirror
|
||||||
|
|
||||||
|
# If the default mirror failed, get some mirrors.
|
||||||
|
mirror_sources = [MIRROR_SOURCE]
|
||||||
for mirror_source in mirror_sources:
|
for mirror_source in mirror_sources:
|
||||||
mirrors = OrderedDict()
|
mirrors = OrderedDict()
|
||||||
if mirror_source is None:
|
try:
|
||||||
mirrors['https://thepiratebay.mn'] = None
|
req = request.Request(mirror_source,
|
||||||
|
headers=pirate.data.default_headers)
|
||||||
|
f = request.urlopen(req, timeout=pirate.data.default_timeout)
|
||||||
|
except IOError:
|
||||||
|
printer.print('Could not fetch additional mirrors', color='WARN')
|
||||||
else:
|
else:
|
||||||
try:
|
if f.getcode() != 200:
|
||||||
req = request.Request(mirror_source,
|
raise IOError('The proxy bay responded with an error.')
|
||||||
headers=pirate.data.default_headers)
|
# Parse the list of mirrors
|
||||||
f = request.urlopen(req, timeout=pirate.data.default_timeout)
|
for mirror in [i.decode('utf-8').strip() for i in f.readlines()][3:]:
|
||||||
except IOError:
|
mirrors[mirror] = None
|
||||||
printer.print('Could not fetch additional mirrors', color='WARN')
|
for mirror in pirate.data.blacklist:
|
||||||
else:
|
if mirror in mirrors:
|
||||||
if f.getcode() != 200:
|
del mirrors[mirror]
|
||||||
raise IOError('The proxy bay responded with an error.')
|
|
||||||
for mirror in [i.decode('utf-8').strip() for i in f.readlines()][3:]:
|
|
||||||
mirrors[mirror] = None
|
|
||||||
for mirror in pirate.data.blacklist:
|
|
||||||
if mirror in mirrors:
|
|
||||||
del mirrors[mirror]
|
|
||||||
|
|
||||||
for mirror in mirrors.keys():
|
if mirrors:
|
||||||
try:
|
results = []
|
||||||
printer.print('Trying', mirror, end='... \n')
|
while not results:
|
||||||
results = pirate.torrent.remote(
|
results, mirror = search_on_mirror(printer, pages, category, sort, action, search, mirror)
|
||||||
printer=printer,
|
|
||||||
pages=pages,
|
|
||||||
category=pirate.torrent.parse_category(printer, category),
|
|
||||||
sort=pirate.torrent.parse_sort(printer, sort),
|
|
||||||
mode=action,
|
|
||||||
terms=search,
|
|
||||||
mirror=mirror
|
|
||||||
)
|
|
||||||
except (urllib.error.URLError, socket.timeout,
|
|
||||||
IOError, ValueError):
|
|
||||||
printer.print('Failed', color='WARN')
|
|
||||||
else:
|
|
||||||
printer.print('Ok', color='alt')
|
|
||||||
return results, mirror
|
|
||||||
else:
|
|
||||||
printer.print('No available mirrors :(', color='WARN')
|
|
||||||
return [], None
|
|
||||||
|
|
||||||
|
return results, mirror
|
||||||
|
|
||||||
|
else:
|
||||||
|
printer.print('No available mirrors :(', color='WARN')
|
||||||
|
return [], None
|
||||||
|
|
||||||
def pirate_main(args):
|
def pirate_main(args):
|
||||||
printer = Printer(args.color)
|
printer = Printer(args.color)
|
||||||
@ -310,7 +343,9 @@ def pirate_main(args):
|
|||||||
if args.source == 'local_tpb':
|
if args.source == 'local_tpb':
|
||||||
results = pirate.local.search(args.database, args.search)
|
results = pirate.local.search(args.database, args.search)
|
||||||
elif args.source == 'tpb':
|
elif args.source == 'tpb':
|
||||||
results, site = search_mirrors(printer, args.pages, args.category, args.sort, args.action, args.search)
|
results, site = search_mirrors(printer, args.pages, args.category,\
|
||||||
|
args.sort, args.action, args.search,\
|
||||||
|
args.mirror)
|
||||||
|
|
||||||
if len(results) == 0:
|
if len(results) == 0:
|
||||||
printer.print('No results')
|
printer.print('No results')
|
||||||
|
Loading…
Reference in New Issue
Block a user