add back and forward
This commit is contained in:
parent
8c5255be59
commit
5bdd16beca
39
Program.cs
39
Program.cs
|
@ -73,6 +73,29 @@ routeServer.Add("/movie",async(ctx)=>{
|
|||
using(var jsonStrm = File.OpenRead(file))
|
||||
movie=await JsonSerializer.DeserializeAsync<YTSMovie>(jsonStrm);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var res=await client.GetFromJsonAsync<YTSMovieResponse>($"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<object> torrents=new List<object>();
|
||||
|
@ -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<YTSMovie> Movies {get;set;}=new List<YTSMovie>();
|
||||
}
|
||||
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;}="";
|
||||
|
|
|
@ -20,6 +20,17 @@
|
|||
</div>
|
||||
<nav>
|
||||
<a href="{{yts_url}}" class="button">View on YTS.MX</a>
|
||||
<nav class="no-space">
|
||||
<a href="./movie?id={{prev}}" class="button border left-round fill">
|
||||
<span><i>arrow_back</i></span>
|
||||
</a>
|
||||
<button class="border no-round">
|
||||
<span>{{id}}</span>
|
||||
</button>
|
||||
<a href="./movie?id={{next}}" class="button border right-round fill">
|
||||
<span><i>arrow_forward</i></span>
|
||||
</a>
|
||||
</nav>
|
||||
</nav>
|
||||
</article>
|
||||
|
||||
|
@ -42,3 +53,4 @@
|
|||
</a>
|
||||
{{end}}
|
||||
|
||||
|
||||
|
|
|
@ -14,4 +14,16 @@
|
|||
<div>
|
||||
<a href="{{movie.url}}"><img src="{{movie.thumbnail}}" alt="thumbnail"> {{movie.title}}</a>
|
||||
</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
<nav class="no-space">
|
||||
<a href="./search?q={{search_text_attr}}&page={{prev}}" class="button border left-round fill">
|
||||
<span><i>arrow_back</i></span>
|
||||
</a>
|
||||
<button class="border no-round">
|
||||
<span>{{page}}</span>
|
||||
</button>
|
||||
<a href="./search?q={{search_text_attr}}&page={{next}}" class="button border right-round fill">
|
||||
<span><i>arrow_forward</i></span>
|
||||
</a>
|
||||
</nav>
|
Loading…
Reference in New Issue