Commit 1b9ce09f authored by echel0n's avatar echel0n

Refactored add_episodes_to_trakt_watch_list method

Refactored APIBulderHandler get method
Refactored API call CMD_ShowSeasonList
Refactored API call CMD_ShowStats
Fixed issues with API Builder and async calls
Fixed JS issue with schedule view episode details toggle
Bumped jQuery to v3.5.1
Fixed issue with API call for grabbing detailed episode information
parent ee66914f
......@@ -25,7 +25,6 @@ import traceback
import sickrage
from sickrage.core.common import Quality
from sickrage.core.common import SKIPPED, WANTED, UNKNOWN
from sickrage.core.databases.main import MainDB
from sickrage.core.exceptions import EpisodeNotFoundException
from sickrage.core.helpers import sanitize_file_name, make_dir, chmod_as_parent
from sickrage.core.queues.search import BacklogSearchTask
......@@ -99,7 +98,7 @@ class TraktSearcher(object):
def sync_watchlist(self):
sickrage.app.log.debug("Syncing SiCKRAGE with Trakt Watchlist")
self.remove_show_from_sick_rage()
self.remove_show_from_sickrage()
if self._get_show_watchlist():
self.add_show_to_trakt_watch_list()
......@@ -258,19 +257,20 @@ class TraktSearcher(object):
"WATCHLIST::REMOVE::FINISH - Look for Episodes to Remove from Trakt Watchlist")
def add_episodes_to_trakt_watch_list(self):
session = sickrage.app.main_db.session()
trakt_data = []
sickrage.app.log.debug("WATCHLIST::ADD::START - Look for Episodes to Add to Trakt Watchlist")
for s in get_show_list():
for e in session.query(MainDB.TVEpisode).filter_by(showid=s.indexer_id).filter(
~MainDB.TVEpisode.episode.in_(Quality.SNATCHED + Quality.SNATCHED_PROPER + [UNKNOWN] + [WANTED])):
trakt_id = IndexerApi(s.indexer).trakt_id
if self._check_in_list(trakt_id, str(e.showid), e.season, e.episode):
sickrage.app.log.debug("Adding Episode %s S%02dE%02d to watchlist" % (s.name, e.season, e.episode))
trakt_data.append((e.showid, s.indexer, s.name, s.startyear, e.season, e.episode))
for show_object in get_show_list():
for episode_object in show_object.episodes:
if episode_object.status in Quality.SNATCHED + Quality.SNATCHED_PROPER + [UNKNOWN, WANTED]:
continue
trakt_id = IndexerApi(show_object.indexer).trakt_id
if self._check_in_list(trakt_id, str(show_object.indexer_id), episode_object.season, episode_object.episode):
sickrage.app.log.debug("Adding Episode %s S%02dE%02d to watchlist" % (show_object.name, episode_object.season, episode_object.episode))
trakt_data.append(
(show_object.indexer_id, show_object.indexer, show_object.name, show_object.startyear, episode_object.season, episode_object.episode))
if len(trakt_data):
try:
......@@ -309,7 +309,7 @@ class TraktSearcher(object):
sickrage.app.log.debug("SHOW_WATCHLIST::ADD::FINISH - Look for Shows to Add to Trakt Watchlist")
def remove_show_from_sick_rage(self):
def remove_show_from_sickrage(self):
sickrage.app.log.debug("SHOW_SICKRAGE::REMOVE::START - Look for Shows to remove from SiCKRAGE")
for show in get_show_list():
......
This diff is collapsed.
......@@ -18,7 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with SiCKRAGE. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
import base64
import datetime
import json
import os
......@@ -76,17 +76,17 @@ class APIBulderHandler(BaseHandler, ABC):
def titler(x):
return (remove_article(x), x)[not x or sickrage.app.config.sort_article]
session = sickrage.app.main_db.session()
episodes = {}
for result in session.query(MainDB.TVEpisode).order_by(MainDB.TVEpisode.season, MainDB.TVEpisode.episode):
if result.showid not in episodes:
episodes[result.showid] = {}
if result.season not in episodes[result.showid]:
episodes[result.showid][result.season] = []
for show_object in get_show_list():
if show_object.indexer_id not in episodes:
episodes[show_object.indexer_id] = {}
for episode_object in show_object.episodes:
if episode_object.season not in episodes[show_object.indexer_id]:
episodes[show_object.indexer_id][episode_object.season] = []
episodes[result.showid][result.season].append(result.episode)
episodes[show_object.indexer_id][episode_object.season].append(episode_object.episode)
if len(sickrage.app.config.api_key) == 32:
apikey = sickrage.app.config.api_key
......@@ -101,7 +101,7 @@ class APIBulderHandler(BaseHandler, ABC):
title=_('API Builder'),
header=_('API Builder'),
shows=sorted(get_show_list(), key=cmp_to_key(lambda x, y: titler(x.name) < titler(y.name))),
episodes=episodes,
episodes=base64.b64encode(json.dumps(episodes).encode()).decode(),
apikey=apikey,
api_commands=api_commands,
controller='root',
......
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
......@@ -8,7 +8,7 @@
<%block name="metas">
<meta data-var="commands" data-content="${api_commands}">
<meta data-var="episodes" data-content="${json.dumps(episodes)}">
<meta data-var="episodes" data-content="${episodes}">
</%block>
<%block name="content">
......@@ -88,9 +88,7 @@
<div class="col-md-12">
<h4>${_('Playground')}</h4>
<span>
${_('URL:')} <kbd
id="command-${command_id}-base-url">${request.protocol}
://${request.host}${srWebRoot}/api/${apikey}/?cmd=${command}</kbd>
${_('URL:')} <kbd id="command-${command_id}-base-url">${srWebRoot}/api/${apikey}/?cmd=${command}</kbd>
</span>
</div>
</div>
......
......@@ -1442,8 +1442,8 @@ $(document).ready(function ($) {
$('.ep_summary').hide();
$('.ep_summaryTrigger').click(function () {
$(this).next('.ep_summary').slideToggle('normal', function () {
$.prev('.ep_summaryTrigger').attr('src', function (i, src) {
return $(this).next('.ep_summary').is(':visible') ? src.replace('plus', 'minus') : src.replace('minus', 'plus');
$(this).prev('.ep_summaryTrigger').attr('class', function (i, className) {
return $(this).next('.ep_summary').is(':visible') ? className.replace('fa-plus-square', 'fa-minus-square') : className.replace('fa-minus-square', 'fa-plus-square');
});
});
});
......@@ -1591,7 +1591,7 @@ $(document).ready(function ($) {
var select = $('[data-command=' + command + '][name=episode]');
var season = $(this).val();
var show = $('[data-command=' + command + '][name=indexerid]').val();
var episodes = $.parseJSON(SICKRAGE.getMeta('episodes'));
var episodes = $.parseJSON(window.atob(SICKRAGE.getMeta('episodes')));
if (select !== undefined) {
select.removeClass('d-none');
......@@ -1613,7 +1613,7 @@ $(document).ready(function ($) {
var command = $(this).data('command');
var select = $('[data-command=' + command + '][name=season]');
var show = $(this).val();
var episodes = $.parseJSON(SICKRAGE.getMeta('episodes'));
var episodes = $.parseJSON(window.atob(SICKRAGE.getMeta('episodes')));
if (select !== undefined) {
select.removeClass('d-none');
......
Markdown is supported
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