Esempio n. 1
0
def main():
    spotify_client_wrapper = SpotifyClientWrapper()
    music_util = MusicUtil(spotify_client_wrapper, print)

    matching_artists = spotify_client_wrapper.get_matching_artists("beatles")
    artist = music_util.get_most_popular_artist(matching_artists)
    for album in spotify_client_wrapper.get_artist_albums(artist.id):
        print(album.name)
Esempio n. 2
0
class TestSpotifyClientWrapper(unittest.TestCase):
    def setUp(self):
        #putenv("SPOTIPY_CLIENT_ID", "x")
        #putenv("SPOTIPY_CLIENT_SECRET", "x")
        #putenv("SPOTIPY_REDIRECT_URI", "x")
        self.spotify_client_wrapper = SpotifyClientWrapper()

    def test_add_tracks(self):
        pass

    def test_get_artist_genres(self):
        artist_id = "3nFkdlSjzX9mRTtwJOzDYB"  # Jay-Z

        artist_genres = self.spotify_client_wrapper.get_artist_genres(
            artist_id)

        self.assertEqual(
            sorted(['east coast hip hop', 'hip hop', 'rap']),
            sorted(artist_genres),
        )

    def test_get_my_albums(self):
        num_albums_to_fetch = 10

        albums = self.spotify_client_wrapper.get_my_albums(num_albums_to_fetch)

        self.assertEqual(num_albums_to_fetch, len(albums))
        self.assertEqual(Album, type(albums[0]))
        self.assertEqual(Artist, type(albums[0].artists[0]))

    def test_get_artist_albums(self):
        artist_id = "74ASZWbe4lXaubB36ztrGX"  # Bob Dylan

        albums = self.spotify_client_wrapper.get_artist_albums(artist_id)

        self.assertIn("Rough and Rowdy Ways", [album.name for album in albums])

    def test__get_playlist_tracks(self):
        playlist_id = "04Ajor0wgmBWSGKRLyR4nw"  # playlist 'test__get_playlist_tracks'

        tracks = self.spotify_client_wrapper._get_playlist_tracks(playlist_id)

        self.assertIn("Fast Fuse", [track.name for track in tracks])
        self.assertLess(100, len(tracks))

    def test_find_current_user_playlist(self):
        playlist_name = "Test Playlist: test_find_current_user_playlist"

        playlist_id = self.spotify_client_wrapper.find_current_user_playlist(
            playlist_name)

        self.assertEqual("62y1x73aOCl7F52EcAfHbP", playlist_id)
Esempio n. 3
0
def main():
    spotify_client_wrapper = SpotifyClientWrapper()
    music_util = MusicUtil(spotify_client_wrapper, print)
    my_music_lib = MyMusicLib(spotify_client_wrapper, music_util, print)
    playlist_stats = PlaylistStats(my_music_lib, music_util, print)

    target_playlist = "kremwerk"
    print(
        f"Getting playlist '{target_playlist}' along with audio feature data")
    playlist = my_music_lib.get_playlist_by_name(target_playlist)
    music_util.populate_track_audio_features(playlist)

    if playlist is None:
        print(f"Couldn't find playlist '{target_playlist}'")
        return
    print(f"Got it!")

    playlist_updater = PlaylistUpdater(
        playlist,
        my_music_lib,
        music_util,
        spotify_client_wrapper,
        print,
        playlist_stats,
    )

    playlist_updater.add_recommended_songs_with_similar_attributes(lambda: 10)
Esempio n. 4
0
def main():
    spotify_client_wrapper = SpotifyClientWrapper()
    music_util = MusicUtil(spotify_client_wrapper, print)
    my_music_lib = MyMusicLib(spotify_client_wrapper, music_util, print)

    playlist_names = [
        "americana 4 PlaylistUpdater Test Playlist",
        #"bag of revels 4 PlaylistUpdater Test Playlist",
        #"art rock 4 PlaylistUpdater Test Playlist",
        #"between stations 4 PlaylistUpdater Test Playlist",
        #"buzz off 4 PlaylistUpdater",
        #"it's been easy 4 PlaylistUpdater Test Playlist",
        #"prize of Snell 4 PlaylistUpdater Test Playlist",
        #"velour 4 PlaylistUpdater"
    ]
    for playlist_name in playlist_names:
        playlist = my_music_lib.get_playlist_by_name(playlist_name)
        if playlist is None:
            print(f"Couldn't find your playlist '{playlist_name}'")
            continue

        genres_in_common = music_util.get_common_genres_in_playlist(
            playlist.id)
        genre_breakdown = music_util.get_genres_by_frequency(playlist.id)
        # ref: https://stackoverflow.com/questions/613183/how-do-i-sort-a-dictionary-by-value
        sorted_genre_breakdown = {
            k: v
            for k, v in sorted(genre_breakdown.items(),
                               key=lambda item: item[1],
                               reverse=True)
        }
        print(
            f"Playlist '{playlist_name}' has these genres in common: {genres_in_common}."
        )
        print(
            f"Num artists in playlist: {len(music_util.get_artist_ids(playlist.id))}"
        )
        print("...with this genre breakdown:")
        for genre, count in sorted_genre_breakdown.items():
            print(f"{count}\t{genre}")
        print()
Esempio n. 5
0
def main():
    spotify_client_wrapper = SpotifyClientWrapper()
    music_util = MusicUtil(spotify_client_wrapper, print)
    my_music_lib = MyMusicLib(spotify_client_wrapper, music_util, print)
    print(get_playlist_metadata(my_music_lib, "tapestries"))
Esempio n. 6
0
def main():
    spotify_client_wrapper = SpotifyClientWrapper()
    ui = ConsoleUI()
    music_util = MusicUtil(spotify_client_wrapper, ui.tell_user)
    my_music_lib = MyMusicLib(spotify_client_wrapper, music_util, ui.tell_user)
    MusicLibBot(spotify_client_wrapper, my_music_lib, music_util, ui).run()
Esempio n. 7
0
 def setUp(self):
     #putenv("SPOTIPY_CLIENT_ID", "x")
     #putenv("SPOTIPY_CLIENT_SECRET", "x")
     #putenv("SPOTIPY_REDIRECT_URI", "x")
     self.spotify_client_wrapper = SpotifyClientWrapper()