Search code examples
audioyoutubeffmpegyoutube-dl

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.


Solution

  • 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