75

I've searched for this question several times

Many suggested that 'Get both audio and video. And hide video.' and said that 'there is no audio only API'

But it needs more traffic than when only audio is retrieved if I wanted to listen to music via Youtube.

What makes me confused is, an android app called Firetube provides audio only.

Is this just a trick or does Google provides AUDIO ONLY API?

Jeon
  • 4,000
  • 4
  • 28
  • 73
  • What language are you aiming to do this in? – JustSteveKing Oct 24 '14 at 13:35
  • I am not trying to make something. I am just curious how Firetube do this. Someone said that Firetube can save data traffic. – Jeon Oct 24 '14 at 13:37
  • My guess is they download the whole video as an mp4 then strip out the video component and turn this into either mp3 or mp4a. If it were me doing this I would get the video and do processing on the backend. – JustSteveKing Oct 24 '14 at 13:39
  • YouTube Music (Android App) and Google Home both use audio only streams of YouTube and I don't think they just hacked around it. There must be a private API for this if it isn't a public one. – Elijah Lynn Jun 09 '17 at 20:37
  • 1
    Check my answer here: https://stackoverflow.com/questions/8690255/youtube-audio-only-html5-player/45375023#45375023 – 350D Jul 28 '17 at 13:41
  • No, it it essentially impossible to isolate audio from a YouTube video, due to new web encryption methods and the fact that YouTube keeps changing it – Owen M Sep 19 '17 at 12:03
  • I wouldn't really call this an API, but it's a solution: https://stackoverflow.com/a/60854321/5645656 – Cardinal System Mar 25 '20 at 17:42

8 Answers8

129

YES YOU CAN

Yes, it is certainly possible, here is an API for that:

https://market.mashape.com/ehmo/savedeo

While it is against YouTube Terms of Service, it is technically possible to hack your way to the audio-only download link, and that's how the API's above work.

The is how I imagine the SaveDeo API does its magic: Download ONLY audio from a youtube video

This is what the guy at SaveDeo told me:

Youtube has audio only files. Savedeo doesn't do anything beyond providing you with the link. How we're doing this is the reason why are you using savedeo, isn't it.

