Get the label playlist example working
This is the first relatively big milestone for me.
This commit is contained in:
47
examples/label_playlist.py
Normal file
47
examples/label_playlist.py
Normal file
@ -0,0 +1,47 @@
|
||||
# pylint: disable=missing-module-docstring, missing-function-docstring
|
||||
|
||||
from argparse import ArgumentParser
|
||||
|
||||
from spotify_actions.album import (
|
||||
album_filter_label,
|
||||
album_sort_release,
|
||||
album_to_simplified,
|
||||
album_to_tracks,
|
||||
)
|
||||
from spotify_actions.playlist import (
|
||||
playlist_current_user_all,
|
||||
playlist_current_user_assure,
|
||||
playlist_replace,
|
||||
)
|
||||
from spotify_actions.search import Query, search_albums
|
||||
from spotify_actions.util import read_credentials_oauth
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument("-c", "--credentials", required=True)
|
||||
parser.add_argument("label")
|
||||
|
||||
cmdline = parser.parse_args()
|
||||
|
||||
client = read_credentials_oauth(
|
||||
cmdline.credentials,
|
||||
redirect_uri="https://speice.io/spotify/",
|
||||
scopes=["playlist-read-private", "playlist-modify-private", "playlist-modify-public"],
|
||||
)
|
||||
|
||||
user_playlists = playlist_current_user_all(client)
|
||||
playlists = playlist_current_user_assure(client, user_playlists, cmdline.label)
|
||||
playlist = list(playlists)[0]
|
||||
|
||||
albums_search = search_albums(client, Query(label=cmdline.label))
|
||||
albums_unfiltered = album_to_simplified(client, albums_search)
|
||||
albums_unsorted = album_filter_label(albums_unfiltered, cmdline.label)
|
||||
albums = album_sort_release(albums_unsorted, descending=True)
|
||||
tracks = album_to_tracks(client, albums)
|
||||
|
||||
playlist_replace(client, playlist.spotify_id, tracks)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user