def main(): spotify = Spotify() music_util = MusicUtil(spotify, print) my_music_lib = MyMusicLib(spotify, 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, print, playlist_stats, ) playlist_updater.add_recommended_songs_with_similar_attributes(lambda: 10)
def main(): spotify = Spotify() music_util = MusicUtil(spotify, print) my_music_lib = MyMusicLib(spotify, music_util, print) playlist_stats = PlaylistStats(my_music_lib, music_util, print) seed_prefix = "seed: " seed_playlists = my_music_lib.search_my_playlists(seed_prefix) print(f"Found {len(seed_playlists)} matching playlists.") for seed_playlist in seed_playlists: playlist_updater = PlaylistUpdater(seed_playlist, my_music_lib, music_util, spotify, print, playlist_stats) get_target_playlist_name = lambda seed_playlist_name: seed_playlist_name[ len(seed_prefix):] updated_playlist = playlist_updater.create_or_update_target_from_seed( 3, get_target_playlist_name) if updated_playlist is not None: print(f"Updated '{updated_playlist.name}'.")
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 main(): spotify = Spotify() music_util = MusicUtil(spotify, print) my_music_lib = MyMusicLib(spotify, 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) genre_breakdown = music_util.get_genres_by_frequency(playlist) # 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_artists(playlist))}" ) print("...with this genre breakdown:") for genre, count in sorted_genre_breakdown.items(): print(f"{count}\t{genre}") print()
def main(): spotify = Spotify() ui = ConsoleUI() music_util = MusicUtil(spotify, ui.tell_user) my_music_lib = MyMusicLib(spotify, music_util, ui.tell_user) music_lib_bot = MusicLibBot(spotify, my_music_lib, music_util, ui) music_lib_bot.run_interactive_playlist_picker() music_lib_bot.run_create_playlist_from_an_artists_discography() music_lib_bot.run_create_playlist_based_on_existing_playlist() music_lib_bot.run_create_or_update_target_from_seed() music_lib_bot.run_interactive_playlist_picker() music_lib_bot.run_add_tracks_from_my_saved_albums_with_similar_genres() music_lib_bot.run_add_recommended_tracks_with_similar_attributes() music_lib_bot.run()
def main(): spotify = Spotify() music_util = MusicUtil(spotify, print) my_music_lib = MyMusicLib(spotify, music_util, print) print(get_playlist_metadata(my_music_lib, "tapestries"))
def main(): spotify = Spotify() ui = ConsoleUI() music_util = MusicUtil(spotify, ui.tell_user) my_music_lib = MyMusicLib(spotify, music_util, ui.tell_user) MusicLibBot(spotify, my_music_lib, music_util, ui).run()
def setUp(self): self.mock_spotify = MagicMock() self.music_util = MusicUtil(self.mock_spotify, MagicMock()) self.my_music_lib = MyMusicLib(MagicMock(), MagicMock(), MagicMock()) self.playlist_stats = PlaylistStats(self.my_music_lib, self.music_util, MagicMock())
def setUp(self): self.my_music_lib = MyMusicLib(MagicMock(), MagicMock(), MagicMock())