Dancing around YouTube's API

·

2 min read

Did something that made me feel really cool.

I had this problem where I wanted to listen to entire YouTube channels on a shuffle; it's really helpful for passive practice listening to a foreign language. There often isn't always an easy built-in way to do this, and a colleague of mine suggested I work on making a plugin that could extract the video URLs from a page when I proposed the problem I was trying to solve. I had a feeling that might not be necessary though, given what any user can interact with on YouTube that already exists.

Well, I found someone's existing JavaScript that made playlists from an entire channel's content; a semi-solution to the problem had been around for a while; basically restoring an old feature YouTube had hidden, but was still somewhat functional under the hood. Cool, but it had a problem.

I couldn't save it as my own playlist, and since it was kinda hacky, it didn't shuffle properly like a natural playlist. I knew I could copy my own playlists and add them to other playlists I've made, and from web developer experience I know all this really is is some kind of HTTP request. I thought there must be a way to replicate this request on another playlist page where that interface is usually unavailable.

Turns out there was. With some investigating by going through the interface for copying a playlist, I found the HTTP request in my network tab that mattered, and by copying it as a fetch request in my console, and swapping out the relevant playlist IDs which I could see were part of the playlist URLs, I could indeed use it to copy other playlists I normally couldn't into my own new playlist. When in the network tab I saw the POST request pass with a 200 success status response code and my playlist update with over 800 videos after a few test runs with smaller batches I was quite happy.

With that problem off my mind, now I can get back to studying.