/*
TYTDDownloadWebUI a YouTube Search webui for TYTD (Note this program is seperate from the main TYTD Console App but depends on nuget package Tesses.YouTubeDownloader)
Copyright (C) 2023 Mike Nolan (Tesses)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
using System.Text;
using Tesses.WebServer;
using Tesses.YouTubeDownloader;
using YoutubeExplode;
using YoutubeExplode.Channels;
using YoutubeExplode.Playlists;
using YoutubeExplode.Search;
using YoutubeExplode.Videos;
/*
Configuration
*/
string myIP = "http://192.168.0.142:3252/"; //change me for your downloader
int myPort = 49204; //if you change me you also have to change this port in Dockerfile
/*
Code
*/
string redirstr = "
OK Added!OK Added!
Please use back button in browser
";
string failStr = "Failed To AddFailed To Add
Please use back button in browser
";
TYTDClient hclient = new TYTDClient(myIP);
YoutubeClient sclient = new YoutubeClient();
RouteServer routeServer=new RouteServer();
routeServer.Add("/",async(ctx)=>{
StringBuilder builder=new StringBuilder();
builder.Append("Download YouTube VideosDownload YouTube Videos
");
builder.Append("");
await ctx.SendTextAsync(builder.ToString());
});
routeServer.Add("/video",async(ctx)=>{
if(ctx.QueryParams.TryGetFirst("v",out var vid))
{
var id = VideoId.TryParse(vid);
if(id.HasValue)
{
await hclient.AddVideoAsync(id.Value);
await ctx.SendTextAsync(redirstr);
return;
}
}
await ctx.SendTextAsync(failStr);
});
routeServer.Add("/playlist",async(ctx)=>{
if(ctx.QueryParams.TryGetFirst("id",out var vid))
{
var id = PlaylistId.TryParse(vid);
if(id.HasValue)
{
await hclient.AddPlaylistAsync(id.Value);
await ctx.SendTextAsync(redirstr);
return;
}
}
await ctx.SendTextAsync(failStr);
});
routeServer.Add("/channel",async(ctx)=>{
if(ctx.QueryParams.TryGetFirst("id",out var vid))
{
var id = ChannelId.TryParse(vid);
if(id.HasValue)
{
await hclient.AddChannelAsync(id.Value);
await ctx.SendTextAsync(redirstr);
return;
}
}
await ctx.SendTextAsync(failStr);
});
routeServer.StartServer(myPort);