//Checks if a url is a valid youtube one, following discord url parameters //in cases where the id was greater than 11, getting only the 11 characters still lead to the same video nevertheless public static YTUrlValidationResponse TryParseID(string url) { YTUrlValidationResponse result = new YTUrlValidationResponse(); result.Valid = false; result.ID = null; if (url.Length >= 28) { if (url.Substring(0, 17) == "https://youtu.be/") { result.Valid = true; result.ID = url.Substring(17, 11); return(result); } } if (url.Length >= 37) { if (url.Substring(0, 26) == "https://youtube.com/embed/") { result.Valid = true; result.ID = url.Substring(26, 11); return(result); } } if (url.Length >= 39) { if (url.Substring(0, 28) == "https://youtube.com/watch?v=") { result.Valid = true; result.ID = url.Substring(28, 11); return(result); } } if (url.Length >= 41) { if (url.Substring(0, 30) == "https://www.youtube.com/embed/") { result.Valid = true; result.ID = url.Substring(30, 11); return(result); } } if (url.Length >= 43) { if (url.Substring(0, 32) == "https://www.youtube.com/watch?v=") { result.Valid = true; result.ID = url.Substring(32, 11); return(result); } } return(result); }
public static YTUrlValidationResponse TryParsePlaylistID(string playlistUrl) { YTUrlValidationResponse result = new YTUrlValidationResponse(); result.Valid = false; result.ID = null; //Minimum playlist id is 13 if (playlistUrl.Length >= 51) { if (playlistUrl.Substring(0, 38) == "https://www.youtube.com/playlist?list=") { result.Valid = true; result.ID = playlistUrl.Substring(38); } } if (playlistUrl.Length >= 47) { if (playlistUrl.Substring(0, 34) == "https://youtube.com/playlist?list=") { result.Valid = true; result.ID = playlistUrl.Substring(34); } } if (playlistUrl.Length >= 62) { if (playlistUrl.Substring(0, 32) == "https://www.youtube.com/watch?v=") { if (playlistUrl.Substring(43, 6) == "&list=") { result.Valid = true; result.ID = playlistUrl.Substring(49); } } } if (playlistUrl.Length >= 58) { if (playlistUrl.Substring(0, 28) == "https://youtube.com/watch?v=") { if (playlistUrl.Substring(39, 6) == "&list=") { result.Valid = true; result.ID = playlistUrl.Substring(45); } } } if (playlistUrl.Length >= 48) { if (playlistUrl.Substring(0, 17) == "https://youtu.be/") { if (playlistUrl.Substring(28, 1) == "/") { result.Valid = true; result.ID = playlistUrl.Substring(29); } } } return(result); }