nightcoreify
Nightcore is mind-numbingly simple. It's just a speed-shift of a pre-existing track, with anime artwork and a visualizer slapped on top. The harsh reality is, we are wasting human minds on the creation of such low-effort "music."
I decided to take matters into my own hands and automate the process. This is a Python script that:
- finds and downloads a random (somewhat, see below) song from YouTube
- finds and downloads a random anime artwork from Reddit
- I broke tradition and went with Reddit rather than Pixiv because their API is so much friendlier.
- renders a new video, using FFmpeg, with sped up audio + image + audio visualizer
- uploads the finished product to YouTube
I currently have this script running in an AWS Lambda function, scheduled with an EventBridge rule, and uploading here every 6 hours. It's deployed on top of this Lambda layer for FFmpeg.
Clarification on "random" YouTube videos
There's no easy way to find a totally random video on YouTube, much less one belonging to a certain category (music in my case), at least that I can find, so I had to get a little creative. To find a "random" video, the script generates a 4-character string prepended with v=
(total of 6 characters), and searches for it in the music category. This typically returns videos whose IDs start with the 4-character string, but sometimes there will also be videos whose titles contain the 4-character string.
To reduce automatic copyright claims, the script also needs to check the copyright status of a video. This is not easy to do with YouTube's API, so it uses a naïve scraping solution.
$100 bounty opportunity!
aayushg.com/ideas has offered a $100 grant for this repo to pull songs from Spotify and/or TikTok and add copyright checks to uploaded videos. Specifically, it could nightcore the top unposted TikTok song or songs from a chosen Spotify playlist, instead of a random song!
Help wanted!
This bot's YouTube channel keeps getting flagged for adult content, because of the subreddits it links to. I've chosen the bot's subreddits after a quick search, but I don't browse them myself and have no idea what's posted there on a daily basis. If you know of subreddits that absolutely do not contain anything suggestive, receive frequent submissions and match the theme of nightcore, please add them to the SUBREDDITS
tuple in nightcorei.py and submit a pull request.
Requirements
- Python 3.8
ffmpeg
google-api-python-client
(and subsequently, a YouTube API key with upload privileges)yt-dlp
Side note: if you dig through the commits in this repo, you'll find that this used to be a Node.js script. I originally wrote it in Node to keep my options open in terms of cloud providers, but rewrote it in Python after I was sure I'd stick with Lambda.
License
This software is released under a MIT License.