fix things
This commit is contained in:
		
							parent
							
								
									a6537ca17d
								
							
						
					
					
						commit
						a1f3092159
					
				
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										70
									
								
								Program.cs
								
								
								
								
							
							
						
						
									
										70
									
								
								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"]);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
		Reference in New Issue