TYTD Throwback is OPEN

This commit is contained in:
Mike Nolan 2024-03-07 17:31:20 -06:00
parent 71d3540d8c
commit eb1a77ec70
2 changed files with 21 additions and 16 deletions

View File

@ -13,8 +13,8 @@ namespace TYTDThrowback;
class Program class Program
{ {
static readonly ILiteDatabase liteDatabase=new LiteDatabase("data/database.db"); ILiteDatabase liteDatabase=new LiteDatabase("data/database.db");
static ILiteCollection<VideoInfo> Videos => liteDatabase.GetCollection<VideoInfo>("videos"); ILiteCollection<VideoInfo> Videos => liteDatabase.GetCollection<VideoInfo>("videos");
public class VideoInfo { public class VideoInfo {
public VideoInfo() public VideoInfo()
@ -86,16 +86,20 @@ class Program
} }
} }
static readonly HttpClient http = new HttpClient(); static readonly HttpClient http = new HttpClient();
static readonly YoutubeClient client=new YoutubeClient(http); 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; bool AllowDownloadingFrom {get;set;}=true;
static bool AllowDownloadingInfoFrom {get;set;}=false; bool AllowDownloadingInfoFrom {get;set;}=false;
static void Main(string[] args) static void Main(string[] args)
{
new Program().Run();
}
void Run()
{ {
if(File.Exists("data/tytd.json")) if(File.Exists("data/tytd.json"))
{ {
@ -112,8 +116,7 @@ class Program
routeServer.Add("/download",DownloadAsync); routeServer.Add("/download",DownloadAsync);
routeServer.StartServer(9900); routeServer.StartServer(9900);
} }
async Task StreamAsync(ServerContext ctx,bool play, VideoInfo video)
static async Task StreamAsync(ServerContext ctx,bool play, VideoInfo video)
{ {
ContentDisposition disposition=new ContentDisposition(); ContentDisposition disposition=new ContentDisposition();
disposition.FileName = $"{video.VideoTitle}-{video.VideoId}.{video.Container}"; disposition.FileName = $"{video.VideoTitle}-{video.VideoId}.{video.Container}";
@ -122,7 +125,7 @@ class Program
ctx.ResponseHeaders.Add("Content-Disposition",disposition.ToString()); ctx.ResponseHeaders.Add("Content-Disposition",disposition.ToString());
await ctx.SendStreamAsync(await client.Videos.Streams.GetAsync(video.GetIStream()),HeyRed.Mime.MimeTypesMap.GetMimeType($"file.{video.Container}")); 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; VideoId? vi=null;
if(ctx.QueryParams.TryGetFirst("v", out var v) && (vi = VideoId.TryParse(v) ).HasValue) 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; VideoId? vi=null;
if(ctx.QueryParams.TryGetFirst("v", out var v) && (vi = VideoId.TryParse(v) ).HasValue) 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)) if(!ctx.QueryParams.TryGetFirst("q",out var query))
query="Trending"; 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())); 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<VideoInfo?> TYTDVideoInfo(VideoId id) private async Task<VideoInfo?> TYTDVideoInfo(VideoId id)
{ {
if(!AllowDownloadingInfoFrom) return null; if(!AllowDownloadingInfoFrom) return null;
if(string.IsNullOrWhiteSpace(Downloader)) if(string.IsNullOrWhiteSpace(Downloader))
@ -219,7 +222,7 @@ class Program
return null; return null;
} }
} }
private static async Task<VideoInfo> EnsureVideoAsync(VideoId v) private async Task<VideoInfo> EnsureVideoAsync(VideoId v)
{ {
var vid = Videos.FindOne(e=>e.VideoId == v.Value); var vid = Videos.FindOne(e=>e.VideoId == v.Value);
if(vid == null) if(vid == null)

View File

@ -1,6 +1,8 @@
TYTD Throwback 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)) 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))