Files
stream-cinema/CinemaWeb/Pages/MediaPage.cs
2024-12-22 23:47:56 +01:00

57 lines
2.0 KiB
C#

using System;
using System.Web;
using CinemaLib.API;
using CinemaWeb.Layouts;
namespace CinemaWeb.Pages;
public class MediaPage : BasicLayout
{
private readonly string _id;
private readonly string _title;
public MediaPage(string id, string title)
{
this._id = id;
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>");
MediaSource? source = await Metadata.DetailAsync(_id, cancel);
InfoLabelI18n? label = source == null ? null : source.i18n_info_labels?.Where(x => x.lang == "cs").FirstOrDefault();
if (label == null && source != null)
label = source.i18n_info_labels?.FirstOrDefault();
if (source != null && source.info_labels != null)
w.WriteLine("<div><small>" + HttpUtility.HtmlEncode(source.info_labels.originaltitle) + "</small></div>");
if (source != null && label != null)
{
if (!string.IsNullOrEmpty(label.art?.poster) && Uri.TryCreate(label.art.poster, UriKind.Absolute, out Uri? posterUri)) {
if (Metadata.TryGetThumbnail(posterUri, 400, 600, out Uri? posterThumbUri))
posterUri = posterThumbUri;
w.WriteLine("<div style=\"float:left; margin:0em 1em 1em 0em\"><img src=\"" + posterUri.ToString() + "\" style=\"width:400px\"/></div>");
}
w.WriteLine($"<div>{source.info_labels?.year} | {source.ratings?.overall?.rating} | {TimeSpan.FromSeconds(source.info_labels?.duration ?? 0).TotalMinutes}m | { string.Join(", ", source.info_labels?.director ?? [])} </div>");
w.WriteLine($"<div>{label.plot}</div>");
}
w.WriteLine("<h2>Zvolte kvalitu</h2>");
CinemaLib.API.Stream[]? res = await Metadata.StreamsAsync(_id, cancel: cancel);
if (res == null || res.Length == 0)
{
w.WriteLine("<em>Nic nenalezeno</em>");
}
else
{
StreamsPage.RenderStreams(w, res, _title);
}
}
}