mirror of
https://github.com/moparisthebest/SickRage
synced 2024-12-12 02:52:20 -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 re
|
||||
import json
|
||||
import os
|
||||
from . import ServiceBase
|
||||
from ..exceptions import DownloadFailedError, ServiceError
|
||||
from ..exceptions import ServiceError
|
||||
from ..language import language_set
|
||||
from ..subtitles import get_subtitle_path, ResultSubtitle
|
||||
from ..videos import Episode, Movie
|
||||
@ -82,34 +81,20 @@ class Subscenter(ServiceBase):
|
||||
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 in languages:
|
||||
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'))
|
||||
'/?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):
|
||||
logger.info(u'Downloading %s in %s' % (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')
|
||||
self.download_zip_file(subtitle.link, subtitle.path)
|
||||
return subtitle
|
||||
|
||||
|
||||
|
@ -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 New Issue
Block a user