This is a simple library for connecting to the unofficial Spotify podcast API.
It can be used to export data from your dashboard at
https://podcasters.spotify.com/home.
- List of episodes
- Starts and streams
- Listeners
- Followers
- Gender
- Age
- Country
- Episode performance
Before you can use the library, you must extract your Spotify credentials from the dashboard; they are not exposed through your Spotify settings.
You can use our web extension for that or take a look at the code to see how to do it manually.
You need three values:
sp_dc: Can be found in the Spotify cookies once you're logged in. It's a long string with around 160 characters.sp_key: Can also be found in the Spotify cookies once you're logged in. It's a UUID (36 characters).client_id: This is a static value and stays the same for everyone. It is05a1371ee5194c27860b3ff3ff3979d2. Spotify might change it in the future, so if you run into issues, please check your network requests while logged in to find the new value.
pip install spotifyconnector
from spotifyconnector import SpotifyConnector
# Set up the connector
connector = SpotifyConnector(
base_url="https://generic.wg.spotify.com/podcasters/v0123"
client_id="05a1371ee5194c27860b3ff3ff3979d2", # login to spotify and monitor connection to get this id
podcast_id="your_spotify_podcast_id",
sp_dc="xxxxxxxxxxxxxxxxxx...xxx", # can be found in cookies after logged in (long string)
sp_key="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" # can be found in cookies after logged in
)
# Get podcast metadata
connector.metadata()
# Get the list of listeners of a podcast
listeners = connector.listeners()
# Get the aggregated listeners of a podcast (by age, country, gender)
aggregate = connector.aggregate()
# Iterate over all episodes (supports pagination)
for episode in connector.episodes():
# Do something with episode
pass
# Get the performance of an episode
performance = connector.performance("episode_id")
# ...See __main.py__ for all endpoints.
You can run the script locally to test it:
make devTo run the script with verbose logging:
export LOGURU_LEVEL=TRACE
make devWe use Pipenv for virtualenv and dev dependency management. With Pipenv installed:
- Install your locally checked-out code in development mode, including its dependencies, and all dev dependencies into a virtual environment:
pipenv sync --dev- Create an environment file and fill in the required values:
cp .env.example .env- Run the script in the virtual environment, which will automatically load
your
.env:
pipenv run spotifyconnectorTo add a new dependency for use during the development of this library:
pipenv install --dev $packageTo add a new dependency necessary for the correct operation of this library, add
the package to the install_requires section of ./setup.py, then:
pipenv installTo publish the package:
python setup.py sdist bdist_wheel
twine upload dist/*or
make publishThis was inspired by the code at wdr-okr, extended and released to PyPi.
