From bd3dd2cace67976b6e64ab45b544bae4cb4579d8 Mon Sep 17 00:00:00 2001 From: Viktor Stanchev Date: Sun, 16 Feb 2014 13:22:10 -0500 Subject: [PATCH] detect blocked mirrors even when error code is 200 closes #8 --- pirate-get.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pirate-get.py b/pirate-get.py index 9ca2da7..9d6dc3f 100755 --- a/pirate-get.py +++ b/pirate-get.py @@ -72,6 +72,13 @@ def main(): res = f.read() found = re.findall(""""(magnet\:\?xt=[^"]*)|([^<]+)""", res) + # check for a blocked mirror + no_results = re.search(""""No hits\.""", res) + if found == [] and not no_results is None: + # Contradiction - we found no results, but the page didn't say there were no results + # the page is probably not actually the pirate bay, so let's try another mirror + raise Exception("Blocked mirror detected.") + # get sizes as well and substitute the   character # print res sizes = [ match.replace(" ", " ") for match in re.findall("(?<=Size )[0-9.]+\ \;[KMGT]*[i ]*B",res) ]