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)
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()
class TestMyMusicLib(unittest.TestCase): def setUp(self): self.my_music_lib = MyMusicLib(MagicMock(), MagicMock(), MagicMock()) @unittest.skip("ported from old test") def test_get_playlist(self): name = "Real Canadian Cheddar" playlist = self.my_music_lib.get_playlist_by_name(name) self.assertEqual(playlist.name, "Real Canadian Cheddar") # Spotify Web API only allows fetching 50 playlists at a time # This is meant to test that a playlist is found even if not in first 50 to be fetched @unittest.skip("ported from old test") def test_get_playlist__not_in_initial_batch(self): name = "JPearson's Top of 2020" playlist = self.my_music_lib.get_playlist_by_name(name) self.assertEqual(playlist.name, "JPearson's Top of 2020") @unittest.skip("ported from old test") def test_get_playlist__does_not_exist__returns_none(self): name = "This playlist does not exist" playlist = self.my_music_lib.get_playlist_by_name(name) self.assertIsNone(playlist) @unittest.skip("ported from old test") def test_get_my_albums_by_genres(self): min_genres_per_group = 1 # - old format: {'rock, dance rock': [Album]} # - new format: [{genres: ['rock', 'dance rock'], albums: [Album]}] album_groups = self.my_music_lib.get_my_albums_grouped_by_genre( 10, min_genres_per_group) self.assertIsNotNone(album_groups) self.assertLess(1, len(album_groups.keys()))
def setUp(self): self.mock_spotify_client = MagicMock() self.music_util = MusicUtil(self.mock_spotify_client, MagicMock()) self.my_music_lib = MyMusicLib(MagicMock(), MagicMock(), MagicMock()) self.playlist_stats = PlaylistStats(self.my_music_lib, self.music_util, MagicMock())
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"))
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()
def setUp(self): self.my_music_lib = MyMusicLib(MagicMock(), MagicMock(), MagicMock())