mirror of
https://github.com/moparisthebest/SickRage
synced 2024-12-12 11:02:21 -05:00
Fixed a few bugs.
Also fixed buggy search function in webserve.
This commit is contained in:
parent
14f3848872
commit
b0426ca12d
@ -18,9 +18,8 @@
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
from . import ServiceBase
|
from . import ServiceBase
|
||||||
from ..exceptions import DownloadFailedError, ServiceError
|
from ..exceptions import ServiceError
|
||||||
from ..language import language_set
|
from ..language import language_set
|
||||||
from ..subtitles import get_subtitle_path, ResultSubtitle
|
from ..subtitles import get_subtitle_path, ResultSubtitle
|
||||||
from ..videos import Episode, Movie
|
from ..videos import Episode, Movie
|
||||||
@ -82,34 +81,20 @@ class Subscenter(ServiceBase):
|
|||||||
response_json = json.loads(response.content)
|
response_json = json.loads(response.content)
|
||||||
for lang, lang_json in response_json.items():
|
for lang, lang_json in response_json.items():
|
||||||
lang_obj = self.get_language(lang)
|
lang_obj = self.get_language(lang)
|
||||||
if lang_obj in self.languages and lang in languages:
|
if lang_obj in self.languages and lang_obj in languages:
|
||||||
for group_data in lang_json.values():
|
for group_data in lang_json.values():
|
||||||
for quality in group_data.values():
|
for quality in group_data.values():
|
||||||
for sub in quality.values():
|
for sub in quality.values():
|
||||||
release = sub.get('subtitle_version')
|
release = sub.get('subtitle_version')
|
||||||
sub_path = get_subtitle_path(filepath, lang_obj, self.config.multi)
|
sub_path = get_subtitle_path(filepath, lang_obj, self.config.multi)
|
||||||
link = self.server_url + 'subtitle/download/' + lang + '/' + str(sub.get('id')) + \
|
link = self.server_url + 'subtitle/download/' + lang + '/' + str(sub.get('id')) + \
|
||||||
'/?v=' + release + '&key=' + str(sub.get('key'))
|
'/?v=' + release + '&key=' + str(sub.get('key'))
|
||||||
subtitles.append(ResultSubtitle(sub_path, lang_obj, self.__class__.__name__.lower(),
|
subtitles.append(ResultSubtitle(sub_path, lang_obj, self.__class__.__name__.lower(),
|
||||||
link, release=to_unicode(release)))
|
link, release=to_unicode(release)))
|
||||||
return subtitles
|
return subtitles
|
||||||
|
|
||||||
def download(self, subtitle):
|
def download(self, subtitle):
|
||||||
logger.info(u'Downloading %s in %s' % (subtitle.link, subtitle.path))
|
self.download_zip_file(subtitle.link, subtitle.path)
|
||||||
try:
|
|
||||||
r = self.session.get(subtitle.link, headers={'Referer': subtitle.link, 'User-Agent': self.user_agent})
|
|
||||||
if r.status_code != 200:
|
|
||||||
raise DownloadFailedError('Request failed with status code %d' % r.status_code)
|
|
||||||
if r.headers['Content-Type'] == 'text/html':
|
|
||||||
raise DownloadFailedError('Download limit exceeded')
|
|
||||||
with open(subtitle.path, 'wb') as f:
|
|
||||||
f.write(r.content)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(u'Download failed: %s' % e)
|
|
||||||
if os.path.exists(subtitle.path):
|
|
||||||
os.remove(subtitle.path)
|
|
||||||
raise DownloadFailedError(str(e))
|
|
||||||
logger.debug(u'Download finished')
|
|
||||||
return subtitle
|
return subtitle
|
||||||
|
|
||||||
|
|
||||||
|
@ -4451,30 +4451,28 @@ class Home(MainHandler):
|
|||||||
return quality_class
|
return quality_class
|
||||||
|
|
||||||
def searchEpisodeSubtitles(self, show=None, season=None, episode=None):
|
def searchEpisodeSubtitles(self, show=None, season=None, episode=None):
|
||||||
|
|
||||||
# retrieve the episode object and fail if we can't get one
|
# retrieve the episode object and fail if we can't get one
|
||||||
ep_obj = _getEpisode(show, season, episode)
|
ep_obj = _getEpisode(show, season, episode)
|
||||||
if isinstance(ep_obj, str):
|
if isinstance(ep_obj, str):
|
||||||
return json.dumps({'result': 'failure'})
|
return json.dumps({'result': 'failure'})
|
||||||
|
|
||||||
# try do download subtitles for that episode
|
# 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:
|
try:
|
||||||
ep_obj.subtitles = ep_obj.downloadSubtitles()
|
ep_obj.subtitles = set(x.language for x in ep_obj.downloadSubtitles().values()[0])
|
||||||
except:
|
except:
|
||||||
return json.dumps({'result': 'failure'})
|
return json.dumps({'result': 'failure'})
|
||||||
|
|
||||||
# return the correct json value
|
# return the correct json value
|
||||||
if previous_subtitles != ep_obj.subtitles:
|
if previous_subtitles != ep_obj.subtitles:
|
||||||
status = 'New subtitles downloaded: %s' % ' '.join([
|
status = 'New subtitles downloaded: %s' % ' '.join([
|
||||||
"<img src='" + sickbeard.WEB_ROOT + "/images/flags/" + subliminal.language.Language(
|
"<img src='" + sickbeard.WEB_ROOT + "/images/flags/" + x.alpha2 +
|
||||||
x).alpha2 + ".png' alt='" + subliminal.language.Language(x).name + "'/>" for x in
|
".png' alt='" + x.name + "'/>" for x in
|
||||||
sorted(list(set(ep_obj.subtitles).difference(previous_subtitles)))])
|
sorted(list(ep_obj.subtitles.difference(previous_subtitles)))])
|
||||||
else:
|
else:
|
||||||
status = 'No subtitles downloaded'
|
status = 'No subtitles downloaded'
|
||||||
ui.notifications.message('Subtitles Search', status)
|
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,
|
def setSceneNumbering(self, show, indexer, forSeason=None, forEpisode=None, forAbsolute=None, sceneSeason=None,
|
||||||
sceneEpisode=None, sceneAbsolute=None):
|
sceneEpisode=None, sceneAbsolute=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user