How to extract Youtube direct links. | |
It works today, but may be broken tomorrow, there is no official API, | |
links are hidden inside JS structures. It should be the reason why it is | |
difficult to find any details on how to do that. | |
Few online resources exist for the same. All have there own specifics, | |
that is why I have found reasonable to get it in one more way. | |
Youtube video pages contain a few <script> blocks. In one of them a specially | |
crafted structure can be found that has an entry «url_encoded_fmt_stream_map». | |
Decoding the value of this entry gives a list of direct URLs associated with | |
the video page. | |
Here is a utility to extract the list of direct video links, that works like th… | |
$ parse-youtube 'https://www.youtube.com/watch?v=YE7VzlLtp-4' | |
type: video/mp4;+codecs="avc1.64001F,+mp4a.40.2" | |
qlty: hd720 | |
url: http://r1---sn-1uxaxjvh-axqe.googlevideo.com/videoplayback?itag=22&mm=31&… | |
type: video/webm;+codecs="vp8.0,+vorbis" | |
qlty: medium | |
url: http://r1---sn-1uxaxjvh-axqe.googlevideo.com/videoplayback?itag=43&mm=31&… | |
Note that the page given with HTTPS, but the output links are HTTP. | |
Both HTTP and HTTPS work, «hd720» URL for example: | |
$ curl -sLI 'https://r1---sn-1uxaxjvh-axqe.googlevideo.com/videoplayback?itag=2… | |
HTTP/1.1 200 OK | |
Content streamed in RTMPE is not eligible for direct downloading. | |
The utility: | |
HTML | |
Plain-text | |