From 9a8f540afb8951f972c21adb049bb1631227f321 Mon Sep 17 00:00:00 2001 From: Amazia Gur Date: Tue, 26 Nov 2024 12:46:45 +0000 Subject: [PATCH] feat: introduce mood based song generator --- Mood based youtube song generator/README.md | 35 +++++++++++++++++++ .../random_song_generator.py | 33 +++++++++++++++++ .../requirements.txt | 1 + README.md | 1 + 4 files changed, 70 insertions(+) create mode 100644 Mood based youtube song generator/README.md create mode 100644 Mood based youtube song generator/random_song_generator.py create mode 100644 Mood based youtube song generator/requirements.txt diff --git a/Mood based youtube song generator/README.md b/Mood based youtube song generator/README.md new file mode 100644 index 00000000..efadd890 --- /dev/null +++ b/Mood based youtube song generator/README.md @@ -0,0 +1,35 @@ +# Mood Based Youtube Song Generator +This Python script fetches a random song from YouTube based on your mood input and opens it in your default web browser. + +## Features +Accepts mood input (e.g., happy, sad, energetic) and finds related songs on YouTube. +Opens the YouTube song URL in your browser. + +## Setup + +### 1. Install dependencies: +```shell +pip install -r requirements.txt +``` + +### 2. Get your YouTube API key: +- Follow the instructions to get your YouTube Data API key. + +### 3. Set your API key: +Replace the api_key variable in the script with your own [YouTube Data API key](https://developers.google.com/youtube/v3/getting-started) +```python +api_key = "YOUR_YOUTUBE_API_KEY" +``` + +### 4. Run the script: +```shell +python random_song_generator.py +``` + +## Example +Input: +```bash +Enter your mood (e.g., happy, sad, energetic): happy +``` +The script will fetch a song and open it in your browser. + diff --git a/Mood based youtube song generator/random_song_generator.py b/Mood based youtube song generator/random_song_generator.py new file mode 100644 index 00000000..241b432c --- /dev/null +++ b/Mood based youtube song generator/random_song_generator.py @@ -0,0 +1,33 @@ +import random +import webbrowser +from googleapiclient.discovery import build + + +def fetch_youtube_songs(mood): + api_key = "your_youtube_api_key" + youtube = build("youtube", "v3", developerKey=api_key) + request = youtube.search().list( + q=f"{mood} song", part="snippet", type="video", maxResults=10 + ) + response = request.execute() + songs = [ + f"{item['snippet']['title']} - https://www.youtube.com/watch?v={item['id']['videoId']}" + for item in response['items'] + ] + return songs + + +def random_song_generator(): + mood = input("Enter your mood (e.g., happy, sad, energetic): ").lower() + try: + songs = fetch_youtube_songs(mood) + random_song = random.choice(songs) + song_title, song_url = random_song.split(" - ") + webbrowser.open(song_url) + print(f"Here's a song for your mood ({mood}):\n{random_song}") + except Exception as e: + print("Error fetching songs. Please check your API key and mood.") + + +if __name__ == "__main__": + random_song_generator() diff --git a/Mood based youtube song generator/requirements.txt b/Mood based youtube song generator/requirements.txt new file mode 100644 index 00000000..704bcd50 --- /dev/null +++ b/Mood based youtube song generator/requirements.txt @@ -0,0 +1 @@ +google-api-python-client \ No newline at end of file diff --git a/README.md b/README.md index cb63b7dd..d590fce9 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ More information on contributing and the general code of conduct for discussion | Longitude & Latitude to conical coverter | [Longitude Latitude conical converter](master/Longitude%20Latitude%20conical%20converter) | Converts Longitude and Latitude to Lambert conformal conic projection. | | Mail Sender | [Mail Sender](https://github.com/DhanushNehru/Python-Scripts/tree/master/Mail%20Sender) | Sends an email. | | Merge Two Images | [Merge Two Images](https://github.com/DhanushNehru/Python-Scripts/tree/master/Merge%20Two%20Images) | Merges two images horizontally or vertically. | +| Mood based youtube song generator | [Mood based youtube song generator](https://github.com/DhanushNehru/Python-Scripts/tree/master/Mood%20based%20youtube%20song%20generator) | This Python script fetches a random song from YouTube based on your mood input and opens it in your default web browser. | | Mouse mover | [Mouse mover](https://github.com/DhanushNehru/Python-Scripts/tree/master/Mouse%20Mover) | Moves your mouse every 15 seconds. | | Morse Code | [Mose Code](https://github.com/DhanushNehru/Python-Scripts/tree/master/Morse%20Code) | Encodes and decodes Morse code. | | No Screensaver | [No Screensaver](https://github.com/DhanushNehru/Python-Scripts/tree/master/No%20Screensaver) | Prevents screensaver from turning on. |