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
13
README.md
13
README.md
@ -60,6 +60,19 @@ colors = true
|
||||
Note:
|
||||
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
|
||||
If you want to use a local copy of the Pirate Bay database download a copy here (or wherever the latest version is currently):
|
||||
|
@ -24,6 +24,8 @@ import pirate.local
|
||||
from os.path import expanduser, expandvars
|
||||
from pirate.print import Printer
|
||||
|
||||
MIRROR_DEFAULT = 'https://thepiratebay.mn'
|
||||
MIRROR_SOURCE = 'https://proxybay.co/list.txt'
|
||||
|
||||
def parse_config_file(text):
|
||||
config = configparser.RawConfigParser()
|
||||
@ -44,6 +46,10 @@ def parse_config_file(text):
|
||||
config.set('Misc', 'transmission', 'false')
|
||||
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)
|
||||
|
||||
# expand env variables
|
||||
@ -177,6 +183,9 @@ def parse_args(args_in):
|
||||
parser.add_argument('--disable-colors', dest='color',
|
||||
action='store_false',
|
||||
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)
|
||||
|
||||
return args
|
||||
@ -229,32 +238,14 @@ def combine_configs(config, args):
|
||||
if not args.open_command:
|
||||
args.open_command = config.get('Misc', 'openCommand')
|
||||
|
||||
if not args.mirror and config.get('Mirror', 'url'):
|
||||
args.mirror = config.get('Mirror', 'url')
|
||||
|
||||
return args
|
||||
|
||||
|
||||
def search_mirrors(printer, pages, category, sort, action, search):
|
||||
mirror_sources = [None, 'https://proxybay.co/list.txt']
|
||||
for mirror_source in mirror_sources:
|
||||
mirrors = OrderedDict()
|
||||
if mirror_source is None:
|
||||
mirrors['https://thepiratebay.mn'] = None
|
||||
else:
|
||||
try:
|
||||
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:
|
||||
if f.getcode() != 200:
|
||||
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]
|
||||
def search_on_mirror(printer, pages, category, sort, action, search, mirror):
|
||||
|
||||
for mirror in mirrors.keys():
|
||||
try:
|
||||
printer.print('Trying', mirror, end='... \n')
|
||||
results = pirate.torrent.remote(
|
||||
@ -272,11 +263,53 @@ def search_mirrors(printer, pages, category, sort, action, search):
|
||||
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:
|
||||
mirrors = OrderedDict()
|
||||
try:
|
||||
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:
|
||||
if f.getcode() != 200:
|
||||
raise IOError('The proxy bay responded with an error.')
|
||||
# Parse the list of mirrors
|
||||
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]
|
||||
|
||||
if mirrors:
|
||||
results = []
|
||||
while not results:
|
||||
results, mirror = search_on_mirror(printer, pages, category, sort, action, search, mirror)
|
||||
|
||||
return results, mirror
|
||||
|
||||
else:
|
||||
printer.print('No available mirrors :(', color='WARN')
|
||||
return [], None
|
||||
|
||||
|
||||
def pirate_main(args):
|
||||
printer = Printer(args.color)
|
||||
|
||||
@ -310,7 +343,9 @@ def pirate_main(args):
|
||||
if args.source == 'local_tpb':
|
||||
results = pirate.local.search(args.database, args.search)
|
||||
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:
|
||||
printer.print('No results')
|
||||
|
Loading…
Reference in New Issue
Block a user