Skip to main content

Get currently playing song and artist from Spotify faster without using the API.

Project description

SwSpotify

Discord Server Test codecov PyPI Downloads

SwSpotify is a Python library to get the song and artist of the currently playing song from the Spotify application faster and without using the API. It works on Windows, Linux, macOS and even the Spotify Web Player! 🥳

In order to add support for the Spotify Web Player, the SwagLyrics Chrome Extension needs to be installed. We have plans to extend this for other browsers as well.

If you're a developer using SwSpotify, you can direct your end users to install the extension to automatically make your application work with the Spotify Web Player. The source of the Chrome Extension is open sourced at https://github.com/SwagLyrics/SwagLyrics-Chrome-Extension.

The original repository was spotilib which worked just for Windows and hasn't been updated since a long while when it broke on account of Spotify updating their application.

Originally made for use in SwagLyrics for Spotify.

Installation

Requires Python3. Use pip or pip3 depending on your installation. You might want to use the --user flag on Linux to avoid using pip as root.

pip install SwSpotify

For linux you need dbus which is usually pre-installed.

Usage

Use it in your project by importing it as:

from SwSpotify import spotify

Then you can access the song and artist as:

>>> spotify.song()
'Hello'
>>> spotify.artist()
'Adele'

Since mostly song and artist are used in conjunction, there is a current() method as well.

>>> spotify.current()
('Hello', 'Adele')

This allows you to access song and artist by tuple unpacking as:

>>> song, artist = spotify.current()

A SpotifyNotRunning Exception is raised if Spotify is closed or paused. SpotifyClosed and SpotifyPaused inherit from SpotifyNotRunning, meaning that you can catch both at the same time:

try:
    title, artist = spotify.current()
except SpotifyNotRunning as e:
    print(e)
else:
    print(f"{title} - {artist}")

In case Spotify is closed or paused, that will automatically be reflected in the value of e.

For finer control you can catch SpotifyClosed and SpotifyPaused separately.

Compiling SwSpotify for Development

  • Clone the repo by git clone https://github.com/SwagLyrics/SwSpotify.git or use ssh.
  • cd into the cloned repo.
  • pip install -e . the -e flag installs it locally in editable mode.

Contributing

Sure, improvements/fixes/issues everything is welcome :)

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

SwSpotify-1.2.3.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

SwSpotify-1.2.3-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file SwSpotify-1.2.3.tar.gz.

File metadata

  • Download URL: SwSpotify-1.2.3.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.10 Darwin/21.2.0

File hashes

Hashes for SwSpotify-1.2.3.tar.gz
Algorithm Hash digest
SHA256 d561193e8c7dfc4dea702bff66de8d558b7785efef5097679c51f8f6fd16349e
MD5 d3a2f86d73f80959480dd8454eefd25c
BLAKE2b-256 151e5a7fb87788c92c78adb12fff4d08e63f84bb08664db01e0b7bdd316ba902

See more details on using hashes here.

File details

Details for the file SwSpotify-1.2.3-py3-none-any.whl.

File metadata

  • Download URL: SwSpotify-1.2.3-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.10 Darwin/21.2.0

File hashes

Hashes for SwSpotify-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 14551b2e86be0fa234717255c49aa51971895d48b5d7aca8c6ffdcef9ce78c3e
MD5 b534a0ed7c938cc953e7a0b56debfc4b
BLAKE2b-256 668abf4a24cbad4d9628b3147c2064eff8b288de3201b5a4c5af62399fc5c1d8

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