wasp-spotify-bindings

Python wrapper to control your Spotify client on MacOS


Keywords
spotify, api, applescript, client, macos, python, python37
License
MIT
Install
pip install wasp-spotify-bindings==0.0.1

Documentation

WASP

Wrapper around AppleScript of Spotify in Python.

This library provides a simple wrapper around the AppleScript API of the Spotify application on MacOS.

Developed and tested with Python 3.7

Install

pip install wasp-spotify-bindings

Test

python wasp/tests/test_wasp.py
python wasp/tests/test_applescript.py

Import

from wasp_spotify_bindings.core import Wasp
wasp = Wasp()

API

Get track metadata.

wasp.get_track()

returns

{
    'artist': 'Rick Astley',
    'album': 'Whenever You Need Somebody',
    'disc_number': 1,
    'duration': 213573,
    'played_count': 0,
    'track_number': 1,
    'popularity': 75,
    'id': 'spotify:track:4uLU6hMCjMI75M1A2tKUQC',
    'name': 'Never Gonna Give You Up',
    'album_artist':
    'Rick Astley',
    'artwork_url':
    'http://i.scdn.co/image/15ac2c9091d9b74e841b281ceb23ca8208321444',
    'spotify_url': 'spotify:track:4uLU6hMCjMI75M1A2tKUQC'
}

Get player state.

wasp.get_state()

returns

{
    "track_id": "spotify:track:4uLU6hMCjMI75M1A2tKUQC",
    "volume": 49,
    "position": 3,  # seconds
    "state": "playing"
}

Start Spotify application.

wasp.start_spotify()

Quit Spotify application.

wasp.quit_spotify()

Play next track.

wasp.next_track()

Play previous track.

wasp.previous_track()

Play current track.

wasp.play()

Toggle play/pause on current track.

wasp.play_pause()

Pause current track.

wasp.pause()

Set volume to [0-100]

wasp.set_volume(volume=10)

Play track referred to by spotify id.

wasp.play_track(spotify_uri='spotify:track:4uLU6hMCjMI75M1A2tKUQC')

Play track in context of an album/playlist.

wasp.play_track_in_context(
    spotify_uri='spotify:track:4uLU6hMCjMI75M1A2tKUQC',
    context='spotify:track:4uLU6hMCjMI75M1A2tKUQC'
)

Increase volume by 10.

wasp.volume_up()

Decrease volume by 10.

wasp.volume_down()

Jump to position in song (seconds).

wasp.jump_to(jump_to_second=5)

Check if repeat is enabled.

wasp.is_repeating()

Check if shuffle is enabled.

wasp.is_shuffling()

Set repeating to True or False.

wasp.set_repeating(set_repeating=True)

Set shuffling to True or False.

wasp.set_shuffling(set_shuffling=True)

Toggle repeat on/off.

wasp.toggle_repeating()

Toggle shuffle on/off.

wasp.toggle_shuffling()

Mute player.

wasp.mute()

Unmute player.

wasp.unmute()