mirror of
https://github.com/vikstrous/pirate-get
synced 2025-01-10 10:04:21 +01:00
Merge pull request #68 from vikstrous/mirror_sources
use an array of mirror sources and check only if necessary
This commit is contained in:
commit
218c3114e5
@ -228,10 +228,14 @@ def combine_configs(config, args):
|
|||||||
|
|
||||||
|
|
||||||
def search_mirrors(pages, category, sort, action, search):
|
def search_mirrors(pages, category, sort, action, search):
|
||||||
|
mirror_sources = [None, 'https://proxybay.co/list.txt']
|
||||||
|
for mirror_source in mirror_sources:
|
||||||
mirrors = OrderedDict()
|
mirrors = OrderedDict()
|
||||||
|
if mirror_source is None:
|
||||||
mirrors['https://thepiratebay.mn'] = None
|
mirrors['https://thepiratebay.mn'] = None
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
req = request.Request('https://proxybay.co/list.txt',
|
req = request.Request(mirror_source,
|
||||||
headers=pirate.data.default_headers)
|
headers=pirate.data.default_headers)
|
||||||
f = request.urlopen(req, timeout=pirate.data.default_timeout)
|
f = request.urlopen(req, timeout=pirate.data.default_timeout)
|
||||||
except IOError:
|
except IOError:
|
||||||
|
@ -122,9 +122,13 @@ class TestPirate(unittest.TestCase):
|
|||||||
with patch('urllib.request.urlopen', return_value=response_obj) as urlopen:
|
with patch('urllib.request.urlopen', return_value=response_obj) as urlopen:
|
||||||
with patch('pirate.torrent.remote', return_value=[]) as remote:
|
with patch('pirate.torrent.remote', return_value=[]) as remote:
|
||||||
results, mirror = pirate.pirate.search_mirrors(pages, category, sort, action, search)
|
results, mirror = pirate.pirate.search_mirrors(pages, category, sort, action, search)
|
||||||
|
self.assertEqual(results, [])
|
||||||
|
self.assertEqual(mirror, 'https://thepiratebay.mn')
|
||||||
remote.assert_called_once_with(pages=1, category=100, sort=10, mode='browse', terms=[], mirror='https://thepiratebay.mn')
|
remote.assert_called_once_with(pages=1, category=100, sort=10, mode='browse', terms=[], mirror='https://thepiratebay.mn')
|
||||||
with patch('pirate.torrent.remote', side_effect=[socket.timeout, []]) as remote:
|
with patch('pirate.torrent.remote', side_effect=[socket.timeout, []]) as remote:
|
||||||
results, mirror = pirate.pirate.search_mirrors(pages, category, sort, action, search)
|
results, mirror = pirate.pirate.search_mirrors(pages, category, sort, action, search)
|
||||||
|
self.assertEqual(results, [])
|
||||||
|
self.assertEqual(mirror, 'https://example.com')
|
||||||
remote.assert_has_calls([
|
remote.assert_has_calls([
|
||||||
call(pages=1, category=100, sort=10, mode='browse', terms=[], mirror='https://thepiratebay.mn'),
|
call(pages=1, category=100, sort=10, mode='browse', terms=[], mirror='https://thepiratebay.mn'),
|
||||||
call(pages=1, category=100, sort=10, mode='browse', terms=[], mirror='https://example.com')
|
call(pages=1, category=100, sort=10, mode='browse', terms=[], mirror='https://example.com')
|
||||||
|
Loading…
Reference in New Issue
Block a user