The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Create a playlist generator from mood input

Here’s a simple Playlist Generator based on mood input. This can be implemented as a Python script that takes a user’s mood and returns a list of songs that match that mood.


Python Code: Mood-Based Playlist Generator

python
import random # Define mood-to-songs mapping playlist_database = { "happy": [ "Pharrell Williams - Happy", "Justin Timberlake - Can't Stop the Feeling!", "Katy Perry - Firework", "Taylor Swift - Shake It Off", "Mark Ronson ft. Bruno Mars - Uptown Funk" ], "sad": [ "Adele - Someone Like You", "Sam Smith - Stay With Me", "Lewis Capaldi - Someone You Loved", "Billie Eilish - Everything I Wanted", "Coldplay - Fix You" ], "relaxed": [ "Norah Jones - Don't Know Why", "John Mayer - Gravity", "Jack Johnson - Better Together", "Fleetwood Mac - Dreams", "Lana Del Rey - Video Games" ], "energetic": [ "Survivor - Eye of the Tiger", "Eminem - Lose Yourself", "Beyoncé - Run the World", "Kanye West - Stronger", "Imagine Dragons - Thunder" ], "romantic": [ "Ed Sheeran - Perfect", "John Legend - All of Me", "Elvis Presley - Can't Help Falling in Love", "Jason Mraz - I'm Yours", "Alicia Keys - If I Ain’t Got You" ], "angry": [ "Linkin Park - Numb", "System of a Down - Chop Suey!", "Three Days Grace - I Hate Everything About You", "My Chemical Romance - Teenagers", "Green Day - American Idiot" ] } def generate_playlist(mood): mood = mood.lower() if mood in playlist_database: songs = random.sample(playlist_database[mood], min(5, len(playlist_database[mood]))) print(f"n🎵 Playlist for mood: {mood.capitalize()}n") for i, song in enumerate(songs, 1): print(f"{i}. {song}") else: print("Sorry, mood not recognized. Try one of: " + ", ".join(playlist_database.keys())) # Example usage user_input = input("Enter your mood (happy, sad, relaxed, energetic, romantic, angry): ") generate_playlist(user_input)

Features

  • Takes a user mood as input.

  • Matches it with a predefined set of moods.

  • Returns a randomized 5-song playlist for that mood.

Would you like a version of this as a web app, mobile app, or integrated with Spotify API?

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About