9

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.

MR-4O4
  • 311
  • 1
  • 2
  • 11

1 Answers1

14

Use youtube-dl to get the list of formats available for a video

e.g.

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

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

youtube-dl --get-url -f 140 https://www.youtube.com/watch?v=abcdefghijk
Gyan
  • 85,394
  • 9
  • 169
  • 201
  • Thanks for the answer, when I tried this, I got url like "https://r6---sn-gwpa-5bge.googlevideo.com/videoplay......." but in example sites, the link is like "https://redirector.googlevideo.com/videoplay......" for same video. Also, when I try to open the 1st link in browser, it shows a bank page but the 2nd link (https://redirector.googlevideo.com/videoplay....) works fine and starts playing audio in the browser. Can you explain how that's happening? – MR-4O4 Jan 19 '17 at 18:16
  • The link from youtube-dl works here in browser (Firefox 47). – Gyan Jan 19 '17 at 18:47
  • @kamronshaw i own one of the sites the link isnt generated through youtube-dl buddy – Sumit May 04 '17 at 23:20
  • The available formats (with codes) can also be obtained directly from the Youtube website, right-click on the video and pick "Stats for Nerds" – pgr Mar 20 '22 at 12:11
  • A list of format codes and their meaning is available here: https://gist.github.com/AgentOak/34d47c65b1d28829bb17c24c04a0096f – pgr Mar 20 '22 at 12:12