add personalplaylists
This commit is contained in:
parent
c3dadd065a
commit
1472ad5d57
|
@ -1,19 +1,21 @@
|
|||
<Properties StartupConfiguration="{E26F8159-6B4B-4660-A7A4-D0333DFEF0DD}|Default" NuGet.AddPackagesDialog.IncludePrerelease="True">
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="Program.cs">
|
||||
<Files>
|
||||
<File FileName="TYTD.Api/Server/Models/InfoType.cs" Line="20" Column="16" />
|
||||
<File FileName="TYTD.Api/Server/Models/InfoType.cs" Line="140" Column="59" />
|
||||
<File FileName="TYTD.Api/Server/Functions/Downloader.cs" Line="18" Column="1" />
|
||||
<File FileName="TYTD.Api/Server/Models/SavedMedia.cs" Line="1" Column="1" />
|
||||
<File FileName="TYTD.Api/Server/Models/SavedVideo.cs" Line="8" Column="1" />
|
||||
<File FileName="TYTD.Api/Server/Models/InfomationQueueItem.cs" Line="125" Column="50" />
|
||||
<File FileName="TYTD.Api/Server/Functions/ffmpeg.cs" Line="5" Column="15" />
|
||||
<File FileName="Program.cs" Line="539" Column="59" />
|
||||
<File FileName="Program.cs" Line="676" Column="30" />
|
||||
<File FileName="TYTD.Api/MyClass.cs" Line="80" Column="14" />
|
||||
<File FileName="TYTD.Api/Server/Models/SavedChannel.cs" Line="6" Column="10" />
|
||||
<File FileName="TYTD.Api/Server/Models/SavedPlaylist.cs" Line="7" Column="1" />
|
||||
<File FileName="TYTD.Api/Server/Models/VideoDownloadProgress.cs" Line="7" Column="16" />
|
||||
<File FileName="TYTD.Api/Server/Models/VideoDownloadProgress.cs" Line="13" Column="5" />
|
||||
<File FileName="youtube-downloader.csproj" Line="1" Column="1" />
|
||||
<File FileName="../../../usr/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets" Line="2101" Column="5" />
|
||||
<File FileName="TYTD.Api/Server/Models/IEnumerator.cs" Line="1" Column="1" />
|
||||
<File FileName="packages.config" Line="1" Column="1" />
|
||||
</Files>
|
||||
<Pads>
|
||||
<Pad Id="ProjectPad">
|
||||
|
|
339
Program.cs
339
Program.cs
|
@ -17,12 +17,23 @@ using TYTD.Server.Functions;
|
|||
using YoutubeExplode.Videos;
|
||||
using YoutubeExplode;
|
||||
using YoutubeExplode.Videos.Streams;
|
||||
|
||||
using PlaylistsNET;
|
||||
using PlaylistsNET.Content;
|
||||
using PlaylistsNET.Models;
|
||||
using PlaylistsNET.Utils;
|
||||
namespace TYTD
|
||||
{
|
||||
|
||||
class Program
|
||||
static class Program
|
||||
{
|
||||
public static void RemoveRange<T>(this List<T> list,IEnumerable<T> items)
|
||||
{
|
||||
foreach(var item in items)
|
||||
{
|
||||
list.Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
static string webSitePath;
|
||||
static void Main(string[] arg)
|
||||
{
|
||||
|
@ -65,7 +76,9 @@ namespace TYTD
|
|||
Route.Add("/api/AddPlaylistOnly/{Id}", (HttpAction)AddPlaylistOnly);
|
||||
Route.Add("/api/AddPlaylist/{Id}", (HttpAction)AddPlaylist);
|
||||
Route.Add("/api/AddPlaylistRes/{R}/{Id}", (HttpAction)AddPlaylistRes);
|
||||
|
||||
Route.Add("/api/PersonalPlaylist/{PlaylistName}",(HttpAction)PersonalPlaylist);
|
||||
Route.Add("/api/CreatePlaylist/{Ids}/playlist.{extension}", (HttpAction)CreatePlaylist);
|
||||
Route.Add("/api/CreatePlaylistRes/{Ids}/playlist.{extension}", (HttpAction)CreatePlaylistRes);
|
||||
/* Search */
|
||||
Route.Add("/api/SearchOnly/{text}", (HttpAction)SearchOnly);
|
||||
Route.Add("/api/Search/{text}", (HttpAction)Search);
|
||||
|
@ -99,14 +112,14 @@ namespace TYTD
|
|||
Route.Add("/api/upload/", (HttpAction)UploadFiles, "POST");
|
||||
|
||||
Route.Add("/api/endpoint", (HttpAction)Endpoint,"POST");
|
||||
|
||||
|
||||
ApiLoader.Init();
|
||||
/* Other */
|
||||
Route.Add("/", (HttpAction)Index);
|
||||
Route.Add("/extensions.html", (HttpAction)Extensions);
|
||||
Route.Add("/{Path}", (HttpAction)RootPath);
|
||||
Route.Add("/{Path}",(HttpAction)UploadFilePut,"PUT");
|
||||
Console.CancelKeyPress += (sender, e) => { ApiLoader.Dispose();var date = DateTime.Now.ToString("yyyyMMdd_HHmmss");File.WriteAllText(Path.Combine("config","queues-close",$"{date}.json"), Downloader.GetQueue()); return; };
|
||||
Console.CancelKeyPress += (sender, e) => { ApiLoader.Dispose();var date = DateTime.Now.ToString("yyyyMMdd_HHmmss");File.WriteAllText(Path.Combine("config","queues-close",$"{date}.json"), Downloader.GetQueue()); e.Cancel = false; };
|
||||
|
||||
|
||||
Console.WriteLine("Almost Ready To Listen");
|
||||
|
@ -151,13 +164,13 @@ namespace TYTD
|
|||
{
|
||||
Downloader.DownloadItem(System.Web.HttpUtility.UrlDecode(args["Id"]));
|
||||
|
||||
rp.AsRedirect("/");
|
||||
rp.AsText("<script>history.back();</script>");
|
||||
}
|
||||
|
||||
public static void AddItemRes(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
Downloader.DownloadItem(System.Web.HttpUtility.UrlDecode(args["Id"]), (Resolution)int.Parse(args["R"]));
|
||||
rp.AsRedirect("/");
|
||||
rp.AsText("<script>history.back();</script>");
|
||||
}
|
||||
public static void AddFile(HttpListenerRequest request, HttpListenerResponse response, Dictionary<string, string> arguments)
|
||||
{
|
||||
|
@ -172,19 +185,19 @@ namespace TYTD
|
|||
public static void AddVideoInfo(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
Downloader.DownloadVideoInfo(System.Web.HttpUtility.UrlDecode(args["Id"]), Resolution.NoConvert);
|
||||
rp.AsRedirect("/");
|
||||
rp.AsText("<script>history.back();</script>");
|
||||
}
|
||||
public static void AddVideo(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
Downloader.DownloadVideo(System.Web.HttpUtility.UrlDecode(args["Id"]));
|
||||
|
||||
rp.AsRedirect("/");
|
||||
rp.AsText("<script>history.back();</script>");
|
||||
}
|
||||
|
||||
public static void AddVideoRes(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
Downloader.DownloadVideo(System.Web.HttpUtility.UrlDecode(args["Id"]), (Resolution)int.Parse(args["R"]));
|
||||
rp.AsRedirect("/");
|
||||
rp.AsText("<script>history.back();</script>");
|
||||
}
|
||||
public static void Redownload(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
|
@ -193,7 +206,7 @@ namespace TYTD
|
|||
string id =Path.GetFileNameWithoutExtension(item);
|
||||
Downloader.DownloadVideo(id, Resolution.NoConvert);
|
||||
}
|
||||
rp.AsRedirect("/");
|
||||
rp.AsText("<script>history.back();</script>");
|
||||
}
|
||||
|
||||
public static void RedownloadRes(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
|
@ -203,7 +216,7 @@ namespace TYTD
|
|||
string id = System.IO.Path.GetFileNameWithoutExtension(item);
|
||||
Downloader.DownloadVideo(id, (Resolution)int.Parse(args["R"]));
|
||||
}
|
||||
rp.AsRedirect("/");
|
||||
rp.AsText("<script>history.back();</script>");
|
||||
}
|
||||
public static void Watch(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
|
@ -215,19 +228,146 @@ namespace TYTD
|
|||
public static void AddPlaylistOnly(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
Downloader.DownloadPlaylistOnly(System.Web.HttpUtility.UrlDecode(args["Id"]), Resolution.NoConvert);
|
||||
rp.AsRedirect("/");
|
||||
rp.AsText("<script>history.back();</script>");
|
||||
}
|
||||
public static void AddPlaylist(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
Downloader.DownloadPlaylist(System.Web.HttpUtility.UrlDecode(args["Id"]));
|
||||
|
||||
rp.AsRedirect("/");
|
||||
rp.AsText("<script>history.back();</script>");
|
||||
}
|
||||
public static void AddPlaylistRes(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
Downloader.DownloadPlaylist(System.Web.HttpUtility.UrlDecode(args["Id"]), (Resolution)int.Parse(args["R"]));
|
||||
rp.AsRedirect("/");
|
||||
rp.AsText("<script>history.back();</script>");
|
||||
}
|
||||
public static void PersonalPlaylist(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
string playlistName=System.Web.HttpUtility.UrlDecode(args["PlaylistName"]);
|
||||
string playlistNameWithoutExtension =Path.GetFileNameWithoutExtension(playlistName);
|
||||
string path= Path.Combine("PersonalPlaylist", $"{playlistNameWithoutExtension}.json");
|
||||
string extension = Path.GetExtension(playlistName);
|
||||
List<(string Id, Resolution Resolution)> list = JsonConvert.DeserializeObject<List<(string Id, Resolution Resolution)>>(File.ReadAllText(path));
|
||||
string mimeType;
|
||||
rp.AsText(CreatePlaylistString(rq, list, extension, out mimeType),mimeType);
|
||||
}
|
||||
public static void CreatePlaylist(HttpListenerRequest rq,HttpListenerResponse rp,Dictionary<string,string> args)
|
||||
{
|
||||
// Route.Add("/api/PersonalPlaylist/{PlaylistName}", (HttpAction)PersonalPlaylist);
|
||||
//Route.Add("/api/CreatePlaylist/{Ids}/playlist.{extension}", (HttpAction)CreatePlaylist);
|
||||
//Route.Add("/api/CreatePlaylistRes/{Ids}/playlist.{extension}", (HttpAction)CreatePlaylistRes);
|
||||
|
||||
string[] ids= System.Web.HttpUtility.UrlDecode(args["Ids"]).Split(',');
|
||||
var list = new List<(string Id, Resolution Resolution)>();
|
||||
foreach (var id in ids)
|
||||
{
|
||||
list.Add((id, Resolution.NoConvert));
|
||||
}
|
||||
string mimeType;
|
||||
rp.AsText(CreatePlaylistString(rq, list, args["extension"],out mimeType),mimeType);
|
||||
}
|
||||
public static void CreatePlaylistRes(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
string[] ids = System.Web.HttpUtility.UrlDecode(args["Ids"]).Split(',');
|
||||
var list = new List<(string Id, Resolution Resolution)>();
|
||||
for (int i=0;i<list.Count;i+=2)
|
||||
{
|
||||
string id = ids[i];
|
||||
string res = ids[i + 1];
|
||||
list.Add((id,(Resolution)int.Parse(res)));
|
||||
}
|
||||
string mimeType;
|
||||
rp.AsText(CreatePlaylistString(rq, list, args["extension"], out mimeType),mimeType);
|
||||
}
|
||||
public static string CreatePlaylistString(HttpListenerRequest req, List<(string Id, Resolution Resolution)> videoIds, string ext,out string mimeType)
|
||||
{
|
||||
string[] _res = { "Converted", "NotConverted", "Audio" };
|
||||
string UrlBegin = GetServerRoot(req);
|
||||
string ext2 = ext.TrimStart('.');
|
||||
if (ext2 == "m3u" || ext2 == "m3u8")
|
||||
{
|
||||
M3uPlaylist playlist = new M3uPlaylist();
|
||||
playlist.IsExtended = true;
|
||||
|
||||
foreach (var item in videoIds)
|
||||
{
|
||||
|
||||
M3uPlaylistEntry entry = new M3uPlaylistEntry();
|
||||
entry.Path = UrlBegin.TrimEnd('/') + $"/api/Storage/File/{_res[(int)item.Resolution]}/{item.Id}.mp4";
|
||||
var video = JsonConvert.DeserializeObject<SavedVideo>(File.ReadAllText(Path.Combine("Info", $"{item.Id}.json")));
|
||||
entry.Title = video.Title;
|
||||
entry.AlbumArtist = video.AuthorTitle;
|
||||
entry.Duration = TimeSpan.FromSeconds(video.Duration);
|
||||
playlist.PlaylistEntries.Add(entry);
|
||||
}
|
||||
|
||||
M3uContent content = new M3uContent();
|
||||
mimeType = "audio/x-mpegurl";
|
||||
return content.ToText(playlist);
|
||||
} else if (ext2 == "wpl")
|
||||
{
|
||||
WplPlaylist playlist = new WplPlaylist();
|
||||
|
||||
|
||||
foreach (var item in videoIds)
|
||||
{
|
||||
|
||||
WplPlaylistEntry entry = new WplPlaylistEntry();
|
||||
entry.Path = UrlBegin.TrimEnd('/') + $"/api/Storage/File/{_res[(int)item.Resolution]}/{item.Id}.mp4";
|
||||
var video = JsonConvert.DeserializeObject<SavedVideo>(File.ReadAllText(Path.Combine("Info", $"{item.Id}.json")));
|
||||
entry.TrackTitle = video.Title;
|
||||
entry.TrackArtist = video.AuthorTitle;
|
||||
entry.Duration = TimeSpan.FromSeconds(video.Duration);
|
||||
playlist.PlaylistEntries.Add(entry);
|
||||
}
|
||||
|
||||
WplContent content = new WplContent();
|
||||
mimeType = "application/vnd.ms-wpl";
|
||||
return content.ToText(playlist);
|
||||
} else if (ext2 == "pls")
|
||||
{
|
||||
PlsPlaylist playlist = new PlsPlaylist();
|
||||
|
||||
int i = 1;
|
||||
foreach (var item in videoIds)
|
||||
{
|
||||
|
||||
PlsPlaylistEntry entry = new PlsPlaylistEntry();
|
||||
entry.Path = UrlBegin.TrimEnd('/') + $"/api/Storage/File/{_res[(int)item.Resolution]}/{item.Id}.mp4";
|
||||
var video = JsonConvert.DeserializeObject<SavedVideo>(File.ReadAllText(Path.Combine("Info", $"{item.Id}.json")));
|
||||
entry.Title = video.Title;
|
||||
entry.Nr = i++;
|
||||
|
||||
playlist.PlaylistEntries.Add(entry);
|
||||
}
|
||||
mimeType = "audio/x-scpls";
|
||||
PlsContent content = new PlsContent();
|
||||
return content.ToText(playlist);
|
||||
} else if (ext2 == "zpl")
|
||||
{
|
||||
ZplPlaylist playlist = new ZplPlaylist();
|
||||
|
||||
|
||||
foreach (var item in videoIds)
|
||||
{
|
||||
|
||||
ZplPlaylistEntry entry = new ZplPlaylistEntry();
|
||||
entry.Path = UrlBegin.TrimEnd('/') + $"/api/Storage/File/{_res[(int)item.Resolution]}/{item.Id}.mp4";
|
||||
var video = JsonConvert.DeserializeObject<SavedVideo>(File.ReadAllText(Path.Combine("Info", $"{item.Id}.json")));
|
||||
entry.TrackTitle = video.Title;
|
||||
entry.TrackArtist = video.AuthorTitle;
|
||||
entry.Duration = TimeSpan.FromSeconds(video.Duration);
|
||||
|
||||
playlist.PlaylistEntries.Add(entry);
|
||||
}
|
||||
mimeType = "application/vnd.ms-zpl";
|
||||
ZplContent content = new ZplContent();
|
||||
return content.ToText(playlist);
|
||||
}
|
||||
mimeType = "text/plain";
|
||||
return "Invalid";
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region Search
|
||||
public static void SearchOnly(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
|
@ -250,36 +390,36 @@ namespace TYTD
|
|||
{
|
||||
Downloader.DownloadChannelOnly(System.Web.HttpUtility.UrlDecode(args["Id"]));
|
||||
|
||||
rp.AsRedirect("/");
|
||||
rp.AsText("<script>history.back();</script>");
|
||||
}
|
||||
public static void AddChannel(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
Downloader.DownloadChannel(System.Web.HttpUtility.UrlDecode(args["Id"]));
|
||||
|
||||
rp.AsRedirect("/");
|
||||
rp.AsText("<script>history.back();</script>");
|
||||
}
|
||||
public static void AddChannelRes(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
Downloader.DownloadChannel(System.Web.HttpUtility.UrlDecode(args["Id"]), (Resolution)int.Parse(args["R"]));
|
||||
rp.AsRedirect("/");
|
||||
rp.AsText("<script>history.back();</script>");
|
||||
}
|
||||
#endregion
|
||||
#region User
|
||||
public static void AddUserOnly(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
Downloader.DownloadUserOnly(System.Web.HttpUtility.UrlDecode(args["Id"]));
|
||||
rp.AsRedirect("/");
|
||||
rp.AsText("<script>history.back();</script>");
|
||||
}
|
||||
public static void AddUser(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
Downloader.DownloadUser(System.Web.HttpUtility.UrlDecode(args["Id"]));
|
||||
|
||||
rp.AsRedirect("/");
|
||||
rp.AsText("<script>history.back();</script>");
|
||||
}
|
||||
public static void AddUserRes(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
Downloader.DownloadUser(System.Web.HttpUtility.UrlDecode(args["Id"]), (Resolution)int.Parse(args["R"]));
|
||||
rp.AsRedirect("/");
|
||||
rp.AsText("<script>history.back();</script>");
|
||||
}
|
||||
#endregion
|
||||
#region Queue And Progress
|
||||
|
@ -291,7 +431,7 @@ namespace TYTD
|
|||
public static void QueueMove(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
Downloader.ModQueue(args["To"], args["From"]);
|
||||
rp.AsRedirect("/");
|
||||
rp.AsText("<script>history.back();</script>");
|
||||
}
|
||||
public static void QueueMove2(HttpListenerRequest request, HttpListenerResponse response, Dictionary<string, string> arguments)
|
||||
{
|
||||
|
@ -326,7 +466,7 @@ namespace TYTD
|
|||
#region Storage
|
||||
public static void StorageGetDirectories(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
string path = Downloader.DL.GetPath(true, args["Path"]);
|
||||
string path = Downloader.DL.GetPath(true, System.Web.HttpUtility.UrlDecode(args["Path"]));
|
||||
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
|
@ -340,7 +480,7 @@ namespace TYTD
|
|||
}
|
||||
public static void StorageGetFiles(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
string path = Downloader.DL.GetPath(true, args["Path"]);
|
||||
string path = Downloader.DL.GetPath(true, System.Web.HttpUtility.UrlDecode(args["Path"]));
|
||||
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
|
@ -354,14 +494,14 @@ namespace TYTD
|
|||
}
|
||||
public static void StorageDirectoryExists(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
string path = Downloader.DL.GetPath(true, args["Path"]);
|
||||
string path = Downloader.DL.GetPath(true, System.Web.HttpUtility.UrlDecode(args["Path"]));
|
||||
string json = Directory.Exists(path) ? "true" : "false";
|
||||
rp.AsText(json, "text/plain");
|
||||
|
||||
}
|
||||
public static void StorageFileExists(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
string path = Downloader.DL.GetPath(true, args["Path"]);
|
||||
string path = Downloader.DL.GetPath(true, System.Web.HttpUtility.UrlDecode(args["Path"]));
|
||||
string json = File.Exists(path) ? "true" : "false";
|
||||
rp.AsText(json, "text/plain");
|
||||
|
||||
|
@ -374,7 +514,7 @@ namespace TYTD
|
|||
}
|
||||
else
|
||||
{
|
||||
string path = Downloader.DL.GetPath(true, args["Path"]);
|
||||
string path = Downloader.DL.GetPath(true, System.Web.HttpUtility.UrlDecode(args["Path"]));
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
string indexHtml = Path.Combine(path, "index.html");
|
||||
|
@ -421,7 +561,7 @@ namespace TYTD
|
|||
}
|
||||
public static void Video(HttpListenerRequest rq,HttpListenerResponse rp,Dictionary<string,string> args)
|
||||
{
|
||||
YoutubeExplode.Videos.VideoId? vid = YoutubeExplode.Videos.VideoId.TryParse(args["Id"]);
|
||||
VideoId? vid = VideoId.TryParse(System.Web.HttpUtility.UrlDecode(args["Id"]));
|
||||
if (vid.HasValue)
|
||||
{
|
||||
string path = Downloader.DL.GetPath(true, "NotConverted",vid.Value +".mp4");
|
||||
|
@ -436,7 +576,7 @@ namespace TYTD
|
|||
}
|
||||
public static void VideoRes(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
VideoId? vid = VideoId.TryParse(args["Id"]);
|
||||
VideoId? vid = VideoId.TryParse(System.Web.HttpUtility.UrlDecode(args["Id"]));
|
||||
if (vid.HasValue)
|
||||
{
|
||||
int res;
|
||||
|
@ -519,7 +659,7 @@ namespace TYTD
|
|||
}
|
||||
private static void UploadFilePut(HttpListenerRequest request, HttpListenerResponse response, Dictionary<string, string> arguments)
|
||||
{
|
||||
string p = arguments["Path"].Split(new char[] { '?' }, StringSplitOptions.RemoveEmptyEntries)[0];
|
||||
string p = System.Web.HttpUtility.UrlDecode(arguments["Path"]).Split(new char[] { '?' }, StringSplitOptions.RemoveEmptyEntries)[0];
|
||||
string path = Path.Combine(webSitePath, p);
|
||||
bool exists = File.Exists(path);
|
||||
using (var instr = request.InputStream)
|
||||
|
@ -541,13 +681,132 @@ namespace TYTD
|
|||
|
||||
private static void Endpoint(HttpListenerRequest request, HttpListenerResponse response, Dictionary<string, string> arguments)
|
||||
{
|
||||
//MultiDictionary<string, string> multi = new MultiDictionary<string, string>();
|
||||
request.ParseBody(arguments);
|
||||
List<string> print = new List<string>();
|
||||
bool hasOtherResponse=false;
|
||||
bool success = true;
|
||||
if(arguments.ContainsKey("operation"))
|
||||
{
|
||||
if (arguments["operation"] == "server_download")
|
||||
if (arguments["operation"] == "create_personal_playlist")
|
||||
{
|
||||
string myName = arguments["name"];
|
||||
string path = Downloader.DL.GetPath(true, "PersonalPlaylist", $"{myName}.json");
|
||||
|
||||
string[] ids = System.Web.HttpUtility.UrlDecode(arguments["ids"]).Split(',');
|
||||
var list = new List<(string Id, Resolution Resolution)>();
|
||||
list.AddRange(ids.Select(e => (e, Resolution.NoConvert)));
|
||||
|
||||
File.WriteAllText(path, JsonConvert.SerializeObject(list));
|
||||
}
|
||||
else if (arguments["operation"] == "create_personal_playlist_res")
|
||||
{
|
||||
string myName = arguments["name"];
|
||||
string path = Downloader.DL.GetPath(true, "PersonalPlaylist", $"{myName}.json");
|
||||
|
||||
string[] ids = System.Web.HttpUtility.UrlDecode(arguments["ids"]).Split(',');
|
||||
var list = new List<(string Id, Resolution Resolution)>();
|
||||
|
||||
for (int i = 0; i < list.Count; i += 2)
|
||||
{
|
||||
string id = ids[i];
|
||||
string res = ids[i + 1];
|
||||
list.Add((id, (Resolution)int.Parse(res)));
|
||||
}
|
||||
|
||||
File.WriteAllText(path, JsonConvert.SerializeObject(list));
|
||||
|
||||
}
|
||||
else if (arguments["operation"] == "add_to_personal_playlist")
|
||||
{
|
||||
string myName = arguments["name"];
|
||||
string path = Downloader.DL.GetPath(true, "PersonalPlaylist", $"{myName}.json");
|
||||
|
||||
string[] ids = System.Web.HttpUtility.UrlDecode(arguments["ids"]).Split(',');
|
||||
var list = JsonConvert.DeserializeObject<List<(string Id, Resolution Resolution)>>(File.ReadAllText(path));
|
||||
|
||||
|
||||
list.AddRange(ids.Select(e => (e, Resolution.NoConvert)));
|
||||
File.WriteAllText(path, JsonConvert.SerializeObject(list));
|
||||
}
|
||||
else if (arguments["operation"] == "add_to_personal_playlist_res")
|
||||
{
|
||||
string myName = arguments["name"];
|
||||
string path = Downloader.DL.GetPath(true, "PersonalPlaylist", $"{myName}.json");
|
||||
|
||||
string[] ids = System.Web.HttpUtility.UrlDecode(arguments["ids"]).Split(',');
|
||||
var list = JsonConvert.DeserializeObject<List<(string Id, Resolution Resolution)>>(File.ReadAllText(path));
|
||||
|
||||
for (int i = 0; i < list.Count; i += 2)
|
||||
{
|
||||
string id = ids[i];
|
||||
string res = ids[i + 1];
|
||||
list.Add((id, (Resolution)int.Parse(res)));
|
||||
}
|
||||
|
||||
File.WriteAllText(path, JsonConvert.SerializeObject(list));
|
||||
}
|
||||
else if (arguments["operation"] == "insert_to_personal_playlist")
|
||||
{
|
||||
string myName = arguments["name"];
|
||||
string path = Downloader.DL.GetPath(true, "PersonalPlaylist", $"{myName}.json");
|
||||
|
||||
string[] ids = System.Web.HttpUtility.UrlDecode(arguments["ids"]).Split(',');
|
||||
var list = JsonConvert.DeserializeObject<List<(string Id, Resolution Resolution)>>(File.ReadAllText(path));
|
||||
int offset = 0;
|
||||
if (arguments.ContainsKey("offset"))
|
||||
{
|
||||
if (!int.TryParse(arguments["offset"], out offset))
|
||||
{
|
||||
offset = 0;
|
||||
}
|
||||
}
|
||||
list.InsertRange(offset, ids.Select(e => (e, Resolution.NoConvert)));
|
||||
File.WriteAllText(path, JsonConvert.SerializeObject(list));
|
||||
}
|
||||
else if (arguments["operation"] == "remove_from_personal_playlist")
|
||||
{
|
||||
string myName = arguments["name"];
|
||||
string path = Downloader.DL.GetPath(true, "PersonalPlaylist", $"{myName}.json");
|
||||
|
||||
string[] ids = System.Web.HttpUtility.UrlDecode(arguments["ids"]).Split(',');
|
||||
var list = JsonConvert.DeserializeObject<List<(string Id, Resolution Resolution)>>(File.ReadAllText(path));
|
||||
List<(string, Resolution)> todel = new List<(string, Resolution)>();
|
||||
foreach(var item in list)
|
||||
{
|
||||
if(ids.Contains(item.Id))
|
||||
{
|
||||
todel.Add(item);
|
||||
}
|
||||
}
|
||||
list.RemoveRange(todel);
|
||||
File.WriteAllText(path, JsonConvert.SerializeObject(list));
|
||||
}
|
||||
else if (arguments["operation"] == "insert_to_personal_playlist_res")
|
||||
{
|
||||
string myName = arguments["name"];
|
||||
string path = Downloader.DL.GetPath(true, "PersonalPlaylist", $"{myName}.json");
|
||||
|
||||
string[] ids = System.Web.HttpUtility.UrlDecode(arguments["ids"]).Split(',');
|
||||
var list = JsonConvert.DeserializeObject<List<(string Id, Resolution Resolution)>>(File.ReadAllText(path));
|
||||
int offset = 0;
|
||||
if (arguments.ContainsKey("offset"))
|
||||
{
|
||||
if (!int.TryParse(arguments["offset"], out offset))
|
||||
{
|
||||
offset = 0;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < list.Count; i += 2)
|
||||
{
|
||||
string id = ids[i];
|
||||
string res = ids[i + 1];
|
||||
list.Insert(offset++,(id, (Resolution)int.Parse(res)));
|
||||
}
|
||||
|
||||
File.WriteAllText(path, JsonConvert.SerializeObject(list));
|
||||
}
|
||||
else if (arguments["operation"] == "server_download")
|
||||
{
|
||||
if (arguments.ContainsKey("url"))
|
||||
{
|
||||
|
@ -637,7 +896,7 @@ namespace TYTD
|
|||
hasOtherResponse = true;
|
||||
|
||||
}
|
||||
else if(arguments["operation"] == "queue_move")
|
||||
else if (arguments["operation"] == "queue_move")
|
||||
{
|
||||
bool containsId = arguments.ContainsKey("id");
|
||||
bool containsIndex = arguments.ContainsKey("index");
|
||||
|
@ -651,7 +910,7 @@ namespace TYTD
|
|||
if (arguments.ContainsKey("to"))
|
||||
{
|
||||
string to_loc = arguments["to"];
|
||||
if(containsId)
|
||||
if (containsId)
|
||||
Downloader.ModQueue2(to_loc, arguments["id"]);
|
||||
|
||||
if (containsIndex)
|
||||
|
@ -685,7 +944,7 @@ namespace TYTD
|
|||
}
|
||||
public static void RootPath(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary<string, string> args)
|
||||
{
|
||||
string p = args["Path"].Split(new char[] { '?' }, StringSplitOptions.RemoveEmptyEntries)[0];
|
||||
string p = System.Web.HttpUtility.UrlDecode(args["Path"]).Split(new char[] { '?' }, StringSplitOptions.RemoveEmptyEntries)[0];
|
||||
string path = Path.Combine(webSitePath, p);
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
|
@ -739,6 +998,18 @@ namespace TYTD
|
|||
response.WithCORS();
|
||||
return false;
|
||||
}
|
||||
public static string GetServerRoot(HttpListenerRequest req)
|
||||
{
|
||||
if(req.Headers.AllKeys.Contains("ServerRoot"))
|
||||
{
|
||||
return req.Headers["ServerRoot"];
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"http://{req.LocalEndPoint.ToString()}/";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
namespace TYTD.Server.Models
|
||||
{
|
||||
internal interface IEnumerator<T1, T2>
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,6 +1,10 @@
|
|||
using YoutubeExplode.Channels;
|
||||
using YoutubeExplode.Playlists;
|
||||
using YoutubeExplode.Videos;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace TYTD.Server.Models
|
||||
{
|
||||
|
@ -13,6 +17,129 @@ namespace TYTD.Server.Models
|
|||
ClosedCaptions=4,
|
||||
FileDownload=5
|
||||
}
|
||||
public class MultiDictionary<T1, T2> : IDictionary<T1, T2>
|
||||
{
|
||||
Dictionary<T1, List<T2>> _dict= new Dictionary<T1, List<T2>>();
|
||||
|
||||
public IReadOnlyDictionary<T1, List<T2>> Dictionary { get { return _dict; } }
|
||||
|
||||
public T2 this[T1 key] { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
|
||||
|
||||
public ICollection<T1> Keys => _dict.Keys;
|
||||
|
||||
public ICollection<T2> Values => new Collection<T2>( _dict.Values.Select<List<T2>, T2>(e => e.First()).ToList());
|
||||
|
||||
public int Count => _dict.Count;
|
||||
|
||||
public bool IsReadOnly => false;
|
||||
|
||||
public void Add(T1 key, T2 value)
|
||||
{
|
||||
if(!_dict.ContainsKey(key))
|
||||
{
|
||||
_dict.Add(key, new List<T2>());
|
||||
}
|
||||
_dict[key].Add(value);
|
||||
}
|
||||
|
||||
public void Add(KeyValuePair<T1, T2> item)
|
||||
{
|
||||
Add(item.Key, item.Value);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_dict.Clear();
|
||||
}
|
||||
|
||||
public bool Contains(KeyValuePair<T1, T2> item)
|
||||
{
|
||||
if(_dict.ContainsKey(item.Key))
|
||||
{
|
||||
return _dict[item.Key].Contains(item.Value);
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool ContainsKey(T1 key)
|
||||
{
|
||||
return _dict.ContainsKey(key);
|
||||
}
|
||||
|
||||
public void CopyTo(KeyValuePair<T1, T2>[] array, int arrayIndex)
|
||||
{
|
||||
int i = arrayIndex;
|
||||
foreach(var item in _dict)
|
||||
{
|
||||
var v = new KeyValuePair<T1, T2>(item.Key,item.Value.First());
|
||||
|
||||
array[i++]=v;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<T1, T2>> GetEnumerator()
|
||||
{
|
||||
return new TEnumerator(_dict.GetEnumerator());
|
||||
}
|
||||
private class TEnumerator : IEnumerator<KeyValuePair<T1,T2>>
|
||||
{
|
||||
public TEnumerator(IEnumerator<KeyValuePair<T1,List<T2>>> dict)
|
||||
{
|
||||
_enum = dict;
|
||||
}
|
||||
IEnumerator<KeyValuePair<T1, List<T2>>> _enum;
|
||||
public object Current => new KeyValuePair<T1, T2>(_enum.Current.Key, _enum.Current.Value.First());
|
||||
|
||||
KeyValuePair<T1, T2> IEnumerator<KeyValuePair<T1, T2>>.Current => new KeyValuePair<T1, T2>(_enum.Current.Key, _enum.Current.Value.First());
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_enum.Dispose();
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
return _enum.MoveNext();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_enum.Reset();
|
||||
}
|
||||
}
|
||||
public bool Remove(T1 key)
|
||||
{
|
||||
return _dict.Remove(key);
|
||||
}
|
||||
|
||||
public bool Remove(KeyValuePair<T1, T2> item)
|
||||
{
|
||||
if(_dict.ContainsKey(item.Key))
|
||||
{
|
||||
return _dict[item.Key].Remove(item.Value);
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryGetValue(T1 key, out T2 value)
|
||||
{
|
||||
List<T2> value0;
|
||||
if(_dict.TryGetValue(key,out value0))
|
||||
{
|
||||
value = value0.First();
|
||||
return true;
|
||||
}
|
||||
value = default(T2);
|
||||
return false;
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return new TEnumerator(_dict.GetEnumerator());
|
||||
}
|
||||
}
|
||||
public class IDResolutionTypeTriplet
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
|
|
@ -10,4 +10,5 @@ namespace TYTD.Server.Models
|
|||
public int Progress { get; set; }
|
||||
public double ProgressRaw { get; set; }
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1 +1 @@
|
|||
86258721c083b2dc3445d3e49869600975273fa0
|
||||
3a0ad01444a7c622c3bd15b537d0dc7e888f6685
|
||||
|
|
|
@ -705,3 +705,4 @@
|
|||
/home/mike/tytd-server/obj/x86/Release/youtube-downloader.csproj.CopyComplete
|
||||
/home/mike/tytd-server/obj/x86/Release/youtube-downloader.exe
|
||||
/home/mike/tytd-server/bin/Release/System.Text.Encoding.CodePages.xml
|
||||
/home/mike/tytd-server/bin/Release/PlaylistsNET.dll
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -7,6 +7,7 @@
|
|||
<package id="Microsoft.CSharp" version="4.7.0" targetFramework="net47" />
|
||||
<package id="MimeTypesMap" version="1.0.8" targetFramework="net47" />
|
||||
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net47" />
|
||||
<package id="PlaylistsNET" version="1.1.3" targetFramework="net47" />
|
||||
<package id="SimpleBase" version="1.3.1" targetFramework="net47" />
|
||||
<package id="Simple-HTTP" version="1.0.6" targetFramework="net47" />
|
||||
<package id="System.Buffers" version="4.5.1" targetFramework="net47" />
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -112,6 +112,9 @@
|
|||
<Reference Include="CookiesTxtParser">
|
||||
<HintPath>packages\CookiesTxtParser.1.0.1\lib\netstandard2.0\CookiesTxtParser.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PlaylistsNET">
|
||||
<HintPath>packages\PlaylistsNET.1.1.3\lib\net45\PlaylistsNET.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
|
|
Loading…
Reference in New Issue