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?
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
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.
Try this API https://youtube2mp3api.com it produces quality YouTube to Mp3/Mp4. Which can be embedded easily in any website or mobile app.
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.
Regarding the Terms of Service of the YouTube API
https://developers.google.com/youtube/terms
YOU CAN'T :
using loadercdn you can apply for your own API to do the download.