TYTD Throwback is OPEN
This commit is contained in:
parent
71d3540d8c
commit
eb1a77ec70
31
Program.cs
31
Program.cs
|
@ -13,8 +13,8 @@ namespace TYTDThrowback;
|
|||
|
||||
class Program
|
||||
{
|
||||
static readonly ILiteDatabase liteDatabase=new LiteDatabase("data/database.db");
|
||||
static ILiteCollection<VideoInfo> Videos => liteDatabase.GetCollection<VideoInfo>("videos");
|
||||
ILiteDatabase liteDatabase=new LiteDatabase("data/database.db");
|
||||
ILiteCollection<VideoInfo> Videos => liteDatabase.GetCollection<VideoInfo>("videos");
|
||||
public class VideoInfo {
|
||||
|
||||
public VideoInfo()
|
||||
|
@ -87,15 +87,19 @@ class Program
|
|||
|
||||
}
|
||||
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;
|
||||
static bool AllowDownloadingInfoFrom {get;set;}=false;
|
||||
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<VideoInfo?> TYTDVideoInfo(VideoId id)
|
||||
private async Task<VideoInfo?> TYTDVideoInfo(VideoId id)
|
||||
{
|
||||
if(!AllowDownloadingInfoFrom) return null;
|
||||
if(string.IsNullOrWhiteSpace(Downloader))
|
||||
|
@ -219,7 +222,7 @@ class Program
|
|||
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);
|
||||
if(vid == null)
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue