Commit 932c107a authored by echel0n's avatar echel0n
Browse files

Revert "Refactored main shows page to load shows via web sockets."

This reverts commit b9b280d7
parent 940d091a
......@@ -190,12 +190,6 @@
"integrity": "sha1-819bqRNmt6WLC2pPIv8JB/4AIhk=",
"dev": true
},
"@sudhanshu/radial-indicator": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@sudhanshu/radial-indicator/-/radial-indicator-2.0.0.tgz",
"integrity": "sha512-lrk4EpESjezikCumBeqAKunfhn8kV8RSebE+CWSvgewYLOm51ve/hPRkResUQVFAN4ykRaHlr8qLAfUNDGbsvQ==",
"dev": true
},
"@webassemblyjs/ast": {
"version": "1.5.13",
"resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.5.13.tgz",
......@@ -5802,6 +5796,16 @@
"integrity": "sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10=",
"dev": true
},
"infinite-scroll": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/infinite-scroll/-/infinite-scroll-3.0.6.tgz",
"integrity": "sha512-679gpKlS/XuAnA+spIRNFSel1dsZ44ljKVlkWHVNTtibJR0cUIC3jwZaBQUsaR1TvPFnaQijRlS8Q/lPgx1VAA==",
"dev": true,
"requires": {
"ev-emitter": "^1.1.0",
"fizzy-ui-utils": "^2.0.5"
}
},
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
......
......@@ -184,7 +184,7 @@ class VersionUpdater(object):
sickrage.app.config.view_changelog = True
if webui:
WebSocketMessage('redirect', {'url': '{}/home/restart/?pid={}'.format(sickrage.app.config.web_root,sickrage.app.pid)}).push()
WebSocketMessage('task', {'cmd': 'restart'}).push()
return True
......
......@@ -62,7 +62,7 @@ from sickrage.core.webserver.handlers.home import HomeHandler, IsAliveHandler, T
DeleteShowHandler, RefreshShowHandler, UpdateShowHandler, SubtitleShowHandler, UpdateKODIHandler, UpdatePLEXHandler, \
UpdateEMBYHandler, SyncTraktHandler, DeleteEpisodeHandler, SetStatusHandler, TestRenameHandler, DoRenameHandler, \
SearchEpisodeHandler, GetManualSearchStatusHandler, SearchEpisodeSubtitlesHandler, \
SetSceneNumberingHandler
SetSceneNumberingHandler, LoadShowsHandler
from sickrage.core.webserver.handlers.home.add_shows import HomeAddShowsHandler, SearchIndexersForShowNameHandler, \
MassAddTableHandler, NewShowHandler, TraktShowsHandler, PopularShowsHandler, AddShowToBlacklistHandler, \
ExistingShowsHandler, AddShowByIDHandler, AddNewShowHandler, AddExistingShowsHandler
......@@ -162,7 +162,7 @@ class WebServer(object):
# Websocket handler
self.app.add_handlers('.*$', [
(r'%s/ws' % sickrage.app.config.web_root, WebSocketUIHandler),
(r'%s/ws/ui' % sickrage.app.config.web_root, WebSocketUIHandler)
])
# Static File Handlers
......@@ -243,6 +243,7 @@ class WebServer(object):
(r'%s/browser(/?)' % sickrage.app.config.web_root, WebFileBrowserHandler),
(r'%s/browser/complete(/?)' % sickrage.app.config.web_root, WebFileBrowserCompleteHandler),
(r'%s/home(/?)' % sickrage.app.config.web_root, HomeHandler),
(r'%s/home/loadShows(/?)' % sickrage.app.config.web_root, LoadShowsHandler),
(r'%s/home/is_alive(/?)' % sickrage.app.config.web_root, IsAliveHandler),
(r'%s/home/testSABnzbd(/?)' % sickrage.app.config.web_root, TestSABnzbdHandler),
(r'%s/home/testTorrent(/?)' % sickrage.app.config.web_root, TestTorrentHandler),
......
......@@ -31,10 +31,12 @@ from mako.exceptions import RichTraceback
from mako.lookup import TemplateLookup
from requests import HTTPError
from tornado import locale
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
from tornado.web import RequestHandler
import sickrage
from sickrage.core import helpers, API
from sickrage.core.databases.main import MainDB
class BaseHandler(RequestHandler, ABC):
......@@ -142,7 +144,6 @@ class BaseHandler(RequestHandler, ABC):
'request': self.request,
}
self.ui = kwargs.pop('ui_modules', self.ui)
template_kwargs.update(self.get_template_namespace())
template_kwargs.update(kwargs)
......
......@@ -18,11 +18,17 @@
# You should have received a copy of the GNU General Public License
# along with SiCKRAGE. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
import calendar
import datetime
import os
import re
import time
from abc import ABC
from collections import OrderedDict
from functools import cmp_to_key
from urllib.parse import unquote_plus, quote_plus
import unidecode
from sqlalchemy import orm
from tornado import gen
from tornado.escape import json_encode
......@@ -38,10 +44,11 @@ from sickrage.core.databases.main import MainDB
from sickrage.core.exceptions import AnidbAdbaConnectionException, CantRefreshShowException, NoNFOException, \
CantUpdateShowException, CantRemoveShowException, EpisodeDeletedException, EpisodeNotFoundException, \
MultipleEpisodesInDatabaseException
from sickrage.core.helpers import clean_url, clean_host, clean_hosts, get_disk_space_usage, checkbox_to_value, try_int
from sickrage.core.helpers import clean_url, clean_host, clean_hosts, get_disk_space_usage, checkbox_to_value, try_int, srdatetime
from sickrage.core.helpers.anidb import get_release_groups_for_anime, short_group_names
from sickrage.core.helpers.srdatetime import SRDateTime
from sickrage.core.helpers.tornado_http import TornadoHTTP
from sickrage.core.media.util import showImage
from sickrage.core.queues.search import BacklogQueueItem, FailedQueueItem, ManualSearchQueueItem
from sickrage.core.scene_exceptions import get_scene_exceptions, update_scene_exceptions
from sickrage.core.scene_numbering import get_scene_numbering_for_show, get_xem_numbering_for_show, \
......@@ -51,7 +58,6 @@ from sickrage.core.traktapi import TraktAPI
from sickrage.core.tv.episode import TVEpisode
from sickrage.core.tv.show.helpers import find_show, get_show_list
from sickrage.core.webserver.handlers.base import BaseHandler
from sickrage.core.websocket import WebSocketMessage
from sickrage.indexers import IndexerApi
from sickrage.subtitles import Subtitles
......@@ -85,9 +91,7 @@ class HomeHandler(BaseHandler, ABC):
if not get_show_list().count():
return self.redirect('/home/addShows/')
self.run_task(self.load_shows, ui_modules=self.ui)
# showlists = OrderedDict({'Shows': []})
showlists = OrderedDict({'Shows': []})
# if sickrage.app.config.anime_split_home:
# for show in sorted(get_show_list(), key=cmp_to_key(lambda x, y: x.name < y.name)):
# if show.is_anime:
......@@ -104,31 +108,11 @@ class HomeHandler(BaseHandler, ABC):
title="Home",
header="Show List",
topmenu="home",
showlists=showlists,
controller='home',
action='index'
)
def load_shows(self, ui_modules):
show_count = get_show_list().count()
shows_loading = [int(x['indexer_id']) for x in sickrage.app.show_queue.loading_show_list]
for show in get_show_list(session=self.db_session):
if sickrage.app.config.home_layout == 'poster':
WebSocketMessage('show', {'action': ('show_grid_append', 'show_grid_prepend')[show.indexer_id in shows_loading],
'show_count': show_count,
'item': self.render_string("/templates/show-container-grid.mako", show=show, is_anime=show.is_anime,
is_loading=show.indexer_id in shows_loading, ui_modules=ui_modules)}).push()
else:
WebSocketMessage('show', {'action': ('show_list_append', 'show_list_prepend')[show.indexer_id in shows_loading],
'show_count': show_count,
'item': self.render_string("/templates/show-container-list.mako", show=show, is_anime=show.is_anime,
is_loading=show.indexer_id in shows_loading, ui_modules=ui_modules)}).push()
if sickrage.app.config.home_layout == 'poster':
WebSocketMessage('show', {'action': 'load_show_grid'}).push()
else:
WebSocketMessage('show', {'action': 'load_show_list'}).push()
def statistics(self):
show_stat = {}
......@@ -173,6 +157,27 @@ class HomeHandler(BaseHandler, ABC):
return show_stat, overall_stats
class LoadShowsHandler(BaseHandler, ABC):
@authenticated
async def get(self, *args, **kwargs):
layout = self.get_argument('layout', 'poster')
to_return = ""
loading_show_list_ids = [int(x['indexer_id']) for x in sickrage.app.show_queue.loading_show_list]
for show in get_show_list():
if show.indexer_id in loading_show_list_ids:
continue
if layout == 'poster':
to_return += self.render_string("/templates/show-container-grid.mako", show=show)
else:
to_return += self.render_string("/templates/show-container-list.mako", show=show)
return self.write(to_return)
class IsAliveHandler(BaseHandler, ABC):
def get(self, *args, **kwargs):
self.set_header('Content-Type', 'text/javascript')
......
......@@ -11,6 +11,9 @@
from sickrage.core.helpers import srdatetime, pretty_file_size
from sickrage.core.media.util import showImage
%>
## <%block name="metas">
## <meta data-var="max_download_count" data-content="${overall_stats['episodes']['total'] * 100}">
## </%block>
<%block name="sub_navbar">
<div class="row submenu">
......@@ -93,29 +96,115 @@
</%block>
<%block name="content">
<%include file="../includes/loading.mako"/>
% if sickrage.app.config.home_layout == 'poster':
<div id="container" class="show-grid clearfix mx-auto d-none"></div>
% else:
<div class="row">
<div class="col-lg-10 mx-auto">
<table class="table d-none" id="showListTableShows">
<thead class="thead-dark">
<tr>
<th>${_('Next Ep')}</th>
<th>${_('Prev Ep')}</th>
<th>${_('Show')}</th>
<th>${_('Network')}</th>
<th>${_('Quality')}</th>
<th>${_('Downloads')}</th>
<th>${_('Size')}</th>
<th>${_('Active')}</th>
<th>${_('Status')}</th>
</tr>
</thead>
<tbody></tbody>
</table>
<% loading_show_list_ids = [] %>
% for curListType, curShowlist in showlists.items():
% if curListType == "Anime":
<div class="row">
<div class="col mx-auto">
<div class="h4 card" style="text-align: center;">${_('Anime List')}</div>
</div>
</div>
</div>
% endif
% endif
% if sickrage.app.config.home_layout == 'poster':
<div id="${('container', 'container-anime')[curListType == 'Anime' and sickrage.app.config.home_layout == 'poster']}"
class="show-grid clearfix mx-auto">
% for curLoadingShow in sickrage.app.show_queue.loading_show_list:
<% loading_show_list_ids.append(curLoadingShow['indexer_id']) %>
<div class="show-container" data-name="0" data-date="010101" data-network="0"
data-progress="101">
<div class="card card-block text-white bg-dark m-1 shadow">
<img alt="" title="${curLoadingShow['name']}" class="card-img-top"
src="${srWebRoot}/images/poster.png"/>
<div class="card-body text-truncate py-1 px-1 small">
<div class="show-title">
${curLoadingShow['name']}
</div>
</div>
<div class="card-footer show-details p-1">
<div class="show-details">
<div class="show-add text-center">${_('... Loading ...')}</div>
</div>
</div>
</div>
</div>
% endfor
</div>
<div class="show-grid-loading-status text-center m-3">
<i class="fas fa-spinner fa-spin fa-fw fa-10x"></i>
</div>
% else:
<div class="row">
<div class="col-lg-10 mx-auto">
<table class="table" id="showListTable${curListType}">
<thead class="thead-dark">
<tr>
<th>${_('Next Ep')}</th>
<th>${_('Prev Ep')}</th>
<th>${_('Show')}</th>
<th>${_('Network')}</th>
<th>${_('Quality')}</th>
<th>${_('Downloads')}</th>
<th>${_('Size')}</th>
<th>${_('Active')}</th>
<th>${_('Status')}</th>
</tr>
</thead>
% if sickrage.app.show_queue.loading_show_list:
<tbody>
% for curLoadingShow in sickrage.app.show_queue.loading_show_list:
<% loading_show_list_ids.append(curLoadingShow['indexer_id']) %>
<tr>
<td class="table-fit">(${_('loading')})</td>
<td></td>
<td>
<a data-fancybox
href="displayShow?show=${curLoadingShow['indexer_id']}">${curLoadingShow['name']}</a>
</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
% endfor
</tbody>
% endif
<tbody>
<tr class="show-list-loading-status">
<td>
<i class="fas fa-spinner fa-spin fa-fw"></i>
</td>
<td>
<i class="fas fa-spinner fa-spin fa-fw"></i>
</td>
<td>
<i class="fas fa-spinner fa-spin fa-fw"></i>
</td>
<td>
<i class="fas fa-spinner fa-spin fa-fw"></i>
</td>
<td>
<i class="fas fa-spinner fa-spin fa-fw"></i>
</td>
<td>
<i class="fas fa-spinner fa-spin fa-fw"></i>
</td>
<td>
<i class="fas fa-spinner fa-spin fa-fw"></i>
</td>
<td>
<i class="fas fa-spinner fa-spin fa-fw"></i>
</td>
<td>
<i class="fas fa-spinner fa-spin fa-fw"></i>
</td>
</tr>
</tbody>
</table>
</div>
</div>
% endif
% endfor
</%block>
<div id="indicatorContainer" style="background-image: url('https://git.sickrage.ca/SiCKRAGE/sickrage/raw/master/sickrage/core/webserver/static/images/logo-badge.png');background-position:center;background-repeat: no-repeat;background-size: 60px"></div>
\ No newline at end of file
% if not is_loading:
<%!
import re
import calendar
import unidecode
import datetime
<%!
import re
import calendar
import unidecode
import datetime
import sickrage
from sickrage.core.helpers import srdatetime, pretty_file_size
from sickrage.core.media.util import showImage
%>
<%namespace file="../includes/quality_defaults.mako" import="renderQualityPill"/>
<%
download_stat_tip = ''
display_status = show.status
import sickrage
from sickrage.core.helpers import srdatetime, pretty_file_size
from sickrage.core.media.util import showImage
%>
<%namespace file="../includes/quality_defaults.mako" import="renderQualityPill"/>
<%
download_stat_tip = ''
display_status = show.status
if display_status:
if re.search(r'(?i)(?:new|returning)\s*series', show.status):
display_status = _('Continuing')
elif re.search(r'(?i)(?:nded)', show.status):
display_status = _('Ended')
if display_status:
if re.search(r'(?i)(?:new|returning)\s*series', show.status):
display_status = _('Continuing')
elif re.search(r'(?i)(?:nded)', show.status):
display_status = _('Ended')
cur_airs_next = show.airs_next
cur_snatched = show.episodes_snatched
cur_downloaded = show.episodes_downloaded
cur_total = len(show.episodes) - show.episodes_special - show.episodes_unaired
cur_airs_next = show.airs_next
cur_snatched = show.episodes_snatched
cur_downloaded = show.episodes_downloaded
cur_total = len(show.episodes) - show.episodes_special - show.episodes_unaired
if cur_total != 0:
download_stat = str(cur_downloaded)
download_stat_tip = _("Downloaded: ") + str(cur_downloaded)
if cur_snatched > 0:
download_stat = download_stat
download_stat_tip = download_stat_tip + " " + _("Snatched: ") + str(cur_snatched)
if cur_total != 0:
download_stat = str(cur_downloaded)
download_stat_tip = _("Downloaded: ") + str(cur_downloaded)
if cur_snatched > 0:
download_stat = download_stat
download_stat_tip = download_stat_tip + " " + _("Snatched: ") + str(cur_snatched)
download_stat = download_stat + " / " + str(cur_total)
download_stat_tip = download_stat_tip + " " + _("Total: ") + str(cur_total)
else:
download_stat = '?'
download_stat_tip = _("no data")
download_stat = download_stat + " / " + str(cur_total)
download_stat_tip = download_stat_tip + " " + _("Total: ") + str(cur_total)
else:
download_stat = '?'
download_stat_tip = _("no data")
progressbar_percent = int(cur_downloaded * 100 / cur_total if cur_total > 0 else 1)
progressbar_percent_class = "progress-{}".format('100' if progressbar_percent > 80 else '80' if progressbar_percent > 60 else '60' if progressbar_percent > 40 else '40' if progressbar_percent > 20 else '20')
progressbar_percent = int(cur_downloaded * 100 / cur_total if cur_total > 0 else 1)
progressbar_percent_class = "progress-{}".format('100' if progressbar_percent > 80 else '80' if progressbar_percent > 60 else '60' if progressbar_percent > 40 else '40' if progressbar_percent > 20 else '20')
data_date = '6000000000.0'
if cur_airs_next > datetime.date.min:
data_date = calendar.timegm(srdatetime.SRDateTime(sickrage.app.tz_updater.parse_date_time(cur_airs_next, show.airs, show.network), convert=True).dt.timetuple())
elif display_status:
if 'nded' not in display_status and 1 == int(show.paused):
data_date = '5000000500.0'
elif 'ontinu' in display_status:
data_date = '5000000000.0'
elif 'nded' in display_status:
data_date = '5000000100.0'
data_date = '6000000000.0'
if cur_airs_next > datetime.date.min:
data_date = calendar.timegm(srdatetime.SRDateTime(sickrage.app.tz_updater.parse_date_time(cur_airs_next, show.airs, show.network), convert=True).dt.timetuple())
elif display_status:
if 'nded' not in display_status and 1 == int(show.paused):
data_date = '5000000500.0'
elif 'ontinu' in display_status:
data_date = '5000000000.0'
elif 'nded' in display_status:
data_date = '5000000100.0'
network_class_name = None
if show.network:
network_class_name = re.sub(r'(?!\w|\s).', '', unidecode.unidecode(show.network))
network_class_name = re.sub(r'\s+', '-', network_class_name)
network_class_name = re.sub(r'^(\s*)([\W\w]*)(\b\s*$)', '\\2', network_class_name)
network_class_name = network_class_name.lower()
%>
<div class="show-container" id="show${show.indexer_id}" data-name="${show.name}"
data-date="${data_date}" data-network="${show.network}"
data-progress="${progressbar_percent}">
<div class="card card-block text-white bg-dark m-1 shadow">
<a href="${srWebRoot}/home/displayShow?show=${show.indexer_id}">
<img alt="" class="card-img-top" src="${srWebRoot}${showImage(show.indexer_id, 'poster').url}"/>
</a>
<div class="card-header bg-dark py-0 px-0">
<span style="display: none;">${download_stat}</span>
<div class="bg-dark progress shadow">
<div class="progress-bar ${progressbar_percent_class} d-print-none"
style="width: ${progressbar_percent}%">
<div class="progressbarText" title="${download_stat_tip}">${download_stat}</div>
</div>
network_class_name = None
if show.network:
network_class_name = re.sub(r'(?!\w|\s).', '', unidecode.unidecode(show.network))
network_class_name = re.sub(r'\s+', '-', network_class_name)
network_class_name = re.sub(r'^(\s*)([\W\w]*)(\b\s*$)', '\\2', network_class_name)
network_class_name = network_class_name.lower()
%>
<div class="show-container" id="show${show.indexer_id}" data-name="${show.name}"
data-date="${data_date}" data-network="${show.network}"
data-progress="${progressbar_percent}">
<div class="card card-block text-white bg-dark m-1 shadow">
<a href="${srWebRoot}/home/displayShow?show=${show.indexer_id}">
<img alt="" class="card-img-top" src="${srWebRoot}${showImage(show.indexer_id, 'poster').url}"/>
</a>
<div class="card-header bg-dark py-0 px-0">
<span style="display: none;">${download_stat}</span>
<div class="bg-dark progress shadow">
<div class="progress-bar ${progressbar_percent_class} d-print-none" style="width: ${progressbar_percent}%">
<div class="progressbarText" title="${download_stat_tip}">${download_stat}</div>
</div>
</div>
<div class="card-body text-truncate py-1 px-1 small">
<div class="show-title">
${show.name}
</div>
<div class="show-date" style="color: grey">
% if cur_airs_next > datetime.date.min:
<% ldatetime = srdatetime.SRDateTime(sickrage.app.tz_updater.parse_date_time(cur_airs_next, show.airs, show.network), convert=True).dt %>
<%
try:
out = srdatetime.SRDateTime(ldatetime).srfdate()
except ValueError:
out = _('Invalid date')
%>
% else:
<% display_status = show.status %>
<%
out = 'UNKNOWN'
if display_status:
out = display_status
if 'nded' not in display_status and 1 == int(show.paused):
out = _('Paused')
%>
% endif
${out}
</div>
</div>
<div class="card-footer show-details p-1">
<table class="show-details w-100" style="height:40px">
<tr>
<td class="text-left align-middle w-25">
% if show.network:
<span>
<i class="show-network-image sickrage-network sickrage-network-${network_class_name}"
title="${show.network}"></i>
</span>
% else:
<span>
<i class="show-network-image sickrage-network sickrage-network-unknown"
title="${_('No Network')}"></i>
</span>
% endif
</td>
<td class="text-right align-middle w-25">
${renderQualityPill(show.quality, showTitle=True)}
</td>
</tr>
</table>
</div>
</div>
</div>
% else:
<div class="show-container" data-name="0" data-date="010101" data-network="0"
data-progress="101">
<div class="card card-block text-white bg-dark m-1 shadow">
<img alt="" title="${show.name}" class="card-img-top" src="${srWebRoot}/images/poster.png"/>
<div class="card-body text-truncate py-1 px-1 small">
<div class="show-title">
${show.name}
</div>
<div class="card-body text-truncate py-1 px-1 small">
<div class="show-title">
${show.name}
</div>
<div class="card-footer show-details p-1">
<div class="show-details">
<div class="show-add text-center">${_('... Loading ...')}</div>
</div>
<div class="show-date" style="color: grey">
% if cur_airs_next > datetime.date.min:
<% ldatetime = srdatetime.SRDateTime(sickrage.app.tz_updater.parse_date_time(cur_airs_next, show.airs, show.network), convert=True).dt %>
<%
try:
out = srdatetime.SRDateTime(ldatetime).srfdate()
except ValueError:
out = _('Invalid date')
%>
% else:
<% display_status = show.status %>
<%
out = 'UNKNOWN'
if display_status:
out = display_status
if 'nded' not in display_status and 1 == int(show.paused):
out = _('Paused')
%>
% endif
${out}
</div>
</div>
<div class="card-footer show-details p-1">
<table class="show-details w-100" style="height:40px">
<tr>
<td class="text-left align-middle w-25">
% if show.network:
<span>
<i class="show-network-image sickrage-network sickrage-network-${network_class_name}"
title="${show.network}"></i>
</span>
% else:
<span>
<i class="show-network-image sickrage-network sickrage-network-unknown"
title="${_('No Network')}"></i>
</span>
% endif
</td>
<td class="text-right align-middle w-25">
${renderQualityPill(show.quality, showTitle=True)}