示例#1
0
文件: cli.py 项目: rgbongocan/spty
def repeat(state):
    """
    Set repeat mode

    \b
    track    Set repeat mode to track
    context  Set repeat mode to context
    off      Turn off repeat
    """
    get_spotify_client().repeat(state)
    if state == "off":
        click.echo("Repeat turned off")
    else:
        click.echo(f"Repeating {state}")
示例#2
0
文件: play.py 项目: rgbongocan/spty
def play_discography(query: str):
    """Find an artist and play their discography"""
    sp = get_spotify_client()
    res = sp.search(query, limit=1, type="artist")
    items = res["artists"]["items"]
    if items:
        sp.start_playback(context_uri=items[0]["uri"])
    else:
        click.echo("No matches found")
示例#3
0
文件: play.py 项目: rgbongocan/spty
def play_list(query: str):
    """Find a playlist and play it"""
    sp = get_spotify_client()
    res = sp.search(query, limit=1, type="playlist")
    items = res["playlists"]["items"]
    if items:
        sp.start_playback(context_uri=items[0]["uri"])
    else:
        click.echo("No matches found")
示例#4
0
文件: volume.py 项目: rgbongocan/spty
def increase_volume():
    """Increase volume by 10"""
    sp = get_spotify_client()
    current = sp.current_playback()["device"]["volume_percent"]
    if current == 100:
        click.echo("Already at max volume")
    else:
        to = min(current + 10, 100)
        sp.volume(to)
        click.echo(f"Volume increased to {to}")
示例#5
0
文件: volume.py 项目: rgbongocan/spty
def decrease_volume():
    """Decrease volume by 10"""
    sp = get_spotify_client()
    current = sp.current_playback()["device"]["volume_percent"]
    if current == 0:
        click.echo("Already muted")
    else:
        to = max(0, current - 10)
        sp.volume(to)
        click.echo(f"Volume decreased to {to}")
示例#6
0
文件: cli.py 项目: rgbongocan/spty
def shuffle(state):
    """Toggle shuffle or explicitly turn it on/off"""
    sp = get_spotify_client()
    if state == "on":
        new_state = True
    elif state == "off":
        new_state = False
    else:
        new_state = not sp.current_playback()["shuffle_state"]
    sp.shuffle(new_state)
    click.echo(f"Shuffle turned {'on' if new_state else 'off'}")
示例#7
0
文件: play.py 项目: rgbongocan/spty
def play_track(query: str):
    """Find a track and play it / resume playback"""
    sp = get_spotify_client()
    if query:
        res = sp.search(query, limit=1)
        items = res["tracks"]["items"]
        if items:
            sp.start_playback(uris=[items[0]["uri"]])
        else:
            click.echo("No matches found")
    elif not sp.current_playback()["is_playing"]:
        sp.start_playback()
示例#8
0
文件: cli.py 项目: rgbongocan/spty
def cli(ctx):
    configure()
    if not ctx.invoked_subcommand:
        # behave as if --help
        click.echo(ctx.command.get_help(ctx))
    elif ctx.invoked_subcommand != "config":
        sp = get_spotify_client()
        if not sp.devices().get("devices"):
            ctx.fail(
                "No device detected! Try opening spotify on your phone or computer."
            )
        elif not sp.current_playback():
            ctx.fail(
                "Your spotify app is currently inactive. Try issuing a command with it first."
            )
示例#9
0
文件: cli.py 项目: rgbongocan/spty
def status(info, verbose):
    """Show playback status, including the elapsed time

    \b
    track   Show track title
    album   Show album title
    artist  Show artist/s
    """
    playback = get_spotify_client().current_playback()
    track = playback["item"]
    title = track["name"]
    album = track["album"]["name"]
    artists = ", ".join([a["name"] for a in track["artists"]])

    if info == "track":
        click.echo(title)
    elif info == "album":
        click.echo(album)
    elif info == "artist":
        click.echo(artists)
    else:
        if playback["is_playing"]:
            play_status = "\u23F5"
        else:
            play_status = "\u23F8" if playback["progress_ms"] else "\u23F9"
        progress = ms_to_duration(playback["progress_ms"])
        duration = ms_to_duration(track["duration_ms"])
        label = "Artists" if len(track["artists"]) > 1 else "Artist"
        click.echo(
            inspect.cleandoc(f"""
                Title: {title}
                Album: {album}
                {label}: {artists}
                {play_status} {progress} / {duration}
                """))
        if verbose:
            click.echo(
                inspect.cleandoc(f"""
                    Repeat {playback["repeat_state"]}
                    Shuffle {'on' if playback['shuffle_state'] else 'off'}
                    """))
示例#10
0
文件: cli.py 项目: rgbongocan/spty
def pause():
    """Pause the playback"""
    sp = get_spotify_client()
    if sp.current_playback()["is_playing"]:
        sp.pause_playback()
示例#11
0
文件: cli.py 项目: rgbongocan/spty
def seek(ms: int):
    """Play current song at TIMESTAMP"""
    get_spotify_client().seek_track(ms)
示例#12
0
文件: volume.py 项目: rgbongocan/spty
def show_volume():
    """Show current volume"""
    sp = get_spotify_client()
    click.echo(sp.current_playback()["device"]["volume_percent"])
示例#13
0
文件: volume.py 项目: rgbongocan/spty
def set_volume(perc: int):
    """Set volume to PERC"""
    get_spotify_client().volume(perc)
示例#14
0
文件: cli.py 项目: rgbongocan/spty
def shift(seconds: int):
    sp = get_spotify_client()
    progress_ms = sp.current_playback()["progress_ms"]
    sp.seek_track(max(0, progress_ms + seconds * 1000))
示例#15
0
文件: cli.py 项目: rgbongocan/spty
def previous():
    """Play the previous song"""
    get_spotify_client().previous_track()
示例#16
0
文件: cli.py 项目: rgbongocan/spty
def next():
    """Skip to the next song"""
    get_spotify_client().next_track()
示例#17
0
文件: cli.py 项目: rgbongocan/spty
def replay():
    """Replay the current song"""
    sp = get_spotify_client()
    sp.seek_track(0)
    if not sp.current_playback()["is_playing"]:
        sp.start_playback()
示例#18
0
文件: cli.py 项目: rgbongocan/spty
def stop():
    """Stop the playback"""
    sp = get_spotify_client()
    if sp.current_playback()["is_playing"]:
        sp.pause_playback()
    sp.seek_track(0)
示例#19
0
文件: cli.py 项目: rgbongocan/spty
def uri():
    """Show the current song's uri"""
    item = get_spotify_client().current_playback()["item"]
    click.echo(item["uri"])
示例#20
0
文件: cli.py 项目: rgbongocan/spty
def url():
    """Show the current song's url"""
    item = get_spotify_client().current_playback()["item"]
    click.echo(item["external_urls"]["spotify"])