tytd/Tesses.YouTubeDownloader.Ex.../Tesses.YouTubeDownloader.Ot.../JavaScript/tytd-jquery.js

203 lines
5.1 KiB
JavaScript
Raw Normal View History

2022-05-10 13:57:58 +00:00
class TYTD
{
constructor(server,defaultres)
{
this.server=server;
this.defaultres=defaultres;
}
get defaultRes()
{
return this.defaultres;
}
set defaultRes(value)
{
this.defaultres=value;
}
get serverUrl()
{
return this.server;
}
downloadItem(url,res)
{
var callurl=new URL(`api/AddItemRes/${res}/${url}`,this.server).href;
2022-05-14 01:49:10 +00:00
$.ajax(callurl,function(e){});
2022-05-10 13:57:58 +00:00
}
downloadItem(url)
{
this.downloadItem(url,this.defaultres);
}
progress(p)
{
var callurl=new URL("api/v2/Progress",this.server).href;
2022-05-14 01:49:10 +00:00
$.ajax(callurl,function(e){
2022-05-10 13:57:58 +00:00
p(JSON.parse(e));
});
}
queuelist(ql)
{
var callurl=new URL("api/v2/QueueList",this.server).href;
2022-05-14 01:49:10 +00:00
$.ajax(callurl,function(e){
2022-05-10 13:57:58 +00:00
ql(JSON.parse(e));
});
}
getvideos(vid)
{
this.getvideoinfofiles(function(e){
//an array
e.forEach(element => {
this.getvideoinfofile(element,vid);
});
});
}
getplaylists(pl)
{
this.getplaylistinfofiles(function(e){
//an array
e.forEach(element => {
this.getplaylistinfofile(element,pl);
});
});
}
getchannels(chan)
{
this.getchannelinfofiles(function(e){
e.forEach(element =>{
this.getchannelinfofile(element,chan);
});
});
}
getchannelinfo(id,info)
{
this.getchannelinfofile(`${id}.json`,info);
}
getvideoinfo(id,info)
{
this.getvideoinfofile(`${id}.json`,info);
}
getvideoinfofile(filename,info)
{
var callurl=new URL(`api/Storage/File/Info/${filename}`,this.server).href;
2022-05-14 01:49:10 +00:00
$.ajax(callurl,function(e){
2022-05-10 13:57:58 +00:00
info(JSON.parse(e));
});
}
getchannelinfofile(filename,info)
{
var callurl=new URL(`api/Storage/File/Channel/${filename}`,this.server).href;
2022-05-14 01:49:10 +00:00
$.ajax(callurl,function(e){
2022-05-10 13:57:58 +00:00
info(JSON.parse(e));
});
}
getvideoinfofiles(vid)
{
var callurl=new URL("api/Storage/GetFiles/Info",this.server).href;
2022-05-14 01:49:10 +00:00
$.ajax(callurl,function(e){
2022-05-10 13:57:58 +00:00
vid(JSON.parse(e));
});
}
getplaylistinfo(info)
{
this.getplaylistinfofile(`${id}.json`,info);
}
getplaylistinfofile(info)
{
var callurl=new URL(`api/Storage/File/Playlist/${filename}`,this.server).href;
2022-05-14 01:49:10 +00:00
$.ajax(callurl,function(e){
2022-05-10 13:57:58 +00:00
info(JSON.parse(e));
});
}
getplaylistinfofiles(pl)
{
var callurl = new URL("api/Storage/GetFiles/Playlist",this.server).href;
2022-05-14 01:49:10 +00:00
$.ajax(callurl,function(e){
2022-05-10 13:57:58 +00:00
pl(JSON.parse(e));
});
}
getchannelinfofiles(chan)
{
var callurl = new URL("api/Storage/GetFiles/Channel",this.server).href;
2022-05-14 01:49:10 +00:00
$.ajax(callurl,function(e){
2022-05-10 13:57:58 +00:00
chan(JSON.parse(e));
});
}
getsubscriptions(subs)
{
var callurl = new URL("api/v2/subscriptions",this.server).href;
2022-05-14 01:49:10 +00:00
$.ajax(callurl,function(e){
2022-05-10 13:57:58 +00:00
subs(JSON.parse(e));
});
}
subscribe(cid,getinfo,conf)
{
var ginfo = getinfo == true ? "true" : "false";
var callurl = new URL(`api/v2/subscribe?id=${encodeURIComponent(cid)}&conf=${conf}&getinfo=${getinfo}`,this.server).href;
2022-05-14 01:49:10 +00:00
$.ajax(callurl,function(e){
2022-05-10 13:57:58 +00:00
});
}
subscribe(name,conf)
{
var callurl = new URL(`api/v2/subscribe?id=${encodeURIComponent(name)}&conf=${conf}`,this.server).href;
2022-05-14 01:49:10 +00:00
$.ajax(callurl,function(e){
2022-05-10 13:57:58 +00:00
});
}
unsubscribe(cid)
{
var callurl = new URL(`api/v2/unsubscribe?id=${encodeURIComponent(cid)}`,this.server).href;
2022-05-14 01:49:10 +00:00
$.ajax(callurl,function(e){
2022-05-10 13:57:58 +00:00
});
}
resubscribe(cid,conf)
{
var callurl = new URL(`api/v2/resubscribe?id=${encodeURIComponent(cid)}&conf=${conf}`,this.server).href;
2022-05-14 01:49:10 +00:00
$.ajax(callurl,function(e){
2022-05-10 13:57:58 +00:00
});
}
getfiles(path,ls)
{
var callurl=new URL(`api/Storage/GetFiles/${path}`,this.server).href;
2022-05-14 01:49:10 +00:00
$.ajax(callurl,function(e){
2022-05-10 13:57:58 +00:00
ls(JSON.parse(e));
});
}
getdirectories(path,ls)
{
var callurl=new URL(`api/Storage/GetDirectories/${path}`,this.server).href;
2022-05-14 01:49:10 +00:00
$.ajax(callurl,function(e){
2022-05-10 13:57:58 +00:00
ls(JSON.parse(e));
});
}
fileexists(path,exists,doesntexist)
{
var callurl=new URL(`api/Storage/FileExists/${path}`,this.server).href;
2022-05-14 01:49:10 +00:00
$.ajax(callurl,function(e){
2022-05-10 13:57:58 +00:00
if(e==="true")
{
exists();
}else{
doesntexist();
}
});
}
directoryexists(path,exists,doesntexist)
{
var callurl=new URL(`api/Storage/DirectoryExists/${path}`,this.server).href;
2022-05-14 01:49:10 +00:00
$.ajax(callurl,function(e){
2022-05-10 13:57:58 +00:00
if(e==="true")
{
exists();
}else{
doesntexist();
}
});
}
}