etayluz
  • 15,920
  • 23
  • 106
  • 151
  • 10
    To add to these, [youtube-dl](https://github.com/rg3/youtube-dl) is an excellent utility to fetch an audio track. – Niket Pathak Jun 22 '17 at 16:29
  • 11
    How the hell is this not the correct answer? The accepted one is basically wrong and just referring to why you shouldn't do it, while this one is an actual answer to the question... – d0n.key Dec 09 '17 at 15:44
  • 4
    @d0n.key I did not accept this answer cause it is not an API provided by YouTube. – Jeon Dec 25 '18 at 01:08
  • 2
    2020 - URL doesnt work – Aid19801 Dec 09 '20 at 11:44
24

Regarding the Terms of Service of the YouTube API

https://developers.google.com/youtube/terms/developer-policies

YOU CAN'T :

separate, isolate, or modify the audio or video components of any YouTube audiovisual content made available through the YouTube API;

promote separately the audio or video components of any YouTube audiovisual content made available through the YouTube API;

cnu
  • 36,135
  • 23
  • 65
  • 63
mpgn
  • 7,121
  • 9
  • 67
  • 100
  • 3
    Can't find something like that in current terms. Though I'm far far away from all this legal stuff - probably have missed some synonym. – Alexander Malakhov Apr 27 '18 at 10:09
  • 16
    This question is not about if it is against the terms of YouTube or not. this is about if it is possible or not. And the true fact is that it is possible. First, need to extract the video download link with YouTube data API which is possible and then convert it into MP3 audio using an API service. So though, it is against YouTube terms and conditions, but it is technically possible. – Faruque Ahamed Mollick Mar 17 '19 at 18:00
  • 1
    So then how do Facebook and TikTok allow you sample YouTube's music in a story? – K. Russell Smith Jan 24 '22 at 14:17
  • The simple fact that Youtube doesn't allow it proves that it is possible to do it – Gabriel May 29 '23 at 11:05
16

youtube-dl

This is technically possible and very easy to do with youtube-dl. Note: this isn't an "api". This isn't supported by Google, and it technically may be against there TOS. I assume if you have access in North Korea, that it's totally legal.

# Download the stream and extract the audio.
youtube-dl -x

# If you just need the url you can use
youtube-dl -x --get-url <URL>
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
  • 2
    Note that for most, if not all Youtube videos are stored as audio and video separately for 1080p+, thus `--format=bestaudio' may saves some bandwidth. – McSinyx Mar 16 '20 at 10:29
10

Update, because I think no one thought it what that easy. Just read it, if you want to use it for private usage (you know, youtube terms and stuff like that).

After some research work with different APIs and libraries and researching source code, I just tried it by myself and wolla.

Just saying, audio only links are in the page source of each video.

You just have to know what you are looking for ;)

Open a youtube video, view page source and search for "mime%3Daudio". There should be 5 matches, full url for example:

"https%3A%2F%2Fr2---sn-35cxanpbo5a-8pxl.googlevideo.com%2Fvideoplayback%3Fsource%3Dyoutube%26signature%3D30EC556F55533FBFD9003767730D10556681F33A.B12E021CA54CCB9E225F58A4430E9BB528081FB5%26requiressl%3Dyes%26expire%3D1527306011%26clen%3D3064602%26initcwndbps%3D1152500%26ipbits%3D0%26mime%3Daudio%252Fmp4%26dur%3D192.911%26fvip%3D5%26lmt%3D1524946334873350%26key%3Dyt6%26sparams%3Dclen%252Cdur%252Cei%252Cgir%252Cid%252Cinitcwndbps%252Cip%252Cipbits%252Citag%252Ckeepalive%252Clmt%252Cmime%252Cmm%252Cmn%252Cms%252Cmv%252Cpl%252Crequiressl%252Csource%252Cexpire%26itag%3D140%26gir%3Dyes%26ip%3D81.217.53.239%26id%3Do-ALNxMeQYw4LLc1FAjxt4h795wKTdqJnzc_SBgzEJVBxR%26c%3DWEB%26keepalive%3Dyes%26mm%3D31%252C29%26mn%3Dsn-35cxanpbo5a-8pxl%252Csn-2gb7sn7r%26ei%3Du4IIW7DfC46rgAfrrpnICw%26ms%3Dau%252Crdu%26mt%3D1527284230%26pl%3D16%26mv%3Dm"

Just decode URL and you got what you want.

Develobba
  • 716
  • 8
  • 22
  • When I decode and test the example (or any other) link I get a 403 (unauthorized). Is there a way to get around this? – Micah Vertal Jun 03 '18 at 01:47
  • This link does not work for you, sry that I did not mention that. You have to search by yourself for the URL and try it, it should word EXCEPT for licencedContent. Look at my reddit post: https://www.reddit.com/r/learnprogramming/comments/8m8vso/youtube_music_do_that_to_build_your_own_for_free/ – Develobba Jun 05 '18 at 13:31
  • Thank you for clarifying - it works now. – Micah Vertal Jun 07 '18 at 04:09
  • New reddit post: https://www.reddit.com/r/learnprogramming/comments/9ctudb/youtube_music_app_for_free_build_it_by_your_own/ – Develobba Jun 12 '19 at 05:43
5

Well, I know its an old thread but still i'm posting my answer because its still unanswered.

I know its against youtube policy to download video but there is a way of downloading youtube video as an audio/mp3 file.

First is: http://api.youtube6download.top These guys will give you an easiest way of converting yt to mp3 by using there HTML LINK, Javascript/iframe widgets.

I have also seen their API listed on mashape link: https://market.mashape.com/CoolGuruji/youtube-to-mp3-download

All you need to enter youtube video id and it will fetch/convert youtube video into audio format.

Its not official an API by youtube itself.

I am using it on my websites it works very well for me.

I hope now this question is actually answered.

Kapil
  • 115
  • 3
  • 17
  • 1
    thanks for answering on this old post, could you elaborate a little? Do you participate in their 'Yt make money' program? What kind of ads do they use on your page? Could their ads be described as 'family friendly' ? thanks – stackPusher May 13 '17 at 16:32
4

Use the YouTube MP3 API. The iframe Code generates Download Buttons in various qualities and it´s free and without Ads.

https://youtubemp3api.com/

Look also at this Github Link: YouTube-MP3-API @ GitHub

dLehr
  • 115
  • 1
  • 7
2

I have developed YouTuber little software to extract mp3 from YouTube.

You can clone source code https://github.com/maythamfahmi/YouTuber

Or just use the release version in (cmd) command line for windows https://github.com/maythamfahmi/YouTuber/releases.

disclaimer: the added github is to my personal repo

Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137
0

using loadercdn you can apply for your own API to do the download.

CrazyFrog
  • 323
  • 5
  • 19