>(jsonData);
await Downloader.ReplacePersonalPlaylistAsync(name,itemList);
}
//Downloader.AddToPersonalPlaylistAsync(name);
}
await ctx.SendTextAsync(
$"You Will Be Redirected in 5 SecYou Will Be Redirected in 5 Sec
\n"
);
}
public async Task Everything_Export(ServerContext ctx)
{
var storage = Downloader as TYTDStorage;
if(storage != null)
{
if(storage.GetLoggerProperties().AllowExport)
{
TYTDExporter exporter=new TYTDExporter(storage);
var res=await exporter.ExportEverythingAsync();
await ctx.SendJsonAsync(res);
}else{
ctx.StatusCode=403;
await ctx.SendTextAsync("Can't Export, Access DeniedCan't Export, Access Denied
Call the TYTD adminstrator if you are not the administrator to edit the following
In file: config/tytdprop.json, unless overriden in code
Change "AllowExport":false with "AllowExport":true
");
}
}
}
public async Task VideosExport(ServerContext ctx)
{
var storage = Downloader as TYTDStorage;
if(storage != null)
{
if(storage.GetLoggerProperties().AllowExport)
{
TYTDExporter exporter=new TYTDExporter(storage);
var res=await exporter.ExportVideosAsync();
await ctx.SendJsonAsync(res);
}else{
ctx.StatusCode=403;
await ctx.SendTextAsync("Can't Export, Access DeniedCan't Export, Access Denied
Call the TYTD adminstrator if you are not the administrator to edit the following
In file: config/tytdprop.json, unless overriden in code
Change "AllowExport":false with "AllowExport":true
");
}
}
}
public async Task PlaylistsExport(ServerContext ctx)
{
var storage = Downloader as TYTDStorage;
if(storage != null)
{
if(storage.GetLoggerProperties().AllowExport)
{
TYTDExporter exporter=new TYTDExporter(storage);
var res=await exporter.ExportPlaylistsAsync();
await ctx.SendJsonAsync(res);
}else{
ctx.StatusCode=403;
await ctx.SendTextAsync("Can't Export, Access DeniedCan't Export, Access Denied
Call the TYTD adminstrator if you are not the administrator to edit the following
In file: config/tytdprop.json, unless overriden in code
Change "AllowExport":false with "AllowExport":true
");
}
}
}
public async Task ChannelsExport(ServerContext ctx)
{
var storage = Downloader as TYTDStorage;
if(storage != null)
{
if(storage.GetLoggerProperties().AllowExport)
{
TYTDExporter exporter=new TYTDExporter(storage);
var res=await exporter.ExportChannelsAsync();
await ctx.SendJsonAsync(res);
}else{
ctx.StatusCode=403;
await ctx.SendTextAsync("Can't Export, Access DeniedCan't Export, Access Denied
Call the TYTD adminstrator if you are not the administrator to edit the following
In file: config/tytdprop.json, unless overriden in code
Change "AllowExport":false with "AllowExport":true
");
}
}
}
public async Task FilesExport(ServerContext ctx)
{
var storage = Downloader as TYTDStorage;
if(storage != null)
{
if(storage.GetLoggerProperties().AllowExport)
{
TYTDExporter exporter=new TYTDExporter(storage);
var res=await exporter.ExportDownloadsAsync();
await ctx.SendJsonAsync(res);
}else{
ctx.StatusCode=403;
await ctx.SendTextAsync("Can't Export, Access DeniedCan't Export, Access Denied
Call the TYTD adminstrator if you are not the administrator to edit the following
In file: config/tytdprop.json, unless overriden in code
Change "AllowExport":false with "AllowExport":true
");
}
}
}
public async Task SubscriptionsExport(ServerContext ctx)
{
var storage = Downloader as TYTDStorage;
if(storage != null)
{
if(storage.GetLoggerProperties().AllowExport)
{
TYTDExporter exporter=new TYTDExporter(storage);
var res=await exporter.ExportSubscriptionsAsync();
await ctx.SendJsonAsync(res);
}else{
ctx.StatusCode=403;
await ctx.SendTextAsync("Can't Export, Access DeniedCan't Export, Access Denied
Call the TYTD adminstrator if you are not the administrator to edit the following
In file: config/tytdprop.json, unless overriden in code
Change "AllowExport":false with "AllowExport":true
");
}
}
}
public async Task PersonalListsExport(ServerContext ctx)
{
var storage = Downloader as TYTDStorage;
if(storage != null)
{
if(storage.GetLoggerProperties().AllowExport)
{
TYTDExporter exporter=new TYTDExporter(storage);
var res=await exporter.ExportPersonalPlaylistsAsync();
await ctx.SendJsonAsync(res);
}else{
ctx.StatusCode=403;
await ctx.SendTextAsync("Can't Export, Access DeniedCan't Export, Access Denied
Call the TYTD adminstrator if you are not the administrator to edit the following
In file: config/tytdprop.json, unless overriden in code
Change "AllowExport":false with "AllowExport":true
");
}
}
}
public async Task AddToList(ServerContext ctx)
{
//this is for personal playlists
string name;
if(ctx.QueryParams.TryGetFirst("name",out name)){
string jsonData;
List itemList;
if(ctx.Method == "POST" && ctx.QueryParams.TryGetFirst("data",out jsonData))
{
itemList = JsonConvert.DeserializeObject>(jsonData);
}else{
itemList=new List();
string id;
if(ctx.QueryParams.TryGetFirst("v",out id))
{
Resolution resolution=Resolution.PreMuxed;
string res;
if(ctx.QueryParams.TryGetFirst("res",out res))
{
if(!Enum.TryParse(res,out resolution))
{
resolution=Resolution.PreMuxed;
}
}
VideoId? id1=VideoId.TryParse(id);
if(id1.HasValue)
{
itemList.Add(new ListContentItem(id1,resolution));
}
}
}
await Downloader.AddToPersonalPlaylistAsync(name,itemList);
//Downloader.AddToPersonalPlaylistAsync(name);
}
await ctx.SendTextAsync(
$"You Will Be Redirected in 5 SecYou Will Be Redirected in 5 Sec
\n"
);
}
public async Task DeleteFromList(ServerContext ctx)
{
//this is for personal playlists
string name;
if(ctx.QueryParams.TryGetFirst("name",out name)){
string id;
if(ctx.QueryParams.TryGetFirst("v",out id))
{
VideoId? id1=VideoId.TryParse(id);
if(id1.HasValue)
{
await Downloader.RemoveItemFromPersonalPlaylistAsync(name,id1.Value);
}
}
}
await ctx.SendTextAsync(
$"You Will Be Redirected in 5 SecYou Will Be Redirected in 5 Sec
\n"
);
}
public async Task SetResolutionInList(ServerContext ctx)
{
//this is for personal playlists
string name;
if(ctx.QueryParams.TryGetFirst("name",out name)){
string id;
if(ctx.QueryParams.TryGetFirst("v",out id))
{
Resolution resolution=Resolution.PreMuxed;
string res;
if(ctx.QueryParams.TryGetFirst("res",out res))
{
if(!Enum.TryParse(res,out resolution))
{
resolution=Resolution.PreMuxed;
}
}
VideoId? id1=VideoId.TryParse(id);
if(id1.HasValue)
{
await Downloader.SetResolutionForItemInPersonalPlaylistAsync(name,id1.Value,resolution);
}
}
}
await ctx.SendTextAsync(
$"You Will Be Redirected in 5 SecYou Will Be Redirected in 5 Sec
\n"
);
}
public async Task Subscriptions(ServerContext ctx)
{
IStorage storage = Downloader as IStorage;
if(storage != null)
{
var sub=storage.GetLoadedSubscriptions();
await ctx.SendJsonAsync(sub);
}
await ctx.SendTextAsync(
$"You Will Be Redirected in 5 SecYou Will Be Redirected in 5 Sec
\n"
);
}
public async Task Resubscribe(ServerContext ctx)
{
IStorage storage = Downloader as IStorage;
if(storage != null)
{
string id;
if(ctx.QueryParams.TryGetFirst("id",out id))
{
string confstr;
ChannelBellInfo conf=ChannelBellInfo.NotifyAndDownload;
if(ctx.QueryParams.TryGetFirst("conf",out confstr))
{
if(!Enum.TryParse(confstr,out conf))
{
conf = ChannelBellInfo.NotifyAndDownload;
}
}
ChannelId? cid=ChannelId.TryParse(id);
if(cid.HasValue)
{
await storage.ResubscribeAsync(cid.Value,conf);
}
}
}
await ctx.SendTextAsync(
$"You Will Be Redirected in 5 SecYou Will Be Redirected in 5 Sec
\n"
);
}
public async Task Unsubscribe(ServerContext ctx)
{
IStorage storage = Downloader as IStorage;
if(storage != null)
{
string id;
if(ctx.QueryParams.TryGetFirst("id",out id))
{
ChannelId? cid=ChannelId.TryParse(id);
if(cid.HasValue)
{
storage.Unsubscribe(cid.Value);
}
}
}
await ctx.SendTextAsync(
$"You Will Be Redirected in 5 SecYou Will Be Redirected in 5 Sec
\n"
);
}
public async Task Subscribe(ServerContext ctx)
{
IStorage storage = Downloader as IStorage;
if(storage != null)
{
string id;
if(ctx.QueryParams.TryGetFirst("id",out id))
{
string getinfostr;
bool getinfo=true;
if(ctx.QueryParams.TryGetFirst("getinfo",out getinfostr))
{
if(getinfostr == "false")
{
getinfo=false;
}
}
string confstr;
ChannelBellInfo conf=ChannelBellInfo.NotifyAndDownload;
if(ctx.QueryParams.TryGetFirst("conf",out confstr))
{
if(!Enum.TryParse(confstr,out conf))
{
conf = ChannelBellInfo.NotifyAndDownload;
}
}
ChannelId? cid=ChannelId.TryParse(id);
if(cid.HasValue)
{
await storage.SubscribeAsync(cid.Value,getinfo,conf);
}else{
UserName? uname=UserName.TryParse(id);
await storage.SubscribeAsync(uname.Value,conf);
}
}
}
await ctx.SendTextAsync(
$"You Will Be Redirected in 5 SecYou Will Be Redirected in 5 Sec
\n"
);
}
public async Task QueueList(ServerContext ctx)
{
await ctx.SendJsonAsync(Downloader.GetQueueList());
}
public async Task ProgressFunc(ServerContext ctx)
{
await ctx.SendJsonAsync(Downloader.GetProgress());
}
public async Task AddFile(ServerContext ctx)
{
string url;
string downloadStr;
bool download=true;
if(ctx.QueryParams.TryGetFirst("url",out url))
{
if(ctx.QueryParams.TryGetFirst("download",out downloadStr))
{
bool dl;
if(bool.TryParse(downloadStr,out dl))
{
download=dl;
}
}
await Downloader.AddFileAsync(url,download);
await ctx.SendTextAsync(
$"You Will Be Redirected in 5 Sec
\n"
);
}
}
public async Task AddVideo(ServerContext ctx)
{
string id;
if(ctx.QueryParams.TryGetFirst("v",out id))
{
Resolution resolution=Resolution.PreMuxed;
string res;
if(ctx.QueryParams.TryGetFirst("res",out res))
{
if(!Enum.TryParse(res,out resolution))
{
resolution=Resolution.PreMuxed;
}
}
VideoId? id1=VideoId.TryParse(id);
if(id1.HasValue)
{
await Downloader.AddVideoAsync(id1.Value,resolution);
}
}
await ctx.SendTextAsync(
$"You Will Be Redirected in 5 SecYou Will Be Redirected in 5 Sec
\n"
);
}
public async Task AddItem(ServerContext ctx)
{
string id;
if(ctx.QueryParams.TryGetFirst("v",out id))
{
Resolution resolution=Resolution.PreMuxed;
string res;
if(ctx.QueryParams.TryGetFirst("res",out res))
{
if(!Enum.TryParse(res,out resolution))
{
resolution=Resolution.PreMuxed;
}
}
await Downloader.AddItemAsync(id,resolution);
}
await ctx.SendTextAsync(
$"You Will Be Redirected in 5 Sec
\n"
);
}
public async Task AddUser(ServerContext ctx)
{
string id;
if(ctx.QueryParams.TryGetFirst("id",out id))
{
Resolution resolution=Resolution.PreMuxed;
string res;
if(ctx.QueryParams.TryGetFirst("res",out res))
{
if(!Enum.TryParse(res,out resolution))
{
resolution=Resolution.PreMuxed;
}
}
UserName? id1=UserName.TryParse(id);
if(id1.HasValue)
{
await Downloader.AddUserAsync(id1.Value,resolution);
}
}
await ctx.SendTextAsync(
$"You Will Be Redirected in 5 Sec
\n"
);
}
public async Task AddChannel(ServerContext ctx)
{
string id;
if(ctx.QueryParams.TryGetFirst("id",out id))
{
Resolution resolution=Resolution.PreMuxed;
string res;
if(ctx.QueryParams.TryGetFirst("res",out res))
{
if(!Enum.TryParse(res,out resolution))
{
resolution=Resolution.PreMuxed;
}
}
ChannelId? id1=ChannelId.TryParse(id);
if(id1.HasValue)
{
await Downloader.AddChannelAsync(id1.Value,resolution);
}
}
await ctx.SendTextAsync(
$"You Will Be Redirected in 5 Sec
\n"
);
}
public async Task AddPlaylist(ServerContext ctx)
{
string id;
if(ctx.QueryParams.TryGetFirst("id",out id))
{
Resolution resolution=Resolution.PreMuxed;
string res;
if(ctx.QueryParams.TryGetFirst("res",out res))
{
if(!Enum.TryParse(res,out resolution))
{
resolution=Resolution.PreMuxed;
}
}
PlaylistId? id1=PlaylistId.TryParse(id);
if(id1.HasValue)
{
await Downloader.AddPlaylistAsync(id1.Value,resolution);
}
}
await ctx.SendTextAsync(
$"You Will Be Redirected in 5 Sec
\n"
);
}
}
public class TYTDServer
{
///
/// Constructor
///
/// TYTD context
public TYTDServer(ITYTDBase baseCtl)
{
ExtensionsServer=new ChangeableServer();
RootServer=new ChangeableServer();
MountableServer mountableServer=new MountableServer(RootServer);
IDownloader downloader=baseCtl as IDownloader;
if(downloader != null)
{
mountableServer.Mount("/api/",new ApiV1Server(downloader));
mountableServer.Mount("/api/v2/",new ApiV2Server(downloader));
}
mountableServer.Mount("/api/v2/Extensions/",ExtensionsServer);
mountableServer.Mount("/api/Storage/",new ApiStorage(baseCtl));
InnerServer=mountableServer;
}
///
/// To provide to tesses.webserver
///
public IServer InnerServer {get; private set;}
///
/// Set by Nuget Package Tesses.YouTubeDownloader.ExtensionLoader
///
public ChangeableServer ExtensionsServer {get; private set;}
///
/// An optional static website (recomendeded)
///
public ChangeableServer RootServer {get;private set;}
}
}