diff --git a/medusa/init/__init__.py b/medusa/init/__init__.py index 974369bbe4..ca75938640 100644 --- a/medusa/init/__init__.py +++ b/medusa/init/__init__.py @@ -140,7 +140,7 @@ def _configure_subliminal(): 'itasa = {basename}.subtitle_providers.itasa:ItaSAProvider'.format(basename=basename), 'legendastv = {basename}.subtitle_providers.legendastv:LegendasTVProvider'.format(basename=basename), 'subscenter = {basename}.subtitle_providers.subscenter:SubsCenterProvider'.format(basename=basename), - 'thewiz = {basename}.subtitle_providers.thewiz:TheWizProvider'.format(basename=basename)): + 'wizdom = {basename}.subtitle_providers.wizdom:WizdomProvider'.format(basename=basename)): provider_manager.register(name) refiner_manager.register('release = {basename}.refiners.release:refine'.format(basename=basename)) diff --git a/medusa/subtitle_providers/thewiz.py b/medusa/subtitle_providers/wizdom.py similarity index 75% rename from medusa/subtitle_providers/thewiz.py rename to medusa/subtitle_providers/wizdom.py index ff63a50d2d..f35925307e 100644 --- a/medusa/subtitle_providers/thewiz.py +++ b/medusa/subtitle_providers/wizdom.py @@ -19,13 +19,13 @@ logger = logging.getLogger(__name__) -class TheWizSubtitle(Subtitle): - """TheWiz Subtitle.""" - provider_name = 'thewiz' +class WizdomSubtitle(Subtitle): + """Wizdom Subtitle.""" + provider_name = 'wizdom' def __init__(self, language, hearing_impaired, page_link, series, season, episode, title, imdb_id, subtitle_id, releases): - super(TheWizSubtitle, self).__init__(language, hearing_impaired, page_link) + super(WizdomSubtitle, self).__init__(language, hearing_impaired, page_link) self.series = series self.season = season self.episode = episode @@ -72,10 +72,10 @@ def get_matches(self, video): return matches -class TheWizProvider(Provider): - """TheWiz Provider.""" +class WizdomProvider(Provider): + """Wizdom Provider.""" languages = {Language.fromalpha2(l) for l in ['he']} - server_url = 'http://subs.thewiz.info/' + server_url = 'wizdom.xyz' _tmdb_api_key = 'f7f51775877e0bb6703520952b3c7840' @@ -94,49 +94,41 @@ def _search_imdb_id(self, title, year, is_movie): :param str title: title to search for. :param int year: year to search for (or 0 if not relevant). - :param bool is_movie: If True, IMDB ID will be searched for in TMDB instead of TheWiz. + :param bool is_movie: If True, IMDB ID will be searched for in TMDB instead of Wizdom. :return: the IMDB ID for the given title and year (or None if not found). :rtype: str """ # make the search logger.info('Searching IMDB ID for %r%r', title, '' if not year else ' ({})'.format(year)) + category = 'movie' if is_movie else 'tv' title = title.replace('\'', '') - if is_movie: - # get TMDB ID first - r = self.session.get('http://api.tmdb.org/3/search/movie?api_key={}&query={}{}&language=en'.format( - self._tmdb_api_key, title, '' if not year else '&year={}'.format(year))) - r.raise_for_status() - tmdb_results = r.json().get('results') - if tmdb_results: - tmdb_id = tmdb_results[0].get('id') - if tmdb_id: - # get actual IMDB ID from TMDB - r = self.session.get('http://api.tmdb.org/3/movie/{}?api_key={}&language=en'.format( - tmdb_id, self._tmdb_api_key)) - r.raise_for_status() - return str(r.json().get('imdb_id', '')) or None - return None - - # handle TV series - r = self.session.get(self.server_url + 'search.tv.php', params={'name': title}, timeout=10) + # get TMDB ID first + r = self.session.get('http://api.tmdb.org/3/search/{}?api_key={}&query={}{}&language=en'.format( + category, self._tmdb_api_key, title, '' if not year else '&year={}'.format(year))) r.raise_for_status() - return r.text or None + tmdb_results = r.json().get('results') + if tmdb_results: + tmdb_id = tmdb_results[0].get('id') + if tmdb_id: + # get actual IMDB ID from TMDB + r = self.session.get('http://api.tmdb.org/3/{}/{}{}?api_key={}&language=en'.format( + category, tmdb_id, '' if is_movie else '/external_ids', self._tmdb_api_key)) + r.raise_for_status() + return str(r.json().get('imdb_id', '')) or None + return None def query(self, title, season=None, episode=None, year=None, filename=None, imdb_id=None): # search for the IMDB ID if needed. is_movie = not (season and episode) imdb_id = imdb_id or self._search_imdb_id(title, year, is_movie) - # get search parameters - season = season or 0 - episode = episode or 0 - version = os.path.splitext(os.path.basename(filename))[0] if filename else 0 + if not imdb_id: + return {} # search logger.debug('Using IMDB ID %r', imdb_id) - url = 'http://subs.thewiz.info/search.id.php?imdb={}&season={}&episode={}&version={}'.format( - imdb_id, season, episode, version) - page_link = self.server_url + '#/{}/{}'.format('movies' if is_movie else 'series', imdb_id) + url = 'http://json.{}/{}.json'.format(self.server_url, imdb_id) + page_link = 'http://{}/#/{}/{}'.format(self.server_url, 'movies' if is_movie else 'series', imdb_id) # get the list of subtitles logger.debug('Getting the list of subtitles') @@ -147,13 +139,19 @@ def query(self, title, season=None, episode=None, year=None, filename=None, imdb except ValueError: return {} + # filter irrelevant results + if not is_movie: + results = results.get('subs', {}).get(str(season), {}).get(str(episode), []) + else: + results = results.get('subs', []) + # loop over results subtitles = {} for result in results: language = Language.fromalpha2('he') hearing_impaired = False subtitle_id = result['id'] - release = result['versioname'] + release = result['version'] # add the release and increment downloaded count if we already have the subtitle if subtitle_id in subtitles: @@ -163,7 +161,7 @@ def query(self, title, season=None, episode=None, year=None, filename=None, imdb continue # otherwise create it - subtitle = TheWizSubtitle(language, hearing_impaired, page_link, title, season, episode, title, imdb_id, + subtitle = WizdomSubtitle(language, hearing_impaired, page_link, title, season, episode, title, imdb_id, subtitle_id, [release]) logger.debug('Found subtitle %r', subtitle) subtitles[subtitle_id] = subtitle @@ -187,7 +185,7 @@ def list_subtitles(self, video, languages): def download_subtitle(self, subtitle): # download - url = self.server_url + 'zip/{}.zip'.format(subtitle.subtitle_id) + url = 'http://zip.{}/{}.zip'.format(self.server_url, subtitle.subtitle_id) r = self.session.get(url, headers={'Referer': subtitle.page_link}, timeout=10) r.raise_for_status() diff --git a/medusa/subtitles.py b/medusa/subtitles.py index 32e1b345d9..ff7bf84a95 100644 --- a/medusa/subtitles.py +++ b/medusa/subtitles.py @@ -64,7 +64,8 @@ 'shooter': 'http://www.shooter.cn', 'subscenter': 'http://www.subscenter.org', 'thesubdb': 'http://www.thesubdb.com', - 'tvsubtitles': 'http://www.tvsubtitles.net' + 'tvsubtitles': 'http://www.tvsubtitles.net', + 'wizdom': 'http://wizdom.xyz' } diff --git a/pytest.ini b/pytest.ini index 76bf6157ec..0271c7b7f4 100644 --- a/pytest.ini +++ b/pytest.ini @@ -147,7 +147,7 @@ flake8-ignore = medusa/subtitle_providers/__init__.py D104 medusa/subtitle_providers/legendastv.py I100 D100 D102 D105 D204 medusa/subtitle_providers/itasa.py D102 I100 D100 D101 D105 D400 E123 E126 - medusa/subtitle_providers/thewiz.py D100 D102 D204 + medusa/subtitle_providers/wizdom.py D100 D102 D204 medusa/subtitle_providers/subscenter.py I100 D100 D102 D204 medusa/system/__init__.py D104 medusa/system/restart.py D100 D101 D102 diff --git a/static/images/subtitles/thewiz.png b/static/images/subtitles/thewiz.png deleted file mode 100644 index c0917fd877..0000000000 Binary files a/static/images/subtitles/thewiz.png and /dev/null differ diff --git a/static/images/subtitles/wizdom.png b/static/images/subtitles/wizdom.png new file mode 100644 index 0000000000..faf51e5fef Binary files /dev/null and b/static/images/subtitles/wizdom.png differ diff --git a/tests/test_subtitles.py b/tests/test_subtitles.py index 18af7ed054..b35cf16b4d 100644 --- a/tests/test_subtitles.py +++ b/tests/test_subtitles.py @@ -33,8 +33,8 @@ def test_sorted_service_list(monkeypatch): {'name': 'opensubtitles', 'enabled': False}, {'name': 'podnapisi', 'enabled': False}, {'name': 'subscenter', 'enabled': False}, - {'name': 'thewiz', 'enabled': False}, {'name': 'tvsubtitles', 'enabled': False}, + {'name': 'wizdom', 'enabled': False}, ] assert expected == [{'name': a['name'], 'enabled': a['enabled']} for a in actual]