How youtube-dl works?

0

How can I get direct youtube video URL? I tried to do this with Chrome Network monitor. I used this video as example: https://www.youtube.com/watch?v=dQw4w9WgXcQ enter image description here With this way i got this URL(It will expire tomorrow):

https://r2---sn-bpb5oxu-vqne.googlevideo.com/videoplayback?expire=1565036255&ei=fzpIXau_FYLwyQXAk7_IAw&ip=213.231.39.107&id=o-AMYUX0_QrQNg9MVm5kZz__GshDwdFlff2L5-DeeZzaoC&itag=248&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C278%2C394%2C395%2C396%2C397%2C398&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-bpb5oxu-vqne%2Csn-3c27sn7k&ms=au%2Crdu&mv=m&mvi=1&pl=18&nh=%2CIgpwcjAxLmticDAxKgkxMjcuMC4wLjE&gcr=ua&initcwndbps=433750&mime=video%2Fwebm&gir=yes&clen=57856215&dur=212.040&lmt=1544415215209302&mt=1565014541&fvip=13&keepalive=yes&beids=9466586&c=web&txp=5535432&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cgcr%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cnh%2Cinitcwndbps&lsig=AHylml4wRAIgZVL3xFoRK47BJCnUf8Ngmdtzb06uxvo7EqoMFrRSua4CIGRoriCRXeEa_ZF2rRZN-KztSbS9l4vzkCQuD1VKpjDr&alr=yes&sig=ALgxI2wwRgIhAOzFGe22cfpqpEjyp_QIW6BacKYIICEqPT98Mj2SPHU8AiEA_leke3wKKgzJZq4tw2D8tlX30NYpFirEnmSnjDLqjLo%3D&cpn=G9F192iSCg-PzEPT&cver=html5

But the problem is that I can get only with built-in network monitor. I want to know how to do this programmatically? So how services and programs like youtube-dl obtain direct video and audio URL/URI? Can I get video URL with audio and video without using ffmpeg to mux it?

Vlad Gavriuk

Posted 2019-08-05T14:39:28.607

Reputation: 126

1The team behind youtube-dl spends a lot of time reverse engineering Youtube and other sites and figuring that out. You won't get a better answer than by looking at the Python code yourself and trying to understand it. – LawrenceC – 2019-08-05T16:20:27.717

@LawrenceC I looked python code of youtube-dl, file youtube.py but it has bad style of python code and very huge. I want to understand basic concept. – Vlad Gavriuk – 2019-08-05T16:22:28.537

Answers

2

The URL you got is a temporary one that only has meaning on your computer. The is no such website as https://r2---sn-bpb5oxu-vqne.googlevideo.com/.

On the other hand, youtube-dl is no longer enough for YouTube videos. YouTube has moved away from direct video play into the streaming of segments. Some videos still use the old system, but many videos are now becoming more of a playlist than one video file.

Usually, the image YouTube shows on the video when you move the cursor over the timeline is that of the segment, as you can see when it doesn't change for a minuscule movement of the cursor.

I already answered a similar question on the post
Trying to download a youtube video, but getting a weird incomprehensible http error, even via tools.

The only solution I found was to use a more recent video downloader than youtube-dl, and the one I recommended was y2mate.com.

harrymc

Posted 2019-08-05T14:39:28.607

Reputation: 306 093

y2mate is worse than youtube-dl. y2mate.com cannot download this video - https://www.youtube.com/watch?v=KHut4-LtmnM but youtube-dl can.

– Vlad Gavriuk – 2019-08-05T16:46:24.127

It think that the conclusion is that YouTube has a long history and various methods of encoding. I do know that when uploading a new video, its conversion is assigned to some internal YouTube video server, but not all such servers run the same software. You might need to use a number of such utilities and website downloaders, because there doesn't seem to be one that works for all cases. – harrymc – 2019-08-05T16:51:07.940

for me, youtube-dl works for all) – Vlad Gavriuk – 2019-08-05T16:53:51.420

1Lucky you, but luck doesn't last forever. To be serious: A direct YouTube URL is no longer possible, except perhaps for videos uploaded years ago. – harrymc – 2019-08-05T16:56:28.223

hey guys, maybe there's a github-issue opened already in youtube-dl repo about these playlist-based videos? – user1623521 – 2020-02-16T08:12:25.477