How to get youtube channel video list?
- paksoft2009
- 2018-03-01 18:19:37
- 2,128
In this tutorial How to get youtube channel video list, we will use C# to get list of all the videos uploaded on a youtube channel. This comes handy when we need to audit our youtube channel or doing some research, or anything sneaky. :)
To make sure we aren't re-inventing the wheel here, we will use opensource downloader utilities like youtube-dl and NewtonSoft.Json for this purpose. So go ahead and install NewtonSoft.Json using nugget and download youtube-dl's binary.
Follow these steps to create a new project in Visula Studio
Create new project and select Console Apllication
Install NewtonSoft.Json using nugget manager.
Download youtube-dl and place it in debug folder.
Now create these two classes
public class Entry{ public string title { get; set; } public string id { get; set; } public string ie_key { get; set; } public string _type { get; set; } public string url { get; set; } }
public class RootObject{ public string extractor_key { get; set; } public string extractor { get; set; } public string webpage_url_basename { get; set; } public string title { get; set; } public List
entries { get; set; } public string webpage_url { get; set; } public string _type { get; set; } public string id { get; set; } } In main class Program.cs, place this code as is, you can change anything you like.
public static void Main(string[] args) { string exePath = Environment.GetCommandLineArgs()[0]; string appPath = exePath.Replace("ConsoleApplication1.exe", ""); string youtubedl = ""; youtubedl = appPath + "youtube-dl.exe"; string log = appPath + "log.txt"; string youtubeUrl = ""; //We will create a bat file to send channel link to exe as argument so we dont have to compile our program again for another channel url. if (args.Length > 0) { youtubeUrl = args[0]; //string youtubeUrl = "https://www.youtube.com/channel/UCuReY4zNcUkX0T879HlGosg"; Console.WriteLine("Channel Url: "+youtubeUrl); Console.WriteLine("Process Started"); try { string youtubedlSource = ""; var startinfo = new ProcessStartInfo(youtubedl) { CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, Arguments = string.Format(" --flat-playlist --get-title --dump-single-json \"{0}\"", youtubeUrl) }; Process process = new Process { StartInfo = startinfo }; process.Start(); var reader = process.StandardOutput; youtubedlSource = process.StandardOutput.ReadToEnd(); process.WaitForExit(); if (youtubedlSource != null) { string json = youtubedlSource.Trim(); RootObject m = JsonConvert.DeserializeObject
(json); foreach (var item in m.entries) { string line = "https://youtube.com/watch?v="+item.url + "," + item.title.Replace(","," "); Console.WriteLine(item.url + ":" + item.title); using (var sw = new StreamWriter(log, true)) { sw.Write(line+Environment.NewLine); } } } } catch { //Catch exceptions here } Console.WriteLine("Process Finished"); Console.ReadLine(); } } Now build the project. It will create an exe in debug folder.
Now create a run.bat file in same debug folder with following content.
ConsoleApplication1.exe "YOUR YOUTUBE CHANNEL LINK HERE"
Save and run this run.bat, it will create a log.txt containing all the youtube video links in that channel.