All checks were successful
continuous-integration/drone/push Build is passing
100 lines
3.2 KiB
C#
100 lines
3.2 KiB
C#
using System;
|
|
using System.Web;
|
|
using CinemaLib.API;
|
|
using CinemaWeb.Layouts;
|
|
|
|
namespace CinemaWeb.Pages;
|
|
|
|
public class EpisodesPage : BasicLayout
|
|
{
|
|
private readonly string _parentId;
|
|
private readonly string _title;
|
|
|
|
public EpisodesPage(string parentId, string title)
|
|
{
|
|
this._parentId = parentId;
|
|
this._title = title;
|
|
}
|
|
|
|
protected override string Title => _title;
|
|
|
|
protected override async Task RenderContentAsync(HttpRequest req, TextWriter w, CancellationToken cancel)
|
|
{
|
|
w.WriteLine("<h1>" + HttpUtility.HtmlEncode(_title) + "</h1>");
|
|
|
|
FilterResponse? res = await Metadata.ChildrenAsync(_parentId, sort: FilterSortBy.Episode, cancel: cancel);
|
|
|
|
if (res == null || res.hits == null || res.hits.hits == null || res.hits.hits.Count == 0)
|
|
{
|
|
w.WriteLine("<em>Nic nenalezeno</em>");
|
|
}
|
|
else
|
|
{
|
|
if (res.hits.hits[0]._source?.children_count == 0)
|
|
{
|
|
// Just episodes
|
|
w.WriteLine("<h2>Epizody</h2>");
|
|
RenderEpisodes(w, res.hits.hits, _title);
|
|
|
|
}
|
|
else
|
|
{
|
|
// Seasons and episodes
|
|
foreach (MediaInfo i in res.hits.hits)
|
|
{
|
|
if (i._source == null)
|
|
continue;
|
|
InfoLabelI18n? label = i._source.i18n_info_labels?.Where(x => x.lang == "cs").FirstOrDefault();
|
|
if (label == null)
|
|
label = i._source.i18n_info_labels?.FirstOrDefault();
|
|
if (label == null)
|
|
continue;
|
|
|
|
w.WriteLine("<h2>Sezóna " + label.title + "</h2>");
|
|
|
|
FilterResponse? resEp = await Metadata.ChildrenAsync(i._id, sort: FilterSortBy.Episode, cancel: cancel);
|
|
if (resEp == null || resEp.hits == null || resEp.hits.hits == null || resEp.hits.hits.Count == 0)
|
|
{
|
|
w.WriteLine("<em>Nic nenalezeno</em>");
|
|
}
|
|
else
|
|
{
|
|
RenderEpisodes(w, resEp.hits.hits, _title + " - " + label.title);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void RenderEpisodes(TextWriter w, IEnumerable<MediaInfo> episodes, string parentTitles)
|
|
{
|
|
w.WriteLine("<div class=\"media-episodes\">");
|
|
foreach (MediaInfo i in episodes)
|
|
{
|
|
if (i._source == null)
|
|
continue;
|
|
InfoLabelI18n? label = i._source.i18n_info_labels?.Where(x => x.lang == "cs").FirstOrDefault();
|
|
if (label == null)
|
|
label = i._source.i18n_info_labels?.FirstOrDefault();
|
|
if (label == null)
|
|
continue;
|
|
|
|
string? artUriS = label?.art?.poster ?? label?.art?.fanart;
|
|
Uri? artUri;
|
|
if (artUriS == null)
|
|
artUri = null;
|
|
else if (Metadata.TryGetThumbnail(artUri = new Uri(artUriS), 128, 128, out Uri? artThumbUri))
|
|
artUri = artThumbUri;
|
|
|
|
string streamsUri = "/streams/" + i._id + "/" + HttpUtility.UrlEncode(parentTitles + " - " + label?.title ?? "neznamy");
|
|
|
|
w.WriteLine("<div class=\"media-info\">");
|
|
w.WriteLine("<div class=\"media-art\"><a href=\"" + streamsUri + "\"><img src=\"" + artUri?.ToString() + "\"></a></div>");
|
|
w.WriteLine("<div class=\"media-title\"><a href=\"" + streamsUri + "\">" + HttpUtility.HtmlEncode(label?.title) + "</a></div>");
|
|
w.WriteLine("<div class=\"media-plot\">" + HttpUtility.HtmlEncode(label?.plot) + "</div>");
|
|
w.WriteLine("</div>"); // media-info
|
|
}
|
|
w.WriteLine("</div>");
|
|
}
|
|
}
|