MR-4O4
MR-4O4

Reputation: 321

Extract just the audio link from a youtube video without converting

I know there are hundreds of sites to convert youtube video to mp3. Most of them do it by first downloading the video and then converting it to mp3(or any other audio format) on their server using youtube-dl, ffmpeg or similar programs.

What I want to know is, is there any way I can just extract the audio link for any youtube video? I don't know if it's possible but I saw a couple of websites doing it .

First Website : Openaisearch.com This website simply gives a download link for the audio(getting it from youtube videos). I searched for a song and saw the download url, it looked something like this :

https://redirector.googlevideo.com/videoplayback?source=youtube&requiressl=yes&clen=3814013&upn=dzwY9aUVYME&lmt=1469875393441562&expire=1484854959&mime=audio%2Fmp4&nh=IgpwcjAxLnNlYTA5Kg01Mi45NS4yMTYuMTAy&itag=140........... 

I believe that this is not done by first downloading and converting the video to audio format(Correct me if I am wrong). Although the file which gets downloaded after using this link is without any extension, but adding ".m4a" at the end of downloaded file does the work.

Second Website : http://keepvid.com/?url=https://www.youtube.com/watch?v=PT2_F-1esPk

Again similar website with similar audio link. You can check by visiting the URL and see link of audio files.

Any idea how these websites get that "googlevideo.com" link? Do they scrap the youtube video links or something?

Thanks.

Upvotes: 10

Views: 22102

Answers (2)

In PyPI there are several versions of youtube-dl, neither of which works anymore:

The solution is to use yt-dlp, which has the same interface as youtube-dl and actually works:

yt-dlp --get-url -f bestaudio https://www.youtube.com/watch?v=jNQXAC9IVRw

Update Jan 2025: Now, Google decided to force us to login, so it won't work anymore wihtout credentials. You must log into YouTube in a browser, export your cookies into a Netscape cookie jar (I use the Cookie Manager extension in Firefox), and pass that to yt-dlp as --cookies cookies.txt.

Upvotes: 0

Gyan
Gyan

Reputation: 93221

Edit: youtube-dl is obsolete now. yt-dlp is mostly a drop-in replacement.

Use yt-dlp to get the list of formats available for a video

e.g.

yt-dlp -F https://www.youtube.com/watch?v=abcdefghijk

Identify the format code for the audio stream you want, say 140. Then run

yt-dlp --get-url -f 140 https://www.youtube.com/watch?v=abcdefghijk

Upvotes: 14

Related Questions