A
A
Alexander Andropov2020-04-17 12:51:45
YouTube
Alexander Andropov, 2020-04-17 12:51:45

How to get a direct link to a YouTube video?

Good day. Tell me how to get a direct link (or how to send a request via cURL) to a YouTube video.
Now I do this, I get meta information like this https://www.youtube.com/get_video_info?video_id=ay... with the help of

$data = file_get_contents("https://www.youtube.com/get_video_info?video_id=айди_видео");

There I find a link to the video, but for some reason, some video links do not provide, but I get this answer:
{"playabilityStatus":{"status":"UNPLAYABLE","reason":"Это видео недоступно.","errorScreen":{"playerErrorMessageRenderer":{"reason":{"simpleText":"Это видео недоступно."},"proceedButton":{"buttonRenderer":{"style":"STYLE_PRIMARY","size":"SIZE_DEFAULT","isDisabled":false,"text":{"simpleText":"Посмотреть на YouTube"},"trackingParams":"CAQQ8FsiEwjU34jNju_oAhWNdbIKHSxYDQA="}},"thumbnail":{"thumbnails":[{"url":"//s.ytimg.com/yts/img/meh7-vflGevej7.png","width":140,"height":100}]},"icon":{"iconType":"ERROR_OUTLINE"}}},"contextParams":"Q0FFU0FnZ0M="},"videoDetails"

For what reason? The video is available to watch on YouTube. I can not understand.
Please tell me how to get a link via meta or how to contact YouTube in a different way to get a direct link and info about the video. Thank you .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pankov, 2020-04-24
@trapwalker

As you were answered in the comments in a simple way, you will not be able to download a video file from YouTube. YouTube is simply not profitable and it prevents this in every possible way.
There is an arms race going on here: Google comes up with countermeasures, and enthusiasts come up with workarounds.
By asking the question, it was not clear what you really need and what kind of direct link to the video you needed to get.
If we are talking about downloading videos from YouTube, then there is a wonderful Python utility youtube-dl .
It is convenient to use it with the help of docker: https://hub.docker.com/r/wernight/youtube-dl
This eliminates problems with updates and dependencies.
I use it to download stuff from youtube for "watch later" before it gets deleted.
On a cheap VDS, a bot is running that listens to YouTube URLs from me, and replies with links to download the file when it uploads it itself. Convenient. I will not share the bot yet.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question