This project displays Spotify statistics for multiple users via Grafana.
It uses Laravel commands for data collection from the Spotify API and InfluxDB as data storage.
- Copy
config/*.env.dist
toconfig/*.env
and change the credentials - Run
composer install
inphp/src
to make sure vendor exists for volume mount (only dev environment) - Run
docker-compose up -d
to provision Grafana, InfluxDB and PHP+Nginx - Log in to the Spotify Developer website
- Set up a new Spotify App, add the callback URL
http://localhost:8080/spotify/callback
and add client id and client secret tophp.env
- Log in to Grafana and remove the permission "View" on dashboard "Current User" (navigate settings > permissions > click on group "SpotiSights" > remove role "Viewer" from board)
- Admin: add user email to permitted users in your Spotify app
- User: Call http://localhost:8080/ and connect services (technical reference: see auth section)
- User: initial crawl is executed for new users on first successful connection (pulls max. 50 last listened tracks)
- Admin: find username by new session name in file system / username in admin dashboard
- Admin: create user with email, username = Spotify username and "Viewer" permissions (default)
- Cronjob: collects recent tracks fron the authorized user and saves them to InfluxDB (interval defined in docker-cron)
- User: Log in to Grafana at http://localhost:3000/ and navigate to the Dashboard "spotisights" (http://localhost:3000/?orgId=1&search=open)
- User: There should be a dashboard called "Current User" whch only shows data for the current user
This app implements the Authorization Code Flow of Spotify with Refresh Tokens by using file sessions.
scope | reason | api endpoint |
---|---|---|
user-read-recently-played | used for statistic collection | getMyRecentTracks() |
user-read-private | used for reading username | me() |
user-read-email | currently not used, but required | me() |
playlist-modify-public | create playlist based on input parameters | createPlaylist() |
playlist-modify-public | create playlist based on input parameters | createPlaylist() |
While there are alternatives for each image and building / running them on linux/amd64 will work with minor adjustments building and running them on ARM is problematic.
In any case the image mendhak/arm32v6-influxdb
isn't a 1:1 replacement and you have to manually create the database
after startup or write a script for that.
You also have to start crond manually due to using the user "nobody" during runtime:
crond -b -L /docker.stdout
Grafana is only compatible with linux/armv7, the container will not start.
Despite Grafana now working the php container will not start due to one of the following errors:
dns for composer resolution will fail, even when adding the dns server directly to the docker daemon config
php_1 | Fatal Python error: init_interp_main: can't initialize time
php_1 | Python runtime state: core initialized
php_1 | PermissionError: [Errno 1] Operation not permitted
php_1 |
php_1 | Current thread 0x76f87390 (most recent call first):
php_1 | <no Python frame>
This most likely has to do with libseccomp2 not being compatible.
I stopped debugging and used a system with a linux/amd64 CPU.
- https://developer.spotify.com/console/get-recently-played/?limit=2&after=&before=
- https://github.com/jwilsson/spotify-web-api-php
This project is open-sourced software licensed under the MIT license.