79 lines
2.4 KiB
C#
79 lines
2.4 KiB
C#
using System;
|
|
using System.Web;
|
|
using StreamCinemaLib.API;
|
|
using StreamCinemaWeb.Layouts;
|
|
|
|
namespace StreamCinemaWeb.Pages;
|
|
|
|
public class StreamsPage : BasicLayout
|
|
{
|
|
private readonly string _id;
|
|
private readonly string _title;
|
|
|
|
public StreamsPage(string id, string title)
|
|
{
|
|
this._id = id;
|
|
this._title = title;
|
|
}
|
|
|
|
protected override string Title => _title;
|
|
|
|
protected override async Task RenderContentAsync(HttpRequest req, TextWriter w)
|
|
{
|
|
w.WriteLine("<h1>" + HttpUtility.HtmlEncode(_title) + "</h1>");
|
|
w.WriteLine("<div><b>Zvolte kvalitu</b></div>");
|
|
|
|
StreamCinemaLib.API.Stream[]? res = await Metadata.StreamsAsync(_id, cancel: req.HttpContext.RequestAborted);
|
|
|
|
if (res == null || res.Length == 0)
|
|
{
|
|
w.WriteLine("<em>Nic nenalezeno</em>");
|
|
}
|
|
else
|
|
{
|
|
RenderStreams(w, res, _title);
|
|
}
|
|
}
|
|
|
|
internal static void RenderStreams(TextWriter w, IEnumerable<StreamCinemaLib.API.Stream> streams, string title)
|
|
{
|
|
w.WriteLine("<div class=\"media-streams\">");
|
|
foreach (StreamCinemaLib.API.Stream i in streams)
|
|
{
|
|
w.WriteLine("<div class=\"media-stream\"><a href=\"/link/" + i.provider + "/" + HttpUtility.UrlEncode(i.ident) + "/" + HttpUtility.UrlEncode(i.name) + "/" + HttpUtility.UrlEncode(title) + "\">");
|
|
|
|
w.WriteLine($"<div class=\"stream-basic\">{Math.Round((double)(i.size ?? 0) / (1024 * 1024 * 1024), 2)} GB ({i.date_added})</div>");
|
|
|
|
if (i.video != null && i.video.Count != 0)
|
|
{
|
|
StreamVideo a = i.video.First();
|
|
string is3D = a.is3d ? " (3D)" : "";
|
|
w.WriteLine($"<div class=\"video-channel\">{a.width}x{a.height} {a.codec}{is3D} {Math.Round((a.duration ?? 0) / 60)} min</div>");
|
|
}
|
|
|
|
if (i.audio != null && i.audio.Count != 0)
|
|
{
|
|
w.WriteLine("<div class=\"audio-channels\">");
|
|
foreach (StreamAudio j in i.audio)
|
|
{
|
|
w.WriteLine($"<div class=\"audio-channel\">{j.language} {j.codec} {j.channels}</div>");
|
|
}
|
|
w.WriteLine("</div>");
|
|
}
|
|
|
|
if (i.subtitles != null && i.subtitles.Count != 0)
|
|
{
|
|
w.WriteLine("<div class=\"subtitle-channels\">");
|
|
foreach (StreamSubtitle j in i.subtitles)
|
|
{
|
|
w.WriteLine($"<div class=\"subtitle-channel\">{j.language}</div>");
|
|
}
|
|
w.WriteLine("</div>");
|
|
}
|
|
|
|
w.WriteLine("</a></div>");
|
|
}
|
|
w.WriteLine("</div>");
|
|
}
|
|
}
|