diff --git a/gui/slick/images/subtitles/subscenter.png b/gui/slick/images/subtitles/subscenter.png new file mode 100644 index 00000000..84389c57 Binary files /dev/null and b/gui/slick/images/subtitles/subscenter.png differ diff --git a/lib/subliminal/core.py b/lib/subliminal/core.py index 9c3fa3dc..0ecbf3f6 100644 --- a/lib/subliminal/core.py +++ b/lib/subliminal/core.py @@ -32,7 +32,8 @@ __all__ = ['SERVICES', 'LANGUAGE_INDEX', 'SERVICE_INDEX', 'SERVICE_CONFIDENCE', 'create_list_tasks', 'create_download_tasks', 'consume_task', 'matching_confidence', 'key_subtitles', 'group_by_video'] logger = logging.getLogger("subliminal") -SERVICES = ['opensubtitles', 'subswiki', 'subtitulos', 'thesubdb', 'addic7ed', 'tvsubtitles', 'itasa', 'usub'] +SERVICES = ['opensubtitles', 'subswiki', 'subtitulos', 'thesubdb', 'addic7ed', 'tvsubtitles', 'itasa', + 'usub', 'subscenter'] LANGUAGE_INDEX, SERVICE_INDEX, SERVICE_CONFIDENCE, MATCHING_CONFIDENCE = range(4) diff --git a/lib/subliminal/services/subscenter.py b/lib/subliminal/services/subscenter.py new file mode 100644 index 00000000..3646c50b --- /dev/null +++ b/lib/subliminal/services/subscenter.py @@ -0,0 +1,101 @@ +# -*- coding: utf-8 -*- +# Copyright 2012 Ofir Brukner +# +# This file is part of subliminal. +# +# subliminal is free software; you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# subliminal is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with subliminal. If not, see . +import logging +import re +import json +from . import ServiceBase +from ..exceptions import ServiceError +from ..language import language_set +from ..subtitles import get_subtitle_path, ResultSubtitle +from ..videos import Episode, Movie +from ..utils import to_unicode, get_keywords + + +logger = logging.getLogger("subliminal") + + +class Subscenter(ServiceBase): + server_url = 'http://subscenter.cinemast.com/he/' + site_url = 'http://subscenter.cinemast.com/' + api_based = False + languages = language_set(['he', 'en']) + videos = [Episode, Movie] + require_video = False + required_features = ['permissive'] + + @staticmethod + def slugify(string): + new_string = string.replace(' ', '-').replace("'", '').replace(':', '').lower() + # We remove multiple spaces by using this regular expression. + return re.sub('-+', '-', new_string) + + def list_checked(self, video, languages): + series = None + season = None + episode = None + title = video.title + if isinstance(video, Episode): + series = video.series + season = video.season + episode = video.episode + return self.query(video.path or video.release, languages, get_keywords(video.guess), series, season, + episode, title) + + def query(self, filepath, languages=None, keywords=None, series=None, season=None, episode=None, title=None): + logger.debug(u'Getting subtitles for %s season %d episode %d with languages %r' % (series, season, episode, languages)) + # Converts the title to Subscenter format by replacing whitespaces and removing specific chars. + if series and season and episode: + # Search for a TV show. + kind = 'episode' + slugified_series = self.slugify(series) + url = self.server_url + 'cinemast/data/series/sb/' + slugified_series + '/' + str(season) + '/' + \ + str(episode) + '/' + elif title: + # Search for a movie. + kind = 'movie' + slugified_title = self.slugify(title) + url = self.server_url + 'cinemast/data/movie/sb/' + slugified_title + '/' + else: + raise ServiceError('One or more parameters are missing') + logger.debug('Searching subtitles %r', {'title': title, 'season': season, 'episode': episode}) + response = self.session.get(url) + if response.status_code != 200: + raise ServiceError('Request failed with status code %d' % response.status_code) + + subtitles = [] + response_json = json.loads(response.content) + for lang, lang_json in response_json.items(): + lang_obj = self.get_language(lang) + if lang_obj in self.languages and lang_obj in languages: + for group_data in lang_json.values(): + for quality in group_data.values(): + for sub in quality.values(): + release = sub.get('subtitle_version') + sub_path = get_subtitle_path(filepath, lang_obj, self.config.multi) + link = self.server_url + 'subtitle/download/' + lang + '/' + str(sub.get('id')) + \ + '/?v=' + release + '&key=' + str(sub.get('key')) + subtitles.append(ResultSubtitle(sub_path, lang_obj, self.__class__.__name__.lower(), + link, release=to_unicode(release))) + return subtitles + + def download(self, subtitle): + self.download_zip_file(subtitle.link, subtitle.path) + return subtitle + + +Service = Subscenter \ No newline at end of file diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index c8f2f951..46e88f5e 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -4451,30 +4451,28 @@ class Home(MainHandler): return quality_class def searchEpisodeSubtitles(self, show=None, season=None, episode=None): - # retrieve the episode object and fail if we can't get one ep_obj = _getEpisode(show, season, episode) if isinstance(ep_obj, str): return json.dumps({'result': 'failure'}) # try do download subtitles for that episode - previous_subtitles = ep_obj.subtitles + previous_subtitles = set(subliminal.language.Language(x) for x in ep_obj.subtitles) try: - ep_obj.subtitles = ep_obj.downloadSubtitles() + ep_obj.subtitles = set(x.language for x in ep_obj.downloadSubtitles().values()[0]) except: return json.dumps({'result': 'failure'}) # return the correct json value if previous_subtitles != ep_obj.subtitles: status = 'New subtitles downloaded: %s' % ' '.join([ - "" + subliminal.language.Language(x).name + "" for x in - sorted(list(set(ep_obj.subtitles).difference(previous_subtitles)))]) + "" + x.name + "" for x in + sorted(list(ep_obj.subtitles.difference(previous_subtitles)))]) else: status = 'No subtitles downloaded' ui.notifications.message('Subtitles Search', status) - return json.dumps({'result': status, 'subtitles': ','.join([x for x in ep_obj.subtitles])}) - + return json.dumps({'result': status, 'subtitles': ','.join([x.alpha2 for x in ep_obj.subtitles])}) def setSceneNumbering(self, show, indexer, forSeason=None, forEpisode=None, forAbsolute=None, sceneSeason=None, sceneEpisode=None, sceneAbsolute=None):