Skip to content

Commands

Compose a playlist entrypoint.

compose

Compose a playlist from a composition configuration.

You can use a YAML file to specify playlists and artists should be used, and weigh them.

Source code in chopin/cli/compose.py
@click.command()
@click.argument("configuration", type=click.Path(exists=True, path_type=Path))
def compose(
    configuration: Path,
):
    """Compose a playlist from a composition configuration.

    You can use a YAML file to specify playlists and artists should be
    used, and weigh them.
    """
    click.echo("🤖 Composing . . .")

    yaml = YAML(typ="safe", pure=True)
    config = ComposerConfig.model_validate(yaml.load(open(configuration)))

    tracks = compose_playlist(composition_config=config)

    playlist = create(name=config.name, description=config.description, overwrite=True)
    fill(uri=playlist.uri, tracks=tracks)
    click.echo(f"Playlist '{playlist.name}' successfully created.")

compose_from_new_releases

Compose a playlist based on recent releases.

Parameters:

Name Type Description Default
configuration_path Path

The composition configuration, confs/recent.yaml by default.

Path('confs/recent.yaml')
Source code in chopin/cli/compose.py
def compose_from_new_releases(
    configuration_path: Path = Path("confs/recent.yaml"),
):
    """Compose a playlist based on recent releases.

    Args:
        configuration_path: The composition configuration, `confs/recent.yaml` by default.
    """
    LOGGER.info("🆕 Composing with new releases")
    yaml = YAML(typ="safe", pure=True)
    config = ComposerConfig.model_validate(yaml.load(open(configuration_path)))
    config.release_range = ((datetime.now() - timedelta(days=15)).date(), datetime.now().date())
    tracks = compose_playlist(composition_config=config)

    playlist = create(name=config.name, description=config.description, overwrite=True)
    fill(uri=playlist.uri, tracks=tracks)
    LOGGER.info(f"Playlist '{playlist.name}' successfully created.")

Create a playlist from the queue entrypoint.

from_queue

Create a playlist and shuffle it from the user's queue.

Warning

Due to Spotify API limits, you must be playing a song on an

active device for this to work.

Warning

Due to Spotify API limits, the maximum number of songs you can

use is 20.

Source code in chopin/cli/from_queue.py
@click.command()
@click.argument("name", type=str, default=constants.QUEUED_MIX.name, required=False)
def from_queue(name: str):
    """Create a playlist and shuffle it from the user's queue.

    !!! warning

        Due to Spotify API limits, you must be _playing_ a song on an
    active device for this to work.

    !!! warning

        Due to Spotify API limits, the maximum number of songs you can
    use is 20.
    """
    click.echo("🔮 Queuing . . .")
    create_playlist_from_queue(name)
    click.echo(f"Playlist '{name}' successfully created.")

Entrypoint to shuffle_playlist a playlist.

shuffle

Shuffle an existing playlist.

Source code in chopin/cli/shuffle.py
@click.command()
@click.argument("name", type=str)
def shuffle(
    name: str,
):
    """Shuffle an existing playlist."""
    click.echo("🔀 Shuffling ...")
    playlist = shuffle_playlist(name)
    click.echo(f"Playlist {playlist.name} successfully shuffled.")