mirror of
https://github.com/SickGear/SickGear.git
synced 2025-01-05 17:43:37 +00:00
Merge pull request #867 from ofir123/subscenter_support
Subscenter support
This commit is contained in:
commit
f9bac63135
4 changed files with 109 additions and 9 deletions
BIN
gui/slick/images/subtitles/subscenter.png
Normal file
BIN
gui/slick/images/subtitles/subscenter.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
|
@ -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)
|
||||
|
||||
|
||||
|
|
101
lib/subliminal/services/subscenter.py
Normal file
101
lib/subliminal/services/subscenter.py
Normal file
|
@ -0,0 +1,101 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2012 Ofir Brukner <ofirbrukner@gmail.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
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
|
|
@ -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([
|
||||
"<img src='" + sickbeard.WEB_ROOT + "/images/flags/" + subliminal.language.Language(
|
||||
x).alpha2 + ".png' alt='" + subliminal.language.Language(x).name + "'/>" for x in
|
||||
sorted(list(set(ep_obj.subtitles).difference(previous_subtitles)))])
|
||||
"<img src='" + sickbeard.WEB_ROOT + "/images/flags/" + x.alpha2 +
|
||||
".png' alt='" + 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):
|
||||
|
|
Loading…
Reference in a new issue