1
0
mirror of https://github.com/vikstrous/pirate-get synced 2025-01-10 10:04:21 +01:00

use an array of mirror sources and check only if necessary

This commit is contained in:
Viktor Stanchev 2015-09-20 00:13:01 -07:00
parent 3d0707f3a7
commit 39b71e0787
2 changed files with 41 additions and 33 deletions

View File

@ -228,10 +228,14 @@ def combine_configs(config, args):
def search_mirrors(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('https://proxybay.co/list.txt',
req = request.Request(mirror_source,
headers=pirate.data.default_headers)
f = request.urlopen(req, timeout=pirate.data.default_timeout)
except IOError:

View File

@ -122,9 +122,13 @@ class TestPirate(unittest.TestCase):
with patch('urllib.request.urlopen', return_value=response_obj) as urlopen:
with patch('pirate.torrent.remote', return_value=[]) as remote:
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')
with patch('pirate.torrent.remote', side_effect=[socket.timeout, []]) as remote:
results, mirror = pirate.pirate.search_mirrors(pages, category, sort, action, search)
self.assertEqual(results, [])
self.assertEqual(mirror, 'https://example.com')
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://example.com')