How to extract download URLs of any Youtube Video in C#

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)
Loading...
December 21, 2017

If you are wondering how most of the Youtube Video Downloader websites help you download any Youtube video, then wonder no more. The elusive download link for any Youtube video is hidden right in the HTML of the video page itself. You can grab download URLs for any Youtube video in multiple resolutions and use a download manager to download them, or just play them directly in the browser. Here’s how you can go about grabbing those download links along with the video quality information using c#.

First of all, simply open any Youtube video and go to its HTML source(Ctrl+U) and search for “url=”. The part after url= is the direct URL to the video file(for a certain resolution), ending at the string “tags=\\u0026”. You will find multiple “url=” matches, all of which point to a video file for the same video, at different resolutions. So, we are just going to grab the part after “url=” here and clean up some unnecessary bits so that we finally have our direct link to the video file. There are already some Nuget packages that allow you to grab these links but if you want a lightweight solution without using any external libraries, you can follow along. The idea is really simple – we just find the matches for url= and try to parse the actual URl using regex.

The Extractor Method takes Youtube video URL as the parameter and returns a List<string> with the video link as the first element and the quality as the second, you can also return it as an array for a slightly better performance.

 

You may also like...