コード例 #1
0
ファイル: main.py プロジェクト: michaelenger/Generalist
def create_playlist(args):
    """Create a playlist with the tracks in the playlist."""
    token = generalist.login_user()
    tracks = generalist.get_saved_tracks(token)

    tracks = list(filter(lambda x: args.genre in x["genres"], tracks))
    playlist_name = args.name or f"Generalist: {args.genre}"
    track_ids = [track["id"] for track in tracks]

    generalist.create_playlist(token, playlist_name, track_ids)
    print(f"Created playlist: {playlist_name}")
コード例 #2
0
ファイル: main.py プロジェクト: michaelenger/Generalist
def list_tracks(args: argparse.Namespace):
    """Show a list of the saved tracks."""
    token = generalist.login_user()
    tracks = generalist.get_saved_tracks(token)

    if args.alpha:
        tracks = utils.sort_track_list(tracks)

    for track in tracks:
        print("{artists} - {track} ({genres})".format(
            artists=", ".join(track["artists"]),
            track=track["name"],
            genres=", ".join(track["genres"]),
        ))
コード例 #3
0
ファイル: main.py プロジェクト: michaelenger/Generalist
def list_artists(args: argparse.Namespace):
    """Show a list of the artists from the saved tracks."""
    token = generalist.login_user()
    tracks = generalist.get_saved_tracks(token)
    artists = {}

    for track in tracks:
        for artist in track["artists"]:
            if artist not in artists:
                artists[artist] = 0
            artists[artist] = artists[artist] + 1

    artists = dict(sorted(artists.items(), key=lambda item: item[0]))
    for artist, amount in artists.items():
        print(f"{artist} ({amount})")
コード例 #4
0
ファイル: main.py プロジェクト: michaelenger/Generalist
def list_genre_tracks(args: argparse.Namespace):
    """List all the tracks in a genre."""
    token = generalist.login_user()
    tracks = generalist.get_saved_tracks(token)

    tracks = list(filter(lambda x: args.genre in x["genres"], tracks))

    if args.alpha:
        tracks = utils.sort_track_list(tracks)

    for track in tracks:
        print("{artists} - {track} ({genres})".format(
            artists=", ".join(track["artists"]),
            track=track["name"],
            genres=", ".join(track["genres"]),
        ))
コード例 #5
0
ファイル: main.py プロジェクト: michaelenger/Generalist
def list_genres(args: argparse.Namespace):
    token = generalist.login_user()
    tracks = generalist.get_saved_tracks(token)
    genres = {}

    for track in tracks:
        for genre in track["genres"]:
            if genre not in genres:
                genres[genre] = 0
            genres[genre] = genres[genre] + 1

    if args.alpha:
        genres = dict(sorted(genres.items(), key=lambda item: item[0]))
    else:
        genres = dict(
            sorted(genres.items(), key=lambda item: item[1], reverse=True))

    for genre, amount in genres.items():
        print(f"{genre} ({amount})")
コード例 #6
0
def test_get_saved_tracks(spotify_mock, mock_artists, mock_saved_tracks):
    spotify_mock.get_saved_tracks.side_effect = mock_saved_tracks
    spotify_mock.get_artists.return_value = mock_artists

    result = generalist.get_saved_tracks("token")

    assert result == [
        {
            "id": "0K9v3Jq3mI0phzWbeKAiqc",
            "name": "The Grey",
            "artists": ["Beyond The Barricade"],
            "genres": [],
        },
        {
            "id": "5CJ1xQCFywhEryVUPJup5T",
            "name": "The Boy Who Wouldn't Hoe Corn",
            "artists": ["Alison Krauss & Union Station"],
            "genres": ["bluegrass", "folk", "progressive bluegrass"],
        },
        {
            "id": "0K9v3Jq3mI0phzWbeKAiqc",
            "name": "The Grey",
            "artists": ["Beyond The Barricade"],
            "genres": [],
        },
        {
            "id": "5CJ1xQCFywhEryVUPJup5T",
            "name": "The Boy Who Wouldn't Hoe Corn",
            "artists": ["Alison Krauss & Union Station"],
            "genres": ["bluegrass", "folk", "progressive bluegrass"],
        },
        {
            "id": "0K9v3Jq3mI0phzWbeKAiqc",
            "name": "The Grey",
            "artists": ["Beyond The Barricade"],
            "genres": [],
        },
    ]