Skip to content

mashb1t/spotisights

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpotiSights - Spotify Insights

Website Status License

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.

Setup

  1. Copy config/*.env.dist to config/*.env and change the credentials
  2. Run composer install in php/src to make sure vendor exists for volume mount (only dev environment)
  3. Run docker-compose up -d to provision Grafana, InfluxDB and PHP+Nginx
  4. Log in to the Spotify Developer website
  5. Set up a new Spotify App, add the callback URL https://localhost:8080/spotify/callback and add client id and client secret to php.env
  6. 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)

Data Flow / User setup

  1. Admin: add user email to permitted users in your Spotify app
  2. User: Call https://localhost:8080/ and connect services (technical reference: see auth section)
  3. User: initial crawl is executed for new users on first successful connection (pulls max. 50 last listened tracks)
  4. Admin: find username by new session name in file system / username in admin dashboard
  5. Admin: create user with email, username = Spotify username and "Viewer" permissions (default)
  6. Cronjob: collects recent tracks fron the authorized user and saves them to InfluxDB (interval defined in docker-cron)
  7. User: Log in to Grafana at https://localhost:3000/ and navigate to the Dashboard "spotisights" (https://localhost:3000/?orgId=1&search=open)
  8. User: There should be a dashboard called "Current User" whch only shows data for the current user

Auth

This app implements the Authorization Code Flow of Spotify with Refresh Tokens by using file sessions.

API Scopes

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()

Disclaimer ARM CPUs (code: see branch "arm")

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

linux/arm/v6

Grafana is only compatible with linux/armv7, the container will not start.

linux/arm/v7

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.

References

Spotify API

InfluxDB

License

This project is open-sourced software licensed under the MIT license.