Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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"
                )
Exemplo n.º 3
0
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")
Exemplo n.º 4
0
def run():
    os.environ['SPOTIFY_AUTH_TOKEN'] = 'put spotify token here '

    # Get a list of our playlists from youtube
    youtube_client = YoutubeClient('./credentials/client_secret.json')
    spotify_client = SpotifyClient(os.getenv('SPOTIFY_AUTH_TOKEN'))
    playlists = youtube_client.get_playlists()

    # Ask whcih playlists we want to get the video 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}")

    # For each video in the playlist, get the song information form youtube
    songs = youtube_client.get_videos_from_playlist(chosen_playlist.id)
    print(f"Attempting to add {len(songs)} ")

    # 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} ")

    # If we find the song add it to our Spotify liked songs

    pass
Exemplo n.º 5
0
def run():
    with open('creds/spotify_auth.json') as sp:
        data = sp.read()
    spotify_cred = json.loads(data)

    image_converter = ImgConverter()
    read_text_file = ReadText()
    spotify_client = SpotifyClient(spotify_cred["spotify_token"])

    img_location = input("Enter location of image file: ")
    txt_file = "sample.txt"  # make a dump file
    txt_location = image_converter.extract_text(img_location, txt_file)
    playlist_name = input("Enter a name for your new playlist: ")
    playlist_id = spotify_client.create_new_playlist(playlist_name)

    songs_arr = read_text_file.read_txt(txt_location)
    songs = read_text_file.find_artist_track(songs_arr)
    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)
        if spotify_song_uri:
            uris.append(spotify_song_uri)
        added_song = spotify_client.add_song_to_spotify(uris, playlist_id)
    print(f"Successfully added songs in your {playlist_name} playlist")
Exemplo n.º 6
0
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 run():
    """
    main driver code
    """
    youtube_client = YoutubeClient('./creds/client_secret.json')
    spotify_client = SpotifyClient(SPOTIFY_API_KEY)
    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}")

    collected_songs = youtube_client.get_videos_from_playlist(
        chosen_playlist.id)
    print(f"Attempting to add {len(collected_songs)} to the spotify library")

    for song in collected_songs:
        spotify_song_id = spotify_client.search_song(song.artist, song.track)

        if spotify_song_id:
            added_flag = spotify_client.add_song_to_spotify(spotify_song_id)
            if added_flag:
                print(f"Successfully added {song.artist} - {song.track}")
Exemplo n.º 8
0
def run():

    spotify_client = SpotifyClient(os.getenv('SPOTIFY_AUTH_TOKEN'))
    main_music_folder = os.getenv('DIR_MUSIC')
    playlist_id = os.getenv('PLAYLIST_ID')

    # searches and finds all mp3s in the file struture of the given dir
    os.chdir(main_music_folder)
    song_list = []
    for root, dirs, files in os.walk(main_music_folder, topdown=True):
        for name in files:
            if name.endswith('.mp3'):
                song_list.append(os.path.join(root, name))

    # temp: will remove the usage of pandas
    songs = pd.DataFrame(song_list, columns=['path'])
    songs['song_info'] = songs['path'].apply(lambda x: song_info(x))
    songs[['artist', 'track']] = songs['song_info'].apply(pd.Series)
    songs = songs[~((songs['artist'].isin([None, ' ', ''])) | (songs['track'].isin([None, ' ', ''])))].reset_index(drop=True)
    songs = songs['song_info'].tolist()

    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, playlist_id)
            if added_song:
                print(f"Added {song['artist']} - {song['track']} to your Spotify Playlist.")
Exemplo n.º 9
0
def run():
    youtube_client = YoutubeClient()
    spotify_client = SpotifyClient('/secrets/secrets.spotify_token')
    playlists = youtube_client.get_playlists()

    for index, playlist in enumerate(playlists):
        print(f"{index}: {playlist.title}")
    choice = int(input("Enter your Playlist 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)}")

    for song in songs:
        spotify_song_id = spotify_client.search_song(song.track)
        if spotify_song_id:
            added_song = spotify_client.add_song_to_spotify(spotify_song_id)
            if added_song:
                print(f"Added {song.track}")
Exemplo n.º 10
0
def run():
    youtube_client = YoutubeClient('./creds/client_secret.json')
    spotify_client = SpotifyClient(os.getenv('SPOTIFY_AUTH_TOKEN'))
    playlists = youtube_client.get_playlists()

    for index, playlist in enumerate(playlists):
        print(f"{index}: {playlist.title}")
    choice = 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.artist, song.track)
        if spotify_song_id:
            added_song = spotify_client.add_song_to_spotify(spotify_song_id)
            if added_song:
                print(f"Successfully added {song.artist}, {song.track}")
Exemplo n.º 11
0
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}")
Exemplo n.º 12
0
def run():
    # Get youtube playlists
    youtube_client = YoutubeClient('./creds/client_secret.json')
    spotify_client = SpotifyClient(os.getenv('SPOTIFY_AUTH_TOKEN'))
    playlists = youtube_client.get_playlists()

    # Add 20 random tracks to your Liked Songs playlist
    # random_tracks = spotify_client.get_random_tracks()
    # track_ids = [track['id'] for track in random_tracks]

    # was_added_to_library = spotify_client.add_tracks_to_library(track_ids)
    # if was_added_to_library:
    #   for track in random_tracks:
    #     print(f"Added {track['name']} to your library")

    # Choose video's playlist
    # iterate through playlist and print names and position for choice
    for index, playlist in enumerate(playlists):
        print(f"{index}: {playlist.title}")
    choice = int(input("Enter your choice: "))
    chosen_playlist = playlists[choice]
    print(f"Selection: {chosen_playlist.title}")

    # Get song videos from playlist user selected
    songs = youtube_client.get_videos_from_playlist(chosen_playlist.id)
    print(f"Adding {len(songs)} songs")

    # Search Songs in 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 Like Songs Playlist"
                )
Exemplo n.º 13
0
def run():
    # 1. Get a list of playlists from YouTube
    youtube_client = YouTubeClient('./creds/client_secret.json')
    spotify_client = SpotifyClient(os.getenv('SPOTIFY_AUTH_TOKEN'))
    playlists = youtube_client.get_playlists()

    # 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 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, artst}")