Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Mood based youtube song generator/README.md
Original file line number Diff line number Diff line change
@@ -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.

33 changes: 33 additions & 0 deletions Mood based youtube song generator/random_song_generator.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions Mood based youtube song generator/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
google-api-python-client
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down