示例#1
0
def let_user_specify_which_songs_to_queue(trackURIList, trackNameList,
                                          artist_name, sp):
    chosen_trakcs = input(
        "\nChoose a track by specifying the corresponding number (x to exit): "
    )
    if chosen_trakcs == 'x':
        return -1
    nice_numbers = utl.convert_song_numbers_to_useful_numbers(
        chosen_trakcs, len(trackURIList))

    while nice_numbers == -1:
        chosen_playlist = input(
            "Try again. Choose a track by specifying the corresponding number (x to exit): "
        )
        if chosen_playlist == 'x':
            return -1
        nice_numbers = utl.convert_song_numbers_to_useful_numbers(
            chosen_playlist, len(trackURIList))

    for number in nice_numbers:
        track_id = trackURIList[number]
        track_name = trackNameList[number]
        # track = ['2cEBG31c2Y7mfRlLY8g1ah', 'Pictures', 'Benjamin Francis Leftwich', 'Ben Howard']
        if utl_sp.add_song_to_queue(sp, track_id, track_name, artist_name, ""):
            continue
        else:
            break
    print()
示例#2
0
def add_recommendation_seeds_to_queue(sp):
    recommendations = recommendation_function(sp)
    if recommendations == -1:
        return 0
    for recommendation in recommendations:
        track_id = recommendation[1]
        track_name = recommendation[0]
        main_artist_name = recommendation[6][0][0]
        # recommendation = ['Motion Picture Soundtrack', '79M3U8vzBBfSFRyxFFGVRl', 34, 179609, 'Motion Picture Soundtrack', '79M3U8vzBBfSFRyxFFGVRl', [['Shallou', '7C3Cbtr2PkH2l4tOGhtCsk']]
        if utl_sp.add_song_to_queue(sp, track_id, track_name, main_artist_name, ""):
            continue
        else:
            break
示例#3
0
def add_x_random_top_track_from_random_follower_to_queue(
        sp,
        number_of_tracks_to_add=1,
        random_artist="uniform",
        random_track="uniform"):
    tracks_to_add = add_x_random_top_track_from_random_follower(
        sp, number_of_tracks_to_add, random_artist, random_track)
    for track in tracks_to_add:
        # track = ['2cEBG31c2Y7mfRlLY8g1ah', 'Pictures', 'Benjamin Francis Leftwich', 'Ben Howard']
        if utl_sp.add_song_to_queue(sp, track[0], track[1], track[2],
                                    track[3]):
            continue
        else:
            break
示例#4
0
def add_random_songs_from_searched_artists(artists,
                                           spotify_object,
                                           number_of_songs_to_add,
                                           top_all="top"):
    number_of_artists = len(artists)
    start_idx = random.randint(0, number_of_artists - 1)
    tracks_to_add = []

    number_songs_per_artist = [0] * len(artists)
    for i in range(number_of_songs_to_add):
        number_songs_per_artist[
            start_idx] = number_songs_per_artist[start_idx] + 1
        start_idx += 1
        if start_idx == (number_of_artists):
            start_idx = 0

    tracks_to_add = []
    for idx, num_to_add in enumerate(number_songs_per_artist):

        artist = artists[idx]

        if top_all == "top":
            randomTopTrack_id_name_popu, song_number = find_random_unique_top_tracks_from_artist(
                spotify_object, artist[1], num_to_add)

        if top_all == "all":
            randomTopTrack_id_name_popu, song_number = search.random_song_artist(
                spotify_object, artist[1], num_to_add)

        for track in randomTopTrack_id_name_popu:
            track_id_to_add_to_queue = track[0]
            track_name_to_add_to_queue = track[1]
            tracks_to_add.append([
                track_id_to_add_to_queue, track_name_to_add_to_queue,
                artist[3], artist[3]
            ])

    random.shuffle(tracks_to_add)

    for track in tracks_to_add:
        # track = ['2cEBG31c2Y7mfRlLY8g1ah', 'Pictures', 'Benjamin Francis Leftwich', 'Ben Howard']
        if utl_sp.add_song_to_queue(spotify_object, track[0], track[1],
                                    track[2], track[3]):
            continue
        else:
            break
