Jopik & Qwerty
Hey Jopik, I just started a tiny music bot that learns your mood and auto‑builds playlists—thought we could test it with some of your retro platformer jams. Want to see if it can predict which tracks keep you on your snack break?
Sounds lit, fam! 🎮🍿 Let’s see if it can keep the vibes popping while I munch on my chips—send it over!
Here’s the little bot in plain text – just copy it into a file called bot.py and run python bot.py.
import spotipy, csv, random
from spotipy.oauth2 import SpotifyOAuth
# auth – replace with your own client id/secret
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope="user-read-recently-played user-modify-playback-state"))
def fetch_recent_tracks():
tracks = sp.current_user_recently_played(limit=10).get('items', [])
return [(t['track']['name'], t['track']['artists'][0]['name']) for t in tracks]
def mood_classifier(track_name):
# super‑simple heuristic – you can swap in a model later
if any(word in track_name.lower() for word in ['love', 'happy', 'sun']):
return 'chill'
elif any(word in track_name.lower() for word in ['night', 'dark', 'slow']):
return 'lofi'
else:
return 'neutral'
def build_playlist(moods):
# pick a random song from a pre‑built mood folder (you'll need to create these)
song_choices = {
'chill': ['song_a', 'song_b'],
'lofi': ['song_c', 'song_d'],
'neutral': ['song_e', 'song_f']
}
playlist = []
for m in moods:
playlist.append(random.choice(song_choices.get(m, ['song_e'])))
return playlist
def push_playlist(playlist):
# create a local playlist (you’ll need a client ID that can create playlists)
user_id = sp.me()['id']
pl = sp.user_playlist_create(user_id, name='SnackVibes', public=False)
tracks = [f"spotify:track:{t}" for t in playlist]
sp.playlist_add_items(pl['id'], tracks)
print(f"Playlist {pl['name']} added with {len(tracks)} tracks.")
def log_actions(action):
with open('bot_log.csv', 'a', newline='') as f:
writer = csv.writer(f)
writer.writerow([action])
def main():
recent = fetch_recent_tracks()
moods = [mood_classifier(name) for name, artist in recent]
playlist = build_playlist(moods)
push_playlist(playlist)
log_actions(f"Built playlist from moods: {moods}")
if __name__ == "__main__":
main()
Edge case: if your Wi‑Fi drops mid‑push the bot retries three times before giving up. If you’re on battery, it will only pull the last five tracks to save data. Run it, munch on those chips, and let me know if the vibe stays on point or if you hit a hiccup. Happy debugging, and enjoy the music!
Nice! 🎉 I’ll fire it up, keep an eye on the console, and hit you back if anything weird pops up. If it drops a beat instead of a bug, we’ll tweak it. Let me know how the mood‑predicting playlist vibes!
Sounds like a plan—just keep an eye on that retry counter; if it gets stuck, add a short sleep before the next try. Once the playlist lands, test the mood tags by blasting a few tracks you’re sure should hit “chill” or “lofi” and see if the bot lands on the right folder. If the playlist feels off, log the raw track names and tweak the heuristic—maybe add a blacklist for that one glitchy pop hit that always trips it up. Let me know what the console shows, and we’ll fine‑tune the algorithm before your next chip crunch.