Tired of pseudo-client-side YouTube downloaders? Then it's time to get right to the source. Just create a new bookmark, type
javascript:
in the "link" field and then paste this code after it:
a=function(g,h,i){return i.indexOf(g)==h};b=yt.player.Application.create('player-api',ytplayer.config);b.dispose();d=JSON.stringify(b.getVideoData()),e=d.match(/https:[^"]+videoplayback[^"]+/g),f=e.filter(z=>z.length<1000);for(c of (f.length?(f.filter(a).map((j,k)=>j+'&signature='+d.match(/[0123456789ABCDEF.]+(?=")/g).filter(z=>z.length>20).filter(a)[k])):e.filter(a)))if(~["141","251","140","171","250","249"].indexOf(new URLSearchParams(c.split('?')[1]).get('itag')))window.location=c
(I only tested this in Chrome). Now, whenever you are on a youtube video page, just click the bookmarklet and it will
- Decrypt the trivial encryption Google applies to the media stream sources.
- Use a well known range exploit to get the full length media instead of individual chunks.
- Choose the best audio bitrate and format available (anywhere from 320k Vorbis to 70k Opus)
- Redirect the current page to the best raw audio stream.
If you reach the media stream, just press CTRL-S
and save the file. If the save-file dialog doesn't automatically give you a file extension, just use "m4a". Some, but not all stream formats can be played directly in the browser. But it is always a better idea just to save them.