There is a very popular open source command-line downloader called youtube-dl. which does exactly that. It grabs the actual video and audio file links from a given YouTube link – or any other popular web video site like Vimeo, Yahoo! Video, uStream, etc.
For HTML5 progressive download video, the actual source file is usually mentioned directly in the source child of the video tag, so if you'd search the page for mp4 or similar. For example on German news show Tagesschau 100. you'll find:
For more advanced playback technologies like MPEG DASH or Apple's HTTP Live Streaming (HLS), you have to parse a meta-information file to get the actual video stream. The meta file ( .mpd for example in DASH, and .m3u8 for HLS) will contain links to segments of video and audio, which you'd later have to combine to
get a playable file.
There's no general solution for this. It requires careful inspection and debugging of the target site.
Start with ytplayer.config.args object. This contains all URLs for the video. It is broken up into
Each of these is a comma separated array of what I would call "stream objects". Each "stream object" will contain values like this
Each URL will be encoded so you will need to decode them. Now the tricky part.
YouTube has at least 4 security levels for their videos
The RTMPE videos are typically used on official full length movies, and are protected with SWF Verification Type 2. This has been around since 2011 and has yet to be reverse engineered.
The type "s" videos are the most difficult that can actually be downloaded. You will typcially see these on VEVO videos and the like. They start with a signature such as
Then the signature is scrambled with a function like this
This function is dynamic, it typically changes every day. To make it more difficult the function is hosted at a URL such as
this introduces the problem of Same-origin policy. Essentially, you cannot download this file from www.youtube.com because they are different domains. A workaround of this problem is CORS. With CORS, s.ytimg.com could add this header
So, now that you have proxied your JS file, and used the function to scramble the signature, you can use that in the querystring to download a video.
Category: Personal Finance