def run(): # 1. Get a list of our playlists from Youtube youtube_client = YouTubeClient('./creds/client_secret.json') spotify_client = SpotifyClient(input("Enter your Spotify Token: ")) playlists = youtube_client.get_playlist() # 2. Ask which playlist we want to get the music videos from for index, playlist in enumerate(playlists): print(f"{index}: {playlist.title}") choice = int(input("Enter your choice: ")) chosen_playlist = playlists[choice] print(f"You selected: {chosen_playlist.title}") # 3. For each video in the playlist, get the song information from Youtube songs = youtube_client.get_videos_from_playlist(chosen_playlist.id) print(f"Attempting to add {len(songs)}") # 4. Search for the song on Spotify for song in songs: spotify_song_id = spotify_client.search_song(song.artist, song.track) if spotify_song_id: added_song = spotify_client.add_song_to_spotify(spotify_song_id) if added_song: print( f"Added {song.artist} - {song.track} to your Spotify Liked Songs" )
def run(): # 1. Get a list of the user's playlists from YouTube youtube_client = YouTubeClient('./credentials/client_secret.json') spotify_client = SpotifyClient(os.getenv('SPOTIFY_AUTH_TOKEN')) playlists = youtube_client.get_playlists() # 2. Ask which playlist the user wants to retrieve music from for index, playlist in enumerate(playlists): print(str(index) + ": " + playlist.title) choice = int(input("Enter your choice: ")) chosen_playlist = playlists[choice] print("You selected: " + chosen_playlist.title) # 3. For each video in the chosen playlist, get the song info from YouTube songs = youtube_client.get_videos_from_playlist(chosen_playlist.id) print("Attempting to add " + str(len(songs)) + " items") # 4. Search for the song on Spotify and add to Spotify Liked Songs list for song in songs: # spotify_song_id = spotify_client.search_song(song.artist, song.track) spotify_song_id = spotify_client.search_song("music", song) if spotify_song_id: added_song = spotify_client.add_song_to_spotify(spotify_song_id) if added_song: # print("Added "+song.track+" ("+song.artist+")") print("Added " + song)
def run(): with open('creds/spotify_auth.json') as sp: data = sp.read() spotify_cred = json.loads(data) youtube_client = YouTubeClient() spotify_client = SpotifyClient(spotify_cred["spotify_token"]) playlists = youtube_client.get_playlists() for index, playlist in enumerate(playlists): print(f"{index}: {playlist.title}") choice = int(input("Enter you choice: ")) chosen_playlist = playlists[choice] print(f"You selected: {chosen_playlist.title}") playlist_name = input("Enter a name for your new playlist: ") playlist_id = spotify_client.create_new_playlist(playlist_name) print(playlist_id) songs = youtube_client.get_songs_from_playlist(chosen_playlist.id) print(songs) print(f"Attept to add {len(songs)} songs") uris = [] for song in songs: spotify_song_uri = spotify_client.search_song(song.artist, song.track) uris.append(spotify_song_uri) print(uris) count = len(uris) added_song = spotify_client.add_song_to_spotify(uris, playlist_id) print(f"added {count} songs in your {playlist_name} playlist")
def run(): # Youtube credentials youtube_client = YouTubeClient('./creds/client_secret.json') #Spotify authentication token spotify_client = SpotifyClient('SPOTIFY_AUTH_TOKEN') #Get the list of playlists playlists = youtube_client.get_playlists() #Print the name of playlists for index, playlist in enumerate(playlists): print(f"{index}: {playlist.title}") #Choose the playlist you want choice = int(input("Enter your choice: ")) chosen_playlist = playlists[choice] print(f"You selected: {chosen_playlist.title}") #Get the list of songs songs = youtube_client.get_videos_from_playlist(chosen_playlist.id) print(f"Attempting to add {len(songs)}") #Search and add the song for song in songs: spotify_song_id = spotify_client.search_song(song.artist, song.track) if spotify_song_id: added_song = spotify_client.add_song_to_spotify(spotify_song_id) if added_song: print( f"Added {song.artist} - {song.track} to your Spotify Liked Songs" )
def run(): #Take user inputs username = input("Enter your Spotify Username: "******"Enter your Spotify token: ") playlist_name = input("Enter desired playlist title: ") youtube_client = YouTubeClient('./creds/client_secret.json') spotify_client = SpotifyClient(sToken) playlists = youtube_client.get_playlists() for index, playlist in enumerate(playlists): print(f"{index}: {playlist.title}") choice = int(input("Enter your choice: ")) chosen_playlist = playlists[choice] print(f"You selected: {chosen_playlist.title}") songs = youtube_client.get_videos_from_playlist(chosen_playlist.id, sToken) playlist_id = spotify_client.create_playlist(username, sToken, playlist_name) print(f"Attempting to add {len(songs)}") uris = [info["spotify_uri"] for song, info in songs.items()] uris = list(filter(None, uris)) request_data = json.dumps(uris) query = "https://api.spotify.com/v1/playlists/{}/tracks".format( playlist_id) response = requests.post(query, data=request_data, headers={ "Content-Type": "application/json", "Authorization": "Bearer {}".format(sToken) }) print(f"Succefully added {len(uris)} songs!")
def run(): #get list of playlists youtube_client = YouTubeClient( './client_secret_876125188595-la35iddi3u0vnuejhksmaf4tnma4tgcp.apps.googleusercontent.com.json' ) spotify_client = SpotifyClient( 'BQAaHHx8oX1TR3CKCIsy4mrTCmf72-Sfq_9XadFMr61VnoxYAlc6OqwoqFFD5QIpCTUuO4bDIskRjkVvnEc3Cmp1s3AURkFp3E5Kq0OJLyzvvBGVn-EKdd_TBqU2D44rCaKGX5CF5csp1dVgnCWAbSfQmemTv6VhOm83UAJ5yTOFTDJgMIRvSdSKX299XdJTfQ' ) playlists = youtube_client.get_playlists() for index, playlist_title in enumerate(playlists): print(f'{index}: {playlist_title}') print(len(playlists)) resp = int(input("Enter your choice: ")) chosen_playlist = playlists[resp] print(f"You selected: {chosen_playlist.title}") #get songs from playlist songs = youtube_client.get_videos_from_playlist(chosen_playlist.id) print(f"Attempting to add: {len(songs)}") #search for songs in playlist for song in songs: spotify_song_id = spotify_client.search_song(song.artist, song.track) if spotify_song_id: added_song = spotify_client.add_song_to_spotify(spotify_song_id) if added_song: print(f"Added {song.artist}")
def main(): yt_client = YouTubeClient() print( "-----------Welcome to Tyrone's YouTube MP3 Downloader / Spotify Playlist Creator ----------\n" ) print("Select the playlist you want below: ") keys = yt_client.get_playlist() print("0. Exit") user_choice = int(input("\nYour Choice: ")) while user_choice != 0: try: if user_choice == keys[user_choice - 1][0]: print("----------------DOWNLOADING--------------------") print("The songs in the playlist you have chosen are: \n") pl_information = yt_client.get_songs(user_choice - 1) playlist_url = f"https://www.youtube.com/watch?v={keys[user_choice-1][1]}&list" \ f"={pl_information['Playlist ID']}" user_path = input("\nPlease specify full path to store files: " ) # ~/Music/YouTube_Downloads mp3_downloader(user_path, playlist_url) user_choice = int(input("\nYour Choice: ")) # print(pl_information['Songs']) song_info = yt_client.get_tracks_artist( pl_information['Songs']) # print(song_info) except IndexError: print("\nNot a Valid Option!!") user_choice = int(input("\nYour Choice: ")) print('\n!!!!THANK YOU FOR USING!!!!')
def run(): # 0. Initialisation of Youtube and Spotify clients youtube_client = YouTubeClient('client_secret_desktop.json') # spotify_client = SpotifyClient(spotify_token, spotify_user_id) spotify_client = SpotifyClient(spotify_user_id, spotify_scope, spotify_client_id, spotify_client_secret, spotify_redirect_url) # 1. Get a list of our Youtube playlists playlists = youtube_client.get_playlists() for index, playlist in enumerate(playlists): print("{}: {}".format(index, playlist.title)) # 2. Select the Youtube playlists we want the music videos from choices = list( map(int, input("Enter the indexes of the different playlists to select: ").split())) # separated by a space print("List of Youtube playlists indexes entered: {}".format(choices)) # 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 # 3. Define the name of the Spotify playlist to create spotify_playlist_name = input( "Define the name of the Spotify playlist to create: ") # Tracks from Youtube Playlists # 4. For each video in each playlist selected, get the track information from Youtube # and search the track in spotify thanks to its uri spotify_track_uris = [] for choice in choices: chosen_playlist = playlists[choice] print("You selected the playlist '{}'".format(chosen_playlist.title)) songs = youtube_client.get_music_videos_from_playlist(chosen_playlist.id) print("Adding {} tracks from '{}'".format(len(songs), chosen_playlist.title)) for song in songs: spotify_track_uri = spotify_client.search_spotify_tracks_uri(song.artist, song.track_name) if spotify_track_uri: # create a list of all uris spotify_track_uris.append(spotify_track_uri) # 5. If we found the track, add it to to the new Spotify playlist added_tracks = spotify_client.add_tracks_to_spotify_playlist(spotify_playlist_name, spotify_track_uris) if added_tracks: print("Tracks added successfully to your new Spotify playlist '{}'!".format(spotify_playlist_name))
def run(): youtube_client = YouTubeClient('./creds/client_secret.json') spotify_client = SpotifyClient(os.getenv('SPOTIFY_AUTH_TOKEN')) playlists = youtube_client.get_playlist() for index, playlist in enumerate(playlists): print(f"{index}: {playlist.title}") choice = int(input("Enter your choice: ")) chosen_playlist = playlists[choice] print(f"You selected: {chosen_playlist.title}") songs = youtube_client.get_videos_from_playlist(chosen_playlist.id) print(f"Attempting to add {len(songs)} songs") for song in songs: spotify_song_id = spotify_client.search_song(song.track) if spotify_song_id: print(f"Attempting to add {spotify_song_id}") added_song = spotify_client.add_song_to_spotify(spotify_song_id) if added_song: print(f"Added {song.track}")
def run(): # 1. Get a list of our playlist from YouTube youtube_client = YouTubeClient('./creds/client_secret.json') spotify_client = SpotifyClient(os.getenv('SPOTIFY_AUTH_TOKEN')) playlists = youtube_client.get_playlist() # 2. Ask which playlist they want to get songs from for index, playlist in enumerate(playlists): print(f'{index}: {playlist.title}') choice = validate("Which Playlist: ") chosen_playlist = playlists[choice] print(f"You've selected: {chosen_playlist.title}") # 3. For each video in playlist get the song information songs = youtube_client.get_videos_from_playlist(chosen_playlist.id) print(f"Attempting to add {len(songs)}") # Search for songs on spotify for song in songs: spotify_song_id = spotify_client.search_song(song.artist, song.track) if spotify_song_id: added_song = spotify_client.add_song_to_spotify(spotify_song_id) if added_song: print(f"Added {song.artist}")