Skip to main content

A python wrapper for Spotify WebSockets

Project description

Spotify Web Sockets

Downloads

Description

The main purpose of this project is to let the users interact with spotify web socket events. Right now the project is still in an alpha version therefore is not complete and may have some bugs. Feel free to contribute is any way.

DISCLAIMER: This library only works with a valid spotify premium subscription

Basic library usage

Example using chrome cookies

from spotifyws import SpotifyWs

client = SpotifyWs()

# Triggered on track change
@client.on('track')
def on_track_change(data):
    print('Track changed => ', data)

# Triggered on volume change
@client.on("volume")
def on_volume_change(data):
    print("Volume changed => ", data)

# Triggered on options change, such as shuffle etc.
@client.on("playback_options")
def on_playback_options_change(data):
    print("Options changed => ", data)

# Triggered playback state is resumed
@client.on("resume")
def on_play():
    print("Playback resumed")

# Triggered playback state is paused
@client.on("pause")
def on_pause():
    print("Playback paused")

Example using cookies from custom file

from spotifyws import SpotifyWs

client = SpotifyWs(cookie_file="./cookie_file.json")

# Triggered on track change
@client.on('track')
def on_track_change(data):
    print('Track changed => ', data)

# Triggered on volume change
@client.on("volume")
def on_volume_change(data):
    print("Volume changed => ", data)

# Triggered on options change, such as shuffle etc.
@client.on("playback_options")
def on_playback_options_change(data):
    print("Options changed => ", data)

# Triggered playback state is resumed
@client.on("resume")
def on_play():
    print("Playback resumed")

# Triggered playback state is paused
@client.on("pause")
def on_pause():
    print("Playback paused")

You can also send playback and volume commands to clients

from spotifyws import SpotifyWs

client = SpotifyWs(cookie_file="./cookie_file.json")

# You can get this using for example `client.get_available_devices()` or the `v1/me/player/devices` endpoint.

target_device_id = 00000000000000

client.send_command("pause", target_device_id)
client.send_command("resume", target_device_id)
client.send_command("skip_next", target_device_id)
client.send_command("skip_prev", target_device_id)
client.send_command("volume", 30000, target_device_id)
client.send_command("seek_to", 5000, target_device_id)

Cookies format

Cookies can be in either two formats

The first format is

{ "cookie1": "cookieValue1" }

and the scond one is

[ {"name": "cookie1", "value": "cookieValue1"} ]

About authentication

Right now authentication can only be achieved using local cookies and not through OAUTH flow.

Note

This code is intended for learning purposes only. You must know that bypassing spotify API is against theirs Terms of service therefore I don't invite you to abuse this library. Thanks

Author

Jacopo De Gattis

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spotify_ws-1.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spotify_ws-1.1.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file spotify_ws-1.1.0.tar.gz.

File metadata

  • Download URL: spotify_ws-1.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for spotify_ws-1.1.0.tar.gz
Algorithm Hash digest
SHA256 d9f06f900724cfbe87fd36b4db25272298adda30b80e303498fcb4bddcaae80d
MD5 4b456799d6fd13c3472372af12a8ab01
BLAKE2b-256 e323e38fbcfffb8eb08bd70a4344d0cfac903c75ce50d4796d98f564f63c5456

See more details on using hashes here.

File details

Details for the file spotify_ws-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: spotify_ws-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for spotify_ws-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68120152d95b7d7225a5b4f22dcd9292765772d0d34cc0eb3a1f50119d8d6109
MD5 0b31cc1719b7f26336b333fa2b4fc69f
BLAKE2b-256 8aeb24b8963c3692b78e6ed26e4cae0e3f955e79c42636b030d131aaba619d39

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page