15

This url returns a huge html page which is for watching the video.

http://www.youtube.com/watch?v=some_id

I can't go through all the HTML tags and get the right url to the actual video. I believe there is a url from where the actual video stream is coming. I expect it to be something like,

http://www.youtube.com/get_the_video?id=some_id
Or,
http://www.youtube.com/get_the_video/some_id.mp4

I can't find any information about the correct url for the video.

Is this how YouTube maintain it's video link or their is something else?

Do they always change the url?

I want to do something like this in HTML to play the video.

<video width="320" height="240" controls autoplay>
        <source src="http://www.youtube.com/get_the_video?id=some_id" type="video/mp4">
</video>

(I am new to how YouTube works. Need some guidance)

Mawia
  • 4,220
  • 13
  • 40
  • 55

1 Answers1

18

You can use youtube-dl to download or get the stream url from YouTube.

to download a video,

youtube-dl http://www.youtube.com/watch?v=some_id

or

youtube-dl some_id

to get the stream url, do

youtube-dl -g http://www.youtube.com/watch?v=some_id

Basically the url is parsed from the html source code of the original page.

Jun
  • 2,339
  • 1
  • 20
  • 26
  • the recommendation is awesome. However, the `-g` flag doesn't work for me. Any clues? Thanks! – Brian Jan 19 '15 at 16:06
  • It's working for me. Try installing the latest version from [here](http://rg3.github.io/youtube-dl/download.html) Checkout the [documentation](https://github.com/rg3/youtube-dl/blob/master/README.md#verbosity--simulation-options) too. Regards – Jun Mar 13 '15 at 06:36
  • @Junaid stream url would keep on changing I guess for security reasons ? – Vihaan Verma Oct 28 '16 at 19:46
  • 1
    still cant get at youtube video file link. even though they dont own the content? – filthy_wizard Mar 15 '18 at 18:51
  • Works flawlessly even in 2022. to the wonderful team that keeps `youtube-dl` up to date! – Gwyneth Llewelyn Sep 26 '22 at 19:55