From 5bdd16becab8eb79be2bc15353914fda5edb551e Mon Sep 17 00:00:00 2001 From: Mike Nolan Date: Fri, 11 Oct 2024 19:00:31 -0500 Subject: [PATCH] add back and forward --- Program.cs | 39 ++++++++++++++++++++++++++++++++-- data/wwwroot/movie/index.html | 12 +++++++++++ data/wwwroot/search/index.html | 14 +++++++++++- 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/Program.cs b/Program.cs index cefc8e0..7172a7b 100644 --- a/Program.cs +++ b/Program.cs @@ -73,6 +73,29 @@ routeServer.Add("/movie",async(ctx)=>{ using(var jsonStrm = File.OpenRead(file)) movie=await JsonSerializer.DeserializeAsync(jsonStrm); } + else + { + + var res=await client.GetFromJsonAsync($"https://yts.mx/api/v2/movie_details.json?movie_id={id}"); + if(res != null) + { + if(res.Status == "ok") + { + if(res.Data.Movie.Id != 0) + { + string _file = $"data/cache/movie/{res.Data.Movie.Id}.json"; + if(!File.Exists(_file)) + { + using(var f = File.Create(_file)) + { + await System.Text.Json.JsonSerializer.SerializeAsync(f,res.Data.Movie); + } + movie=res.Data.Movie; + } + } + } + } + } if(movie != null) { List torrents=new List(); @@ -87,7 +110,7 @@ routeServer.Add("/movie",async(ctx)=>{ string runtime = $"{hrs}:{mins.ToString("D2")}"; - var body=await index.RenderAsync(new{yts_url =HttpUtility.HtmlAttributeEncode(movie.Url) ,mpa_rating =HttpUtility.HtmlEncode(movie.MpaRating),runtime,thumbnail = HttpUtility.HtmlAttributeEncode(movie.MediumCoverImage), name=HttpUtility.HtmlEncode(movie.TitleLong),torrents}); + var body=await index.RenderAsync(new{yts_url =HttpUtility.HtmlAttributeEncode(movie.Url) ,mpa_rating =HttpUtility.HtmlEncode(movie.MpaRating),runtime,thumbnail = HttpUtility.HtmlAttributeEncode(movie.MediumCoverImage), name=HttpUtility.HtmlEncode(movie.TitleLong),torrents,next=id+1,prev=id-1,id}); string title = $"{HttpUtility.HtmlEncode(movie.TitleLong)} - Request Movies"; await ctx.SendTextAsync(await template.RenderAsync(new{body,title})); } @@ -133,7 +156,7 @@ routeServer.Add("/search",async(ctx)=>{ } } } - string body = await index.RenderAsync(new{results,search_text=HttpUtility.HtmlEncode(q), search_text_attr=HttpUtility.HtmlAttributeEncode(q)}); + string body = await index.RenderAsync(new{results,search_text=HttpUtility.HtmlEncode(q), search_text_attr=HttpUtility.HtmlAttributeEncode(q),prev=page-1,next=page+1,page}); await ctx.SendTextAsync(await template.RenderAsync(new{title = $"{HttpUtility.HtmlEncode(q)} - Request Movies",body})); @@ -269,6 +292,18 @@ public class YTSSearchResponseData [JsonPropertyName("movies")] public List Movies {get;set;}=new List(); } +public class YTSMovieResponseData +{ + [JsonPropertyName("movie")] + public YTSMovie Movie {get;set;}=new YTSMovie(); +} +public class YTSMovieResponse { + [JsonPropertyName("status")] + public string Status {get;set;}=""; + + [JsonPropertyName("data")] + public YTSMovieResponseData Data {get;set;}=new YTSMovieResponseData(); +} public class YTSSearchResponse { [JsonPropertyName("status")] public string Status {get;set;}=""; diff --git a/data/wwwroot/movie/index.html b/data/wwwroot/movie/index.html index 8bf2ce3..8adb2e4 100644 --- a/data/wwwroot/movie/index.html +++ b/data/wwwroot/movie/index.html @@ -20,6 +20,17 @@ @@ -42,3 +53,4 @@ {{end}} + diff --git a/data/wwwroot/search/index.html b/data/wwwroot/search/index.html index efb97ef..86dceee 100644 --- a/data/wwwroot/search/index.html +++ b/data/wwwroot/search/index.html @@ -14,4 +14,16 @@ -{{end}} \ No newline at end of file +{{end}} + + \ No newline at end of file