Skip to main content

A python wrapper for spotify web sockets

Project description

Spotify Web Sockets

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.spotify 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.spotify 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.spotify import SpotifyWs

client = SpotifyWs()

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

Launch flask example

In order to launch flask example you need the following commands:

First install the library package from pypi

$ pip3 install spotify-ws

Then cd into the examples folder

$ cd examples/flask-app

Now before launching the server.py you need to retrieve the client-id and the client-secret from your spotify dashboard panel; you can find it here.

Copy paste client-id and client-secret in the respective variables.

Now you're ready to launch the server using the following command

$ python3 server.py

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-0.0.7.tar.gz (8.0 kB view details)

Uploaded Source

File details

Details for the file spotify-ws-0.0.7.tar.gz.

File metadata

  • Download URL: spotify-ws-0.0.7.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.2

File hashes

Hashes for spotify-ws-0.0.7.tar.gz
Algorithm Hash digest
SHA256 3a7b4782fe572e39fdaef917dad7d4d703b918c7ad09f830a938a1892a3a9063
MD5 9c2734eac84a8e732a2d929cbbde4889
BLAKE2b-256 a97131cbfb290855edf8c3262251414c3eddc24e82646157cbddf2a5d22f5c01

See more details on using hashes here.

Supported by

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