Commit 5f10316a authored by echel0n's avatar echel0n
Browse files

fixed sr.setdefaults legacy API v1 endpoint

added is_loading_episodes property to show objects to return True or False when show episode data is being populated
legacy API v1 show.seasons and show.seasonlist wait for episode data to finish loading by using show object is_loading_episodes property
parent 5b4adeb1
......@@ -352,7 +352,7 @@ class ShowTaskAdd(ShowTask):
show_obj.paused = self.paused if self.paused is not None else False
# set up default new/missing episode status
sickrage.app.log.info("Setting all current episodes to the specified default status: " + str(self.default_status))
sickrage.app.log.info("Setting all current episodes to the specified default status: " + str(self.default_status.display_name))
show_obj.default_ep_status = self.default_status
# save to database
......
......@@ -62,6 +62,7 @@ class TVShow(object):
def __init__(self, series_id, series_provider_id, lang='eng', location=''):
self.lock = threading.Lock()
self._episodes = {}
self.loading_episodes = False
with sickrage.app.main_db.session() as session:
try:
......@@ -644,6 +645,10 @@ class TVShow(object):
def is_removing(self):
return self.show_queue_status.get('action') == 'REMOVE'
@property
def is_loading_episodes(self):
return self.loading_episodes
def save(self):
with self.lock, sickrage.app.main_db.session() as session:
sickrage.app.log.debug("{0:d}: Saving to database: {1}".format(self.series_id, self.name))
......@@ -701,6 +706,8 @@ class TVShow(object):
def load_episodes_from_series_provider(self, cache=True):
scanned_eps = {}
self.loading_episodes = True
sickrage.app.log.debug(str(self.series_id) + ": Loading all episodes from " + self.series_provider.name + "..")
# flush episodes from cache so we can reload from database
......@@ -709,6 +716,7 @@ class TVShow(object):
series_provider_language = self.lang or sickrage.app.config.general.series_provider_default_language
series_info = self.series_provider.get_series_info(self.series_id, language=series_provider_language, enable_cache=cache)
if not series_info:
self.loading_episodes = False
raise SeriesProviderException
for season in series_info:
......@@ -737,6 +745,8 @@ class TVShow(object):
self.save()
self.loading_episodes = False
return scanned_eps
def get_episode(self, season=None, episode=None, absolute_number=None, location=None, no_create=False):
......@@ -868,6 +878,8 @@ class TVShow(object):
sickrage.app.log.debug(str(self.series_id) + ": Show dir doesn't exist, not loading episodes from disk")
return
self.loading_episodes = True
sickrage.app.log.debug(str(self.series_id) + ": Loading all episodes from the show directory " + self.location)
# get file list
......@@ -911,6 +923,8 @@ class TVShow(object):
sickrage.app.log.error("%s: Could not refresh subtitles" % self.series_id)
sickrage.app.log.debug(traceback.format_exc())
self.loading_episodes = False
def load_imdb_info(self):
imdb_info_mapper = {
'imdbvotes': 'votes',
......
......@@ -1628,10 +1628,11 @@ class CMD_SiCKRAGESetDefaults(ApiV1Handler):
super(CMD_SiCKRAGESetDefaults, self).__init__(application, request, *args, **kwargs)
self.initial, args = self.check_params("initial", None, False, "list", any_quality_list, *args, **kwargs)
self.archive, args = self.check_params("archive", None, False, "list", best_quality_list, *args, **kwargs)
self.future_show_paused, args = self.check_params("future_show_paused", None, False, "bool", [], *args,
**kwargs)
self.future_show_paused, args = self.check_params("future_show_paused", None, False, "bool", [], *args, **kwargs)
self.flatten_folders, args = self.check_params("flatten_folders", None, False, "bool", [], *args, **kwargs)
self.status, args = self.check_params("status", None, False, "string", ["wanted", "skipped", "ignored"], *args, **kwargs)
self.status, args = self.check_params("status", None, False, "string",
[EpisodeStatus.WANTED.name.lower(), EpisodeStatus.SKIPPED.name.lower(), EpisodeStatus.ARCHIVED.name.lower(),
EpisodeStatus.IGNORED.name.lower()], *args, **kwargs)
def run(self):
""" Set SiCKRAGE's user default configuration value """
......@@ -1650,8 +1651,11 @@ class CMD_SiCKRAGESetDefaults(ApiV1Handler):
sickrage.app.config.general.quality_default = Quality.combine_qualities(iqualityID, aqualityID)
if self.status:
# convert string status to EpisodeStatus
self.status = EpisodeStatus[self.status.upper()]
# only allow the status options we want
if EpisodeStatus[self.status.upper()] not in (EpisodeStatus.WANTED, EpisodeStatus.SKIPPED, EpisodeStatus.ARCHIVED, EpisodeStatus.IGNORED):
if self.status not in (EpisodeStatus.WANTED, EpisodeStatus.SKIPPED, EpisodeStatus.ARCHIVED, EpisodeStatus.IGNORED):
raise InternalApiError("Status Prohibited")
sickrage.app.config.general.status_default = self.status
......@@ -1949,17 +1953,6 @@ class CMD_ShowAddNew(ApiV1Handler):
if not os.path.isdir(self.location):
return _responds(RESULT_FAILURE, msg="'" + self.location + "' is not a valid location")
# convert string status to EpisodeStatus
if self.status:
self.status = EpisodeStatus[self.status.upper()]
# convert string future status to EpisodeStatus
if self.future_status:
self.future_status = EpisodeStatus[self.future_status.upper()]
# convert string search format to SearchFormat
self.search_format = SearchFormat[self.search_format.upper()]
# use default quality as a failsafe
new_quality = int(sickrage.app.config.general.quality_default)
iquality_id = []
......@@ -1978,6 +1971,9 @@ class CMD_ShowAddNew(ApiV1Handler):
# use default status as a failsafe
new_status = sickrage.app.config.general.status_default
if self.status:
# convert string status to EpisodeStatus
self.status = EpisodeStatus[self.status.upper()]
# only allow the status options we want
if self.status not in (EpisodeStatus.WANTED, EpisodeStatus.SKIPPED, EpisodeStatus.IGNORED):
return _responds(RESULT_FAILURE, msg="Status prohibited")
......@@ -1987,9 +1983,13 @@ class CMD_ShowAddNew(ApiV1Handler):
# use default status as a failsafe
default_ep_status_after = sickrage.app.config.general.status_default_after
if self.future_status:
# convert string future status to EpisodeStatus
self.future_status = EpisodeStatus[self.future_status.upper()]
# only allow the status options we want
if self.future_status not in (EpisodeStatus.WANTED, EpisodeStatus.SKIPPED, EpisodeStatus.IGNORED):
return _responds(RESULT_FAILURE, msg="Status prohibited")
default_ep_status_after = self.future_status
series_provider_result = CMD_SiCKRAGESearchSeriesProvider(self.application, self.request, **{
......@@ -2039,7 +2039,7 @@ class CMD_ShowAddNew(ApiV1Handler):
subtitles=self.subtitles,
anime=self.anime,
scene=self.scene,
search_format=self.search_format,
search_format=SearchFormat[self.search_format.upper()],
default_status_after=default_ep_status_after,
skip_downloaded=self.skip_downloaded
)
......@@ -2362,6 +2362,9 @@ class CMD_ShowSeasonList(ApiV1Handler):
if not show_obj:
return _responds(RESULT_FAILURE, msg="Show not found")
while show_obj.is_loading_episodes:
time.sleep(1)
season_list = set()
for episode_object in show_obj.episodes:
season_list.add(episode_object.season)
......@@ -2401,6 +2404,9 @@ class CMD_ShowSeasons(ApiV1Handler):
if not show_obj:
return _responds(RESULT_FAILURE, msg="Show not found")
while show_obj.is_loading_episodes:
time.sleep(1)
if self.season is None:
db_data = session.query(MainDB.TVEpisode).filter_by(series_id=self.series_id, series_provider_id=show_obj.series_provider_id)
else:
......
......@@ -24,9 +24,4 @@ from sickrage.core.webserver.handlers.api.v2 import ApiV2BaseHandler
class ApiV2EpisodeStatusesHandler(ApiV2BaseHandler):
def get(self):
statuses = [{
'name': x.display_name,
'slug': x.name,
} for x in EpisodeStatus]
return self.json_response(statuses)
return self.json_response([{'name': x.display_name, 'slug': x.name} for x in EpisodeStatus])
......@@ -631,9 +631,4 @@ class ApiV2SeriesEpisodesManualSearchHandler(ApiV2BaseHandler):
class ApiV2SeriesSearchFormatsHandler(ApiV2BaseHandler):
def get(self):
search_formats = [{
'name': x.display_name,
'slug': x.name,
} for x in SearchFormat]
return self.json_response(search_formats)
return self.json_response([{'name': x.display_name, 'slug': x.name} for x in SearchFormat])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment