From 53644b5904100410e991fcf61c1122e53108e078 Mon Sep 17 00:00:00 2001 From: slmosl Date: Wed, 7 Sep 2016 14:53:15 +0300 Subject: [PATCH] fixed a breaking change from torec.net -> http://www.xn--9dbf0cd.net leading to addon download malfunction --- addon.xml | 2 +- changelog.txt | 3 +++ resources/lib/TorecSubtitlesDownloader.py | 18 +++++++++++++----- tests/basic_test.py | 4 ++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/addon.xml b/addon.xml index 5c9688a..eb6280e 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/changelog.txt b/changelog.txt index 5111363..a3ae2e8 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +1.0.10 +- fixed a breaking change from torec.net -> http://www.xn--9dbf0cd.net leading to addon download malfunction + 1.0.9 - fixed disfunctional addon (@myakove) diff --git a/resources/lib/TorecSubtitlesDownloader.py b/resources/lib/TorecSubtitlesDownloader.py index c64194c..5edc0fc 100644 --- a/resources/lib/TorecSubtitlesDownloader.py +++ b/resources/lib/TorecSubtitlesDownloader.py @@ -7,6 +7,7 @@ import zlib import bs4 + import xbmc import xbmcaddon @@ -113,7 +114,7 @@ def login(self): class TorecSubtitlesDownloader(FirefoxURLHandler): DEFAULT_SEPERATOR = " " - BASE_URL = "http://www.torec.net" + BASE_URL = "http://www.xn--9dbf0cd.net" SUBTITLE_PATH = "sub.asp?sub_id=" USER_AUTH_JS_URL = "http://www.torec.net/gjs/subw.js" DEFAULT_COOKIE = ( @@ -127,7 +128,7 @@ def __init__(self): def _build_default_cookie(self, sub_id): current_time = datetime.datetime.now().strftime("%m/%d/%Y+%I:%M:%S+%p") return self.DEFAULT_COOKIE % { - "screen_width": 1760, + "screen_width": 1440, "subId": sub_id, "current_datetime": current_time } @@ -139,12 +140,15 @@ def _get_time_waited(self, subw_text): return re.search(r"seconds\s+=\s+(\d+);", subw_text).group(1) def _request_subtitle(self, sub_id): - params = { + params = { "sub_id" : sub_id, "s" : 1440 - } + } - return self.opener.open("%s/ajax/sub/guest_time.asp" % self.BASE_URL, urllib.urlencode(params)).read() + response = self.opener.open("%s/ajax/sub/guest_time.asp" % self.BASE_URL, urllib.urlencode(params)) + data = response.read() + + return data def search(self, movie_name): santized_name = self.sanitize(movie_name) @@ -194,6 +198,10 @@ def get_download_link(self, sub_id, option_id): return response.read() def download(self, download_link): + if not download_link: + log(__name__, "no download link found") + return None, None + response = self.opener.open( "%s%s" % (self.BASE_URL, download_link) ) diff --git a/tests/basic_test.py b/tests/basic_test.py index 2216892..267aa12 100644 --- a/tests/basic_test.py +++ b/tests/basic_test.py @@ -32,6 +32,10 @@ def convert_to_utf(file): result = downloader.get_download_link(page_id, subtitle_id) subtitleData, fileName = downloader.download(result) +if subtitleData is None: + print "Test FAILED" + sys.exit(1) + extension = os.path.splitext(fileName)[1] temp = tempfile.NamedTemporaryFile()