All checks were successful
continuous-integration/drone/push Build is passing
78 lines
3.0 KiB
C#
78 lines
3.0 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Web;
|
|
|
|
using CinemaWeb.Layouts;
|
|
using CinemaLib.API;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace CinemaWeb.Pages;
|
|
|
|
public class SearchPage : BasicLayout
|
|
{
|
|
private const int PageSize = 30;
|
|
private const string ParamExpression = "expr";
|
|
private const string ParamPageIdx = "page";
|
|
|
|
protected override string Title => "Hledat filmy a seriály";
|
|
|
|
protected override async Task RenderContentAsync(HttpRequest req, TextWriter w)
|
|
{
|
|
string? expr;
|
|
if ((expr = req.Query["expr"]) == null || expr.Trim().Length == 0)
|
|
{
|
|
// Show search
|
|
w.WriteLine("<h1>Hledat filmy a seriály</h1>");
|
|
w.WriteLine("<form method=\"GET\" action=\"/\">");
|
|
w.WriteLine("<input type=\"text\" name=\"" + ParamExpression + "\" style=\"width:100%;margin:1em\">");
|
|
w.WriteLine("<input type=\"submit\" value=\"Hledat\">");
|
|
w.WriteLine("</form>");
|
|
|
|
}
|
|
else
|
|
{
|
|
// Execute search
|
|
string? pageS = req.Query[ParamPageIdx];
|
|
int page = pageS != null && int.TryParse(pageS, out int value) ? value : 0;
|
|
FilterResponse? res = await Metadata.SearchAsync(expr, offset: page * PageSize, limit: PageSize, cancel: req.HttpContext.RequestAborted);
|
|
|
|
w.WriteLine("<h1>Hledání: " + HttpUtility.HtmlEncode(expr) + "</h1>");
|
|
if (res == null || res.hits == null || res.hits.hits == null || res.hits.hits.Count == 0)
|
|
{
|
|
w.WriteLine("<em>Nic nenalezeno</em>");
|
|
}
|
|
else
|
|
{
|
|
w.WriteLine("<div class=\"search-results\">");
|
|
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;
|
|
|
|
string? artUriS = label?.art?.poster ?? label?.art?.fanart;
|
|
Uri? artUri;
|
|
if (artUriS == null)
|
|
artUri = null;
|
|
else if (Metadata.TryGetThumbnail(artUri = new Uri(artUriS), 300, 300, out Uri? artThumbUri))
|
|
artUri = artThumbUri;
|
|
|
|
string detailUri = (i._source.children_count == 0 ? "media" : "episodes") + "/" + i._id + "/" + HttpUtility.UrlEncode(label?.title ?? "neznamy");
|
|
|
|
w.WriteLine("<div class=\"media-info\">");
|
|
w.WriteLine("<div class=\"media-art\"><a href=\"" + detailUri + "\"><img src=\"" + artUri?.ToString() + "\"></a></div>");
|
|
w.WriteLine("<div class=\"media-title\"><a href=\"" + detailUri + "\">" + 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>");
|
|
w.WriteLine("<div class=\"btn\"><a href=\"?" + ParamExpression + "=" + HttpUtility.UrlEncode(expr) + "&" + ParamPageIdx + "=" + (page + 1).ToString() + "\">Další</a></div>");
|
|
}
|
|
}
|
|
}
|
|
}
|