示例#5
0
def add_related_artists_from_searched_artists(spotify_object,
                                              number_of_songs_to_add,
                                              random_artist="uniform",
                                              random_track="uniform",
                                              include_given_artist=False):
    artists = search_for_artists(spotify_object)
    number_of_artists = len(artists)
    start_idx = random.randint(0, number_of_artists - 1)
    tracks_to_add = []
    for add in range(number_of_songs_to_add):
        # artist = ['https://api.spotify.com/v1/artists/2wwZDwSBHaVaOI6cE2hfhf', 'spotify:artist:2wwZDwSBHaVaOI6cE2hfhf', '2wwZDwSBHaVaOI6cE2hfhf', 'Yoste']
        artist = artists[start_idx]
        randomRelatedArtist_id_name_followers_popu = find_random_artist_from_related_artists(
            artist[1],
            spotify_object,
            how_random=random_artist,
            include_given_artist=include_given_artist)
        randomTopTrack_id_name_popu, song_number = find_random_top_track_from_artist(
            spotify_object,
            artist_id=randomRelatedArtist_id_name_followers_popu[0],
            how_random=random_track)

        #print(randomRelatedArtist_id_name_followers_popu[1], song_number, start_idx, artist[3], randomTopTrack_id_name_popu[1])

        track_id_to_add_to_queue = randomTopTrack_id_name_popu[0]
        track_name_to_add_to_queue = randomTopTrack_id_name_popu[1]
        tracks_to_add.append([
            track_id_to_add_to_queue, track_name_to_add_to_queue,
            randomRelatedArtist_id_name_followers_popu[1], artist[3]
        ])

        start_idx += 1
        if start_idx == (number_of_artists):
            start_idx = 0

    for track in tracks_to_add:
        # track = ['2cEBG31c2Y7mfRlLY8g1ah', 'Pictures', 'Benjamin Francis Leftwich', 'Ben Howard']
        if utl_sp.add_song_to_queue(spotify_object, track[0], track[1],
                                    track[2], track[3]):
            continue
        else:
            break
示例#6
0
def queue_from_random_playlist(sp, number_of_tracks_to_add):
    playlists = utl_sp.return_all_playlists(sp,
                                            public=True,
                                            private=True,
                                            collaborative=True,
                                            printing=False)
    keys = list(playlists.keys())
    tracks_to_add = []
    for num in range(number_of_tracks_to_add):
        rand_key = random.choice(keys)
        # [['name'], ['id'], ['uri'], print_color]
        playlist_name = playlists[rand_key][0]
        playlist_uri = playlists[rand_key][2]
        info = return_random_song_in_playlist(sp, playlist_uri)
        tracks_to_add.append([info[0], info[1], info[2], playlist_name])

    for track in tracks_to_add:
        # track = ['2cEBG31c2Y7mfRlLY8g1ah', 'Pictures', 'Benjamin Francis Leftwich']
        if utl_sp.add_song_to_queue(sp, track[0], track[1], track[2],
                                    track[3]):
            continue
        else:
            break
示例#7
0
def spotify_terminal_interface():
    scope = 'user-read-private user-read-playback-state user-modify-playback-state ' \
            'playlist-modify-public playlist-modify-private user-read-currently-playing ' \
            'user-read-private user-top-read playlist-read-private playlist-read-collaborative'
    sp = utl_sp.create_spotify_object(scope=scope)
    current_user_info = sp.current_user()
    user_uri = current_user_info['uri']
    utl.clear_terminal()
    skip_choice = False
    user_choice = None

    print("Welcome! \n" \
          "Your are connected with " + str(current_user_info['id']) + "'s account.\n")

    while True:

        message = Fore.LIGHTBLUE_EX + "What do you want to do? \n" + Fore.WHITE + \
                  "0 - Get current playback status\n" \
                  "1 - Modify playback\n" \
                  "2 - Search artist/track/album \n" \
                  "3 - Add current song to playlist\n" \
                  "4 - Add songs to queue\n" \
                  "5 - Find first occurrence of an artist in your playlists\n" \
                  "6 - Playlist features\n"

        number_of_options = utl.find_largest_number_in_string(message)

        if not skip_choice:
            user_choice = utl.specify_int_in_range(0,
                                                   number_of_options,
                                                   message=message,
                                                   error='x')

        utl.clear_terminal()

        if user_choice == 0:
            utl.clear_terminal()
            while True:
                gcps.get_current_playback_status(sp)

                print("Do you want to modify playback ? y/n")
                print("('a' = add current song to playlist)")
                i, o, e = select.select([sys.stdin], [], [], 10)
                "TODO: You should only refresh progress bar, if it is not a new song or new device ..."
                if (i):
                    resp = sys.stdin.readline().strip()
                    if resp == "y" or resp == "n" or resp == "a":
                        response = resp
                        utl.clear_terminal()
                        break
                utl.clear_terminal()

            # gcps.get_current_playback_status(sp)
            # response = utl.proceed_or_refresh(message="Do you want to modify playback (r = refresh) ?")

            skip_choice = False
            if response == 'y':
                user_choice = 1
                skip_choice = True
            if response == 'r':
                user_choice = 0
                skip_choice = True
            if response == 'a':
                user_choice = 3
                skip_choice = True

        # modify playback
        if user_choice == 1:
            legal_values = modi.print_feedback_info_modify()
            modify_mod = input("Modify ('x' = exit): ")
            skip_choice = False
            if modify_mod == 'x':
                utl.clear_terminal()
                continue
            if modify_mod not in legal_values:
                utl.clear_terminal()
                user_choice = 1
                skip_choice = True
                continue

            modify_para = modi.print_feedback_info_modify_parameter(modify_mod)
            modi.modify_spotify(modify_mod, modify_para)
            skip_choice = False

        # search for artist
        if user_choice == 2:

            message_search = Fore.LIGHTBLUE_EX + "What do you want to do? \n" + Fore.WHITE + \
                             "0 - Search Artist \n" \
                             "1 - Search Track \n" \
                             "2 - Search Album \n"

            number_of_options_search = utl.find_largest_number_in_string(
                message_search)

            user_choice_search = utl.specify_int_in_range(
                0, number_of_options_search, message=message_search, error='x')

            utl.clear_terminal()

            if user_choice_search == 0:
                astq.search_for_artist_show_tracks_grouped_by_album_add_queue(
                    sp)

            if user_choice_search == 1:
                print("Not implemented yet")

            if user_choice_search == 2:
                print("Not implemented yet")

        if user_choice == 3:
            output_log = add_cur_song.add_current_song_to_playlist2(
                sp=sp, public=True, private=True, collaborative=True)
            utl.clear_terminal()
            check_list = isinstance(output_log, list)

            if utl.RepresentsString(output_log) and check_list == False:
                print(output_log + "\n")
            elif len(output_log) > 0:
                for i in output_log:
                    print(Fore.BLUE + i.split("was")[0] + Fore.WHITE +
                          i.split("was")[1])
                print()
                print()

        if user_choice == 4:
            utl.clear_terminal()

            queue_message = Fore.LIGHTBLUE_EX + "How do you want to add songs to queue?\n\n" + Fore.WHITE + \
                "1. Search for song and add to queue \n" \
                "2. Add random songs based on related artists to the artists you are following\n" \
                "3. Add random songs from all your playlists \n" \
                "4. Choose artists you are following. (x) \n" \
                "5. Search for artists and add songs from related artists. \n" \
                "6. Search for artist and choose between his/her songs. \n" \
                "7. Search for artists, songs from these artists only.\n" \
                "8. Find songs by genre (x) \n" \
                "9. Add songs based on tracks, artists and/or genre. \n"

            add_song_queue_choice = utl.specify_int_in_range(
                1,
                9,
                message=queue_message + "\nChoose the number "
                "corresponding to what you want "
                "to do.",
                error='x')

            utl.clear_terminal()

            if int(add_song_queue_choice) == 1:
                track_search = input("Track search: ")
                utl.clear_terminal()
                track_info = utl_sp.search_one_type(sp,
                                                    track_search,
                                                    "track",
                                                    limit=3)
                # -1 comes when user says 'x' to quit
                if track_info != -1:
                    # track_info [name, id, uri]
                    artist_name = utl_sp.get_artist_name_from_track_id(
                        sp, track_info[1])
                    utl_sp.add_song_to_queue(sp, track_info[1], track_info[0],
                                             artist_name, "")
                    # may use this function. Can search for artist, album and track.
                    # you should make a smart way to let the user specify what to search for.
                    # astq.add_desired_song_to_queue("artist:" + track_search, sp, type='track', limit=3)
                print()

            if int(add_song_queue_choice) == 2:
                print(
                    "You will add random songs based on artists relevant to the artists you are following.\n"
                )
                number_of_tracks_to_add = utl.specify_int_in_range(
                    1, 50, Fore.LIGHTBLUE_EX +
                    "Specify the number of tracks you want to add to queue (1-50). "
                    + Fore.WHITE)

                random_dict = {1: "uniform", 2: "relevance"}

                message_artist = Fore.LIGHTBLUE_EX + "\nWhen a random artist you follow is picked, we will have to pick one of 20 relevant artists.\n" \
                                                     "How will you choose the relevant artist? \n\n" + Fore.WHITE + \
                                 "1. Equal probability of picking all the relevant artists. \n" \
                                 "2. Higher probability of picking more relevant artists."

                message_track = Fore.LIGHTBLUE_EX + "\nWhen a relevant artists is found, we will have to pick one of its top 10 tracks.\n" \
                                                    "How will you choose among the top tracks? \n\n" + Fore.WHITE + \
                                "1. Equal probability of picking all the tracks. \n" \
                                "2. Higher probability of picking more popular tracks."

                random_artist = random_dict[utl.specify_int_in_range(
                    1, 2, message_artist)]
                random_track = random_dict[utl.specify_int_in_range(
                    1, 2, message_track)]
                print()
                crq.add_x_random_top_track_from_random_follower_to_queue(
                    sp, int(number_of_tracks_to_add), random_artist,
                    random_track)

            if int(add_song_queue_choice) == 3:
                print(Fore.LIGHTBLUE_EX +
                      "\nAdd random songs from all of your playlists\n" +
                      Fore.WHITE)
                number_of_tracks_to_add = utl.specify_int_in_range(
                    1, 50, Fore.LIGHTBLUE_EX +
                    "Choose number of tracks to add to queue (1-50). " +
                    Fore.WHITE)
                crq.queue_from_random_playlist(sp, number_of_tracks_to_add)

            if int(add_song_queue_choice) == 4:
                print("not yet implemented")

            if int(add_song_queue_choice) == 5:
                number_of_tracks_to_add = utl.specify_int_in_range(
                    1, 50, Fore.LIGHTBLUE_EX +
                    "\nChoose number of tracks to add to queue (1-50). " +
                    Fore.WHITE)

                random_dict = {1: "uniform", 2: "relevance"}
                artist_dict = {1: True, 2: False}

                message_artist = Fore.LIGHTBLUE_EX + "\nWhen a random artist you follow is picked, we will have to pick one of 20 relevant artists.\n" \
                                                     "How will you choose the relevant artist? \n\n" + Fore.WHITE + \
                                 "1. Equal probability of picking all the relevant artists. \n" \
                                 "2. Higher probability of picking more relevant artists."

                message_track = Fore.LIGHTBLUE_EX + "\nWhen a relevant artists is found, we will have to pick one of its top 10 tracks.\n" \
                                                    "How will you choose among the top tracks? \n\n" + Fore.WHITE + \
                                "1. Equal probability of picking all the tracks. \n" \
                                "2. Higher probability of picking more popular tracks."

                random_artist = random_dict[utl.specify_int_in_range(
                    1, 2, message_artist)]
                random_track = random_dict[utl.specify_int_in_range(
                    1, 2, message_track)]

                add_chosen_artist = artist_dict[utl.specify_int_in_range(
                    1, 2, Fore.LIGHTBLUE_EX +
                    "\nWill you include the chosen artists with the related artists? "
                    + Fore.WHITE + "\n\n1. True\n2. False ")]
                print()
                print(
                    Fore.LIGHTBLUE_EX +
                    "You will now search for the artists you want to find related artists to. \n"
                    + Fore.WHITE)
                crq.add_related_artists_from_searched_artists(
                    sp,
                    number_of_tracks_to_add,
                    random_artist=random_artist,
                    random_track=random_track,
                    include_given_artist=add_chosen_artist)

            if int(add_song_queue_choice) == 6:
                artist_info = sfa.search_for_one_artist_until_correct(sp)
                trackName, trackURIs, artist_name = sfa.show_all_tracks_from_artist_id(
                    artist_info[2], sp, artist_info[3])
                astq.let_user_specify_which_songs_to_queue(
                    trackURIs, trackName, artist_name, sp)

            if int(add_song_queue_choice) == 7:
                print(
                    "7. Search for artists, songs from these artists only.\n")

                print(Fore.LIGHTBLUE_EX +
                      "You will now search for artists: \n" + Fore.WHITE)
                artists = crq.search_for_artists(sp)

                number_of_tracks_to_add = utl.specify_int_in_range(
                    1, 50, Fore.LIGHTBLUE_EX +
                    "\nChoose number of tracks to add to queue (1-50). \n" +
                    Fore.WHITE)

                track_dict = {1: "top", 2: "all"}
                message_artist = Fore.LIGHTBLUE_EX + "\nHow would you pick songs from your chosen artists?\n" \
                                 + Fore.WHITE + "1. Randomly pick among top 10 songs. \n" \
                                                "2. Randomly pick among all of the artists' songs.\n"

                top_all = track_dict[utl.specify_int_in_range(
                    1, 2, message_artist)]
                crq.add_random_songs_from_searched_artists(
                    artists=artists,
                    spotify_object=sp,
                    number_of_songs_to_add=number_of_tracks_to_add,
                    top_all=top_all)

            # Find songs by genre (x).
            if int(add_song_queue_choice) == 8:
                print("Not implemented. ")

            # Add songs based on tracks, artists and/or genre.
            if int(add_song_queue_choice) == 9:
                reco.add_recommendation_seeds_to_queue(sp=sp)

        # Find first occurrence of an artist in your playlists.
        if user_choice == 5:
            fooc.first_occurance(sp)

        if user_choice == 6:
            print("TODO")
            print("Add next_track() / pause_playback / previous_track() ")
            print("recommendation_genre_seeds(), recommendations()")
            print(
                "Start a track: sp.start_playback(uris=['spotify:track:7lEptt4wbM0yJTvSG5EBof'])"
            )
            print(
                "Add to queue should also include songs by the artists you are following. "
                "'Include the artists uou are following?'")

        print()
        # break the while loop and end spotipy
        if user_choice == -1:
            break

        # check if the user wants to proceed. Main reason to have this is
        # that the user can see the output from last spotify feature call. (add random songs to queue.
        # otherwise it would just call clear terminal and all information would be gone
        if not skip_choice:
            if utl.proceed():
                utl.clear_terminal()
            else:
                break