Created
November 3, 2023 15:37
-
-
Save bethropolis/39dc023ab18516137880e2295f834526 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import random; | |
import os | |
folder_name = "Playlist" | |
tracks=os.listdir(folder_name) | |
while True: | |
songName = input("\n\nEnter the song or artist name(Enter q to quit): ").lower() | |
def readfile(file): | |
file_path = folder_name+"/"+file+".json" | |
if(not os.path.isfile(file_path)): | |
return False | |
with open(file_path) as f: | |
data = json.load(f) | |
total_songs = len(data) | |
for song in data: | |
found = False | |
if song['song'].lower() == songName: | |
found = True | |
print("Below are great alternatives to ", song['song'], ":\n") | |
if song['artist'].lower() == songName: | |
found = True | |
print("Recommended alternatives for", song['artist'], "songs:\n") | |
if found: | |
print(file ,"alternatives:") | |
for i in range(3): | |
song_number = random.randint(0, total_songs) | |
song = data[song_number]['song'] # Access the 'song' key to get the song name | |
artist = data[song_number]['artist'] # Access the 'artist' key to get the artist name | |
print(str(i+1) + ". " + song + " by " + artist) | |
return True | |
else: | |
return False | |
if songName=="q": | |
print("Thank you for using our recommendation system.... ") | |
break | |
checker = False | |
for track in tracks: | |
track_name = str.split(track, ".") | |
if(readfile(track_name[0]) and track_name[1] == "json"): | |
checker = True | |
break | |
if checker == False: | |
print("Song not found. Can you please check the spelling.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment