How to get Youtube Video Title from url programatically

How to get Youtube Video Title from url programatically

Some people have asked me for a code snippet to get Youtube Video Title from Url. Here is how you can fetch youtube video title from url programatically using C#:

_public static string GetTitle(string url) { 
    var api = $"http://youtube.com/get_video_info?video_id={GetArgs(url, "v", '?')}"; 
    return GetArgs(new WebClient().DownloadString(api), "title", '&'); 
} 
private static string GetArgs(string args, string key, char query) { 
         var iqs = args.IndexOf(query); 
    return iqs == -1 ? string.Empty : HttpUtility.ParseQueryString(iqs < args.Length - 1 ? args.Substring(iqs + 1) : string.Empty)[key];
 }

From these two functions you would get video information and title information for a youtube url. Once you get these information, you would have to do this:

public static void Main()
{
    var url = "[https://www.youtube.com/watch?v=nPXfsewcPO8](https://www.youtube.com/watch?v=nPXfsewcPO8)";
    string name = GetTitle(url);
    Console.WriteLine(name);
}</span>

The post Get YouTube Video Title from Url programmatically first appeared on Ravindra Naik.

No Comments Yet