diff --git a/.vs/youtube-downloader/v16/.suo b/.vs/youtube-downloader/v16/.suo index f4f2ed1..10a16bf 100644 Binary files a/.vs/youtube-downloader/v16/.suo and b/.vs/youtube-downloader/v16/.suo differ diff --git a/Program.cs b/Program.cs index 9356b66..41bdbea 100644 --- a/Program.cs +++ b/Program.cs @@ -83,15 +83,59 @@ namespace youtube_downloader rp.AsFile(rq, path); }); - Route.Add("/api/Add/{Id}", (rq, rp, args) => + Route.Add("/api/AddVideo/{Id}", (rq, rp, args) => { - Server.Functions.Downloader.Download(System.Web.HttpUtility.UrlDecode(args["Id"])); + Server.Functions.Downloader.DownloadVideo(System.Web.HttpUtility.UrlDecode(args["Id"])); rp.AsRedirect("/"); }); - Route.Add("/api/AddRes/{R}/{Id}", (rq, rp, args) => + Route.Add("/api/AddVideoRes/{R}/{Id}", (rq, rp, args) => { - Server.Functions.Downloader.Download(System.Web.HttpUtility.UrlDecode(args["Id"]), (Resolution)int.Parse(args["R"])); + Server.Functions.Downloader.DownloadVideo(System.Web.HttpUtility.UrlDecode(args["Id"]), (Resolution)int.Parse(args["R"])); + rp.AsRedirect("/"); + }); + Route.Add("/api/AddPlaylist/{Id}", (rq, rp, args) => + { + Server.Functions.Downloader.DownloadPlaylist(System.Web.HttpUtility.UrlDecode(args["Id"])); + + rp.AsRedirect("/"); + }); + Route.Add("/api/AddPlaylistRes/{R}/{Id}", (rq, rp, args) => + { + Server.Functions.Downloader.DownloadPlaylist(System.Web.HttpUtility.UrlDecode(args["Id"]), (Resolution)int.Parse(args["R"])); + rp.AsRedirect("/"); + }); + Route.Add("/api/AddChannel/{Id}", (rq, rp, args) => + { + Server.Functions.Downloader.DownloadChannel(System.Web.HttpUtility.UrlDecode(args["Id"])); + + rp.AsRedirect("/"); + }); + Route.Add("/api/AddChannelRes/{R}/{Id}", (rq, rp, args) => + { + Server.Functions.Downloader.DownloadChannel(System.Web.HttpUtility.UrlDecode(args["Id"]), (Resolution)int.Parse(args["R"])); + rp.AsRedirect("/"); + }); + Route.Add("/api/AddUser/{Id}", (rq, rp, args) => + { + Server.Functions.Downloader.DownloadUser(System.Web.HttpUtility.UrlDecode(args["Id"])); + + rp.AsRedirect("/"); + }); + Route.Add("/api/AddChannelOnly/{Id}", (rq, rp, args) => + { + Server.Functions.Downloader.DownloadChannelOnly(System.Web.HttpUtility.UrlDecode(args["Id"])); + + rp.AsRedirect("/"); + }); + Route.Add("/api/AddUserOnly/{R}/{Id}", (rq, rp, args) => + { + Server.Functions.Downloader.DownloadUserOnly(System.Web.HttpUtility.UrlDecode(args["Id"])); + rp.AsRedirect("/"); + }); + Route.Add("/api/AddUserRes/{R}/{Id}", (rq, rp, args) => + { + Server.Functions.Downloader.DownloadUser(System.Web.HttpUtility.UrlDecode(args["Id"]), (Resolution)int.Parse(args["R"])); rp.AsRedirect("/"); }); Route.Add("/api/QueueMove/{From}/{To}", (rq, rp, args) => @@ -109,6 +153,24 @@ namespace youtube_downloader string json = JsonConvert.SerializeObject(Server.Functions.Downloader.GetProgress()); rp.AsText(json, "application/json"); }); + Route.Add("/api/Redownload", (rq, rp, args) => + { + foreach (var item in Directory.GetFiles(Server.Functions.Downloader.DL.GetPath(true, "Info"), "*.json")) + { + string id = System.IO.Path.GetFileNameWithoutExtension(item); + Server.Functions.Downloader.DownloadVideo(id, Resolution.NoConvert); + } + rp.AsRedirect("/"); + }); + Route.Add("/api/Redownload/{R}", (rq, rp, args) => + { + foreach (var item in Directory.GetFiles(Server.Functions.Downloader.DL.GetPath(true, "Info"), "*.json")) + { + string id = System.IO.Path.GetFileNameWithoutExtension(item); + Server.Functions.Downloader.DownloadVideo(id, (Resolution)int.Parse(args["R"])); + } + rp.AsRedirect("/"); + }); Route.Add("/{Path}", (rq, rp, args) => { string path = Path.Combine(webSitePath, args["Path"]); diff --git a/Server/Functions/Downloader.cs b/Server/Functions/Downloader.cs index fdf0138..85286ab 100644 --- a/Server/Functions/Downloader.cs +++ b/Server/Functions/Downloader.cs @@ -177,6 +177,33 @@ namespace youtube_downloader.Server.Functions _ = ex; } } + + internal static void DownloadChannelOnly(string id) + { + ChannelId? v = ChannelId.TryParse(id); + if (v.HasValue) + { + InfomationQueueItem item = new InfomationQueueItem(v.Value,Resolution.NoConvert,false); + lock (DL.infoQueue) + { + DL.infoQueue.Insert(0, item); + } + } + } + + internal static void DownloadUserOnly(string id) + { + UserName? v = UserName.TryParse(id); + if (v.HasValue) + { + InfomationQueueItem item = new InfomationQueueItem(v.Value, Resolution.NoConvert, false); + lock (DL.infoQueue) + { + DL.infoQueue.Insert(0, item); + } + } + } + public bool Continue(string v) { if (File.Exists(v)) @@ -396,61 +423,7 @@ namespace youtube_downloader.Server.Functions } } } - public static void Download(string id) - { - Download(id, Resolution.NoConvert); - } - public static void Download(string id,Resolution res) - { - bool hasForwardSlash = false; - if (!string.IsNullOrEmpty(id)) - { - hasForwardSlash = id.Contains("/"); - } - VideoId? vid= VideoId.TryParse(id); - ChannelId? cid = ChannelId.Parse(id); - UserName? uid = UserName.TryParse(id); - PlaylistId? pid = PlaylistId.Parse(id); - if (pid.HasValue && hasForwardSlash) // check for forward slash so we dont get confused - { - //Is Playlist - var v = pid.Value; - InfomationQueueItem item = new InfomationQueueItem(v, res, true); - lock (DL.infoQueue) - { - DL.infoQueue.Insert(0, item); - } - } - - else if (vid.HasValue) //support 11 char id alone so dont check here - { - var v = vid.Value; - InfomationQueueItem item = new InfomationQueueItem(v, res, true); - lock (DL.infoQueue) - { - DL.infoQueue.Insert(0, item); - } - } - else if (cid.HasValue && hasForwardSlash) - { - var v = cid.Value; - InfomationQueueItem item = new InfomationQueueItem(v, res, true); - lock (DL.infoQueue) - { - DL.infoQueue.Insert(0, item); - } - } - else if(uid.HasValue && hasForwardSlash) - { - var v = uid.Value; - InfomationQueueItem item = new InfomationQueueItem(v, res, true); - lock (DL.infoQueue) - { - DL.infoQueue.Insert(0, item); - } - } - } public static void DownloadUser(string name) { DownloadUser(name, Resolution.NoConvert); diff --git a/bin/Debug/youtube-downloader.exe b/bin/Debug/youtube-downloader.exe index 2b1db35..5c09ed9 100644 Binary files a/bin/Debug/youtube-downloader.exe and b/bin/Debug/youtube-downloader.exe differ diff --git a/bin/Debug/youtube-downloader.pdb b/bin/Debug/youtube-downloader.pdb index c1792fc..a50f2fa 100644 Binary files a/bin/Debug/youtube-downloader.pdb and b/bin/Debug/youtube-downloader.pdb differ diff --git a/obj/Debug/youtube-downloader.exe b/obj/Debug/youtube-downloader.exe index 2b1db35..5c09ed9 100644 Binary files a/obj/Debug/youtube-downloader.exe and b/obj/Debug/youtube-downloader.exe differ diff --git a/obj/Debug/youtube-downloader.pdb b/obj/Debug/youtube-downloader.pdb index c1792fc..a50f2fa 100644 Binary files a/obj/Debug/youtube-downloader.pdb and b/obj/Debug/youtube-downloader.pdb differ