Fullstack Dev Versus Youtube

The day before 2023 on of my favorite artists decided to drop a new track! Amazing, I thought, I’ll add it to my Spotify playlist.Unfortunately it was no where to be found, and this wasn’t the only song. Easy! I can just download the mp3 off YouTube and add it to my Spotify playlist manually. Let me just find a website.

Unfortunately it was no where to be found, and this wasn’t the only song. Easy! I can just download the mp3 off YouTube and add it to my Spotify playlist manually. Let me just find a website.

Admittedly the website was pretty nice with only a single strange ad, however it still left a bit of a bad taste in my mouth. Downloading random files off websites like these probably isn’t the most hygienic computing practice. After all I’ve been a full stack dev for a little bit (just graduated college!) This should be no problem let’s just see what YouTube does…

Oh... that's ALOT of parameters

wondering if anyone else had already reversed it, which led me to a hackernews post and then to this site https://tyrrrz.me/blog/reverse-engineering-youtube-revisited

After reading throught the entire AMAZING post I created a fetch request in node using the android example only to get back a 403 error...Not readable. No biggie I'll switch to the embedded web player it seems much more useful anyway! I carefully extracted the decoder from the youtube player just as the blog said and prepared the request

I sent it off and BOOM! ....wait what? a 403?? I double cheked my code and the decryption but didn't find any faults. At this point I was pretty bummed but remembered about an open source project called invidious that Louis Rossman mentioend. I nagivated to the website and noticed that they were pulling the videos directly from youtube's rr endpoint. Exactly what I wanted to do! How is this possible? On a closer inspection of the netowrk traffic I saw the keywork ANDROID. The original method I was using, but how did they get theirs to work?

Since the project is open source I parsed their github only to find it was in a language called crystal. Despite me being unfamilliar it was easy enough to read and reminded me of bash. Eventually I stumbeled on two functions

This was the function I needed! Looking at the request it seems that they had additional context compared to what I had especially the html5 context. I found where the function was called and determined that they initally used and ANDROID client for the first attempt, matching what I initally saw in their network traffic. With all of this I put together my own network call and.... BOOM!!! FINALLY A STREAM. Since this wasn't using the web client I didn't need to decode the signature it was free to access.

let data = { "videoId": videoId, "context": { "client": { "hl": "en", "gl": "US", "clientName": "ANDROID", "clientVersion": "17.10.35", "androidSdkVersion": 30, "osName": "Android", "osVersion": "12", "platform": "MOBILE" } }, "params": "2AMBCgIQBg", "contentCheckOk": true, "racyCheckOk": true, "user": { "lockedSafetyMode": false }, "playbackContext": { "contentPlaybackContext": { "html5Preference": "HTML5_PREF_WANTS", }, }, }

I quickly threw together an ugly frontend and posted it to digital ocean under an express server and prepped another project to repair my broken discord bot.

https://www.yt-linkify.com

Hopefully this is usefull to someone or just an interesting read. Big shoutout to the invidious project and tyrrrz's blog they did basically all of the heavy lifting for this new developer!

If this ever makes it to Hacker News, I love you guys! I read the site multiple times a day. You all keep me motivated especially in times like this where I'm not sure if I should continue being a developer. Thanks for keeping me sane and happy new year!

If anyone is hiring check out the other links on the site to get in contact with me Cheers!

Contact Me!