From be821176006cc8ffdacefc51e141b61c8fb02061 Mon Sep 17 00:00:00 2001 From: josdion Date: Tue, 25 Aug 2020 19:05:33 +0300 Subject: [PATCH] Fix #1089 - YIFY Subtitles server URL update --- .../providers/yifysubtitles.py | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/libs/subliminal_patch/providers/yifysubtitles.py b/libs/subliminal_patch/providers/yifysubtitles.py index 59d683577..e41dc6c69 100644 --- a/libs/subliminal_patch/providers/yifysubtitles.py +++ b/libs/subliminal_patch/providers/yifysubtitles.py @@ -95,7 +95,7 @@ class YifySubtitlesProvider(Provider): ] languages = {Language(l, c) for (_, l, c) in YifyLanguages} - server_url = 'https://www.yifysubtitles.com' + server_urls = ['https://yifysubtitles.org', 'https://www.yifysubtitles.com'] video_types = (Movie,) def initialize(self): @@ -112,20 +112,20 @@ class YifySubtitlesProvider(Provider): def terminate(self): self.session.close() - def _parse_row(self, row, languages): + def _parse_row(self, row, languages, server_url): td = row.findAll('td') rating = int(td[0].text) sub_lang = td[1].text release = re.sub(r'^subtitle ', '', td[2].text) sub_link = td[2].find('a').get('href') - sub_link = re.sub(r'^/subtitles/', self.server_url + '/subtitle/', sub_link) + '.zip' + page_link = server_url + sub_link + sub_link = re.sub(r'^/subtitles/', server_url + '/subtitle/', sub_link) + '.zip' hi = True if td[3].find('span', {'class': 'hi-subtitle'}) else False uploader = td[4].text - page_link = self.server_url + td[5].find('a').get('href') _, l, c = next(x for x in self.YifyLanguages if x[0] == sub_lang) lang = Language(l, c) - if languages & set([lang]): + if languages & {lang}: return [YifySubtitle(lang, page_link, release, uploader, sub_link, rating, hi)] return [] @@ -134,9 +134,13 @@ class YifySubtitlesProvider(Provider): subtitles = [] logger.info('Searching subtitle %r', imdb_id) - response = self.session.get(self.server_url + '/movie-imdb/' + imdb_id, - allow_redirects=False, timeout=10, - headers={'Referer': self.server_url}) + for server_url in self.server_urls: + response = self.session.get(server_url + '/movie-imdb/' + imdb_id, + allow_redirects=False, timeout=10, + headers={'Referer': server_url}) + if response.status_code == 200: + break + response.raise_for_status() if response.status_code != 200: @@ -150,7 +154,7 @@ class YifySubtitlesProvider(Provider): for row in rows: try: - subtitles = subtitles + self._parse_row(row, languages) + subtitles = subtitles + self._parse_row(row, languages, server_url) except Exception as e: pass