From eb1a77ec705b03cb52eba35c7384594271a24cd6 Mon Sep 17 00:00:00 2001 From: Mike Nolan Date: Thu, 7 Mar 2024 17:31:20 -0600 Subject: [PATCH] TYTD Throwback is OPEN --- Program.cs | 35 +++++++++++++++++++---------------- README.md | 2 ++ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Program.cs b/Program.cs index f36d8af..05e08c3 100644 --- a/Program.cs +++ b/Program.cs @@ -13,8 +13,8 @@ namespace TYTDThrowback; class Program { - static readonly ILiteDatabase liteDatabase=new LiteDatabase("data/database.db"); - static ILiteCollection Videos => liteDatabase.GetCollection("videos"); + ILiteDatabase liteDatabase=new LiteDatabase("data/database.db"); + ILiteCollection Videos => liteDatabase.GetCollection("videos"); public class VideoInfo { public VideoInfo() @@ -86,16 +86,20 @@ class Program } } - static readonly HttpClient http = new HttpClient(); - static readonly YoutubeClient client=new YoutubeClient(http); + static readonly HttpClient http = new HttpClient(); + YoutubeClient client=new YoutubeClient(http); - static string Downloader {get;set;}="https://tytd.site.tesses.net/"; + string Downloader {get;set;}="https://tytd.site.tesses.net/"; - static bool AllowAddingTo {get;set;}=true; + bool AllowAddingTo {get;set;}=true; - static bool AllowDownloadingFrom {get;set;}=true; - static bool AllowDownloadingInfoFrom {get;set;}=false; - static void Main(string[] args) + bool AllowDownloadingFrom {get;set;}=true; + bool AllowDownloadingInfoFrom {get;set;}=false; + static void Main(string[] args) + { + new Program().Run(); + } + void Run() { if(File.Exists("data/tytd.json")) { @@ -112,8 +116,7 @@ class Program routeServer.Add("/download",DownloadAsync); routeServer.StartServer(9900); } - - static async Task StreamAsync(ServerContext ctx,bool play, VideoInfo video) + async Task StreamAsync(ServerContext ctx,bool play, VideoInfo video) { ContentDisposition disposition=new ContentDisposition(); disposition.FileName = $"{video.VideoTitle}-{video.VideoId}.{video.Container}"; @@ -122,7 +125,7 @@ class Program ctx.ResponseHeaders.Add("Content-Disposition",disposition.ToString()); await ctx.SendStreamAsync(await client.Videos.Streams.GetAsync(video.GetIStream()),HeyRed.Mime.MimeTypesMap.GetMimeType($"file.{video.Container}")); } - static async Task DownloadAsync(ServerContext ctx) + async Task DownloadAsync(ServerContext ctx) { VideoId? vi=null; if(ctx.QueryParams.TryGetFirst("v", out var v) && (vi = VideoId.TryParse(v) ).HasValue) @@ -147,7 +150,7 @@ class Program } - static async Task InfoAsync(ServerContext ctx) + async Task InfoAsync(ServerContext ctx) { VideoId? vi=null; if(ctx.QueryParams.TryGetFirst("v", out var v) && (vi = VideoId.TryParse(v) ).HasValue) @@ -170,7 +173,7 @@ class Program } } - static async Task SearchAsync(ServerContext ctx) + async Task SearchAsync(ServerContext ctx) { if(!ctx.QueryParams.TryGetFirst("q",out var query)) query="Trending"; @@ -196,7 +199,7 @@ class Program await ctx.SendTextAsync((await File.ReadAllTextAsync("data/www/search.html")).Replace("$QUERY---429492492942",HttpUtility.HtmlAttributeEncode(query)).Replace("$LI---429492492942",b.ToString())); } - private static async Task TYTDVideoInfo(VideoId id) + private async Task TYTDVideoInfo(VideoId id) { if(!AllowDownloadingInfoFrom) return null; if(string.IsNullOrWhiteSpace(Downloader)) @@ -219,7 +222,7 @@ class Program return null; } } - private static async Task EnsureVideoAsync(VideoId v) + private async Task EnsureVideoAsync(VideoId v) { var vid = Videos.FindOne(e=>e.VideoId == v.Value); if(vid == null) diff --git a/README.md b/README.md index 0967b0c..3723315 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ TYTD Throwback ============== +This app is visible at [TYTD Throwback](https://tytdthrowback.site.tesses.net/) + This is a website for searching/downloading YouTube videos (With Basic [TYTD](https://gitlab.tesses.net/tesses50/tytd.git) integration, it mimics [TYTD Wii 2019](https://gitlab.tesses.net/tesses50/tytd-2019))