Skip to content

Commit

Permalink
Rename subtitle provider from TheWiz > Wizdom (#2923)
Browse files Browse the repository at this point in the history
* Rename subtitle provider from TheWiz > Wizdom
* Also change URL
* Fix test
* Update subtitles.py
  • Loading branch information
fernandog authored and p0psicles committed Jul 4, 2017
1 parent 3b125c4 commit b02bc07
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 41 deletions.
2 changes: 1 addition & 1 deletion medusa/init/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'

Expand All @@ -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')
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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()

Expand Down
3 changes: 2 additions & 1 deletion medusa/subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}


Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file removed static/images/subtitles/thewiz.png
Binary file not shown.
Binary file added static/images/subtitles/wizdom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/test_subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit b02bc07

Please sign in to comment.