Just some quick code
The idea for this came when I discovered TikTok street interviewer Cheyne Gitsham @slickpup. Most of his videos are about music and are in the following format. Host: “What song are you listening to right now?” Guest: “I’m listening to {song name} by {artist name}” then there are usually four to six interactions just like that per video. With over 700 videos in that category, I was sure this would be a goldmine of good music, So I set out to make a program to scrape these videos and extract the songs into a Spotify playlist. This weekend project actually came out to be around 530 lines of code, but that’s just Go for you, nevertheless, heres what it takes to make a playlist.
Preparing input data
function getLinks() { // css selector \/
const links = [...document.querySelectorAll('a.css-1undbtb-7937d88b--AVideoContainer')]
.map(a => a.href)
.filter(Boolean)
.join('\n');
console.log(links);
return links;
}
getLinks();
- The JavaScript function above is used in the browser console to get each video link.
- Links are copied to a .csv; then using Excel functions, Text to Columns and transpose, data is formatted to one link per row.
- Run the program which takes the .csv links and adds them to a playlist.
Program sequence
- Iterate links.csv
- Crawler downloads TikTok as .mp3 through a third party service.
- Use FFmpeg to extract audio as a .mp3
- Extract text with GPT-4o mini Transcribe model.
- Format transcript inti playlist .csv from text with GPT-4o mini.
- Use spotify API to get song URIs and add them to the playlist.
TikTok put up a good fight against my Go Chromdriver, so I chose to use a third party service to download the videos. For this same reason the links need to be fetched manualy. As much as I love a good scraper / crawler, I know how they can be frouned apown, so doing some of these steps manually isn’t a big deal to me.
Building off those setbacks, I decided that It would make more sense to build a quick tool rather than a full scheduled application which runs every so often. This allowed me to speed up the development process by focusing only on the core functionality. For instance, I decided to not use a database; instead, the program tracks its progress by keeping all the files and indexing the directory to find the next file to process which I also believe keeps the database from becoming out of sync.
Reviewing my choice of Go, this project probably would’ve made a good Jupyter Notebook, especially since most of the processing is not done in the program. Go did get its moment to shine when I enabled concurrency, though. I didn’t get any metrics, but handling five videos at once was a huge improvement, especially for the amount of work put in to add that feature. If you know me, I’m a fan of Go, even if it did make the code 100 lines longer, this project was great and fulfilled its purpose quite well without being very complicated.
Conclusion
Finally, “How was the music you may ask?” The playlist is on spotify if you want to take a listen, but in my opinion, it was severely underwhelming. It wasn’t a complete loss, though, since I did figure out the black eyed peas arnt half bad, but it seems that I expected it to be incredibly curated when in reality it was just a very average playlist. I created a pivot table to find my repeat offenders, and the data says it all. I like billy joel, but I’ve lost my taste for Vienna after It became popular on TikTok. There are a lot of songs that I like, but it just doesn’t feel special.