A guard bot for your collaborative playlists on Spotify.
This is a project of a bot guard for collaborative playlist on Spotify. Test the bot in action:
- Use the Test playlist by adding a song to it and wait for it to be removed once every minute;
- Check if the bot is up and running accessing its status webpage.
Also, please check the other apps related to this project:
- Spotify Playlist Guard API: An API for the Spotify Playlist Guard application;
- Spotify Playlist Guard Website: A website for the Spotify Playlist Guard application;
Spotify defines playlists as collaborative, private and public. The collaborative status is given to playlists which users want to share with friends or trusty people. However, once the playlists is set to collaborative, any user with access to the URL that leads to that playlist is able to edit it, adding or deleing tracks. At the day of the publication of this project - 07/03/2022 - there is no official available way of limiting access to collaborative playlists.
More discussions can be found in the official Spotify community forum:
This is the codebase for the bot server which performs a guard routine removing, from selected playlists, tracks added by unauthorized users. Please check the other app related to this project:
- Spotify Playlist Guard API: An API for registering to the Spotify Playlist Guard and add playlists to be guarded.
The guard routine performed by the application consists of:
- Retrieving the active playlists registered in the service from the Spotify Playlist Guard API;
- Fetch the current state of the playlist from the Spotify Web API;
- Compare the two states of the playlists in terms of its snapshot_id and track's property 'added_by' which declares the related user;
- Once tracks added by unauthorized users are detected, the application:
- Removes these tracks from the Spotify playlist ;
- Updates it in the Spotify Playlist Guard API service.
Each guard routine performed for a playlist is published and consumed by a message queue.
Notes:
-
Ideally, taking into account the architecture of this application, the producer and consumer of the queues should be hosted in differente servers to avoid loops to block the server instance, but for the current size of the project, these two parts of the application are being exectued in the same server.
-
At the day of the publication of this project, the Spotify Web API does not provide a two-way communication protocol for access to state changes such as playlist update, player update, etc. Therefore, the alternative presented by this project, as described above, consists of periodic calls to the Spotify API in order to get changes in the state of the playlists. More discussions about this topic can be found in the resources:
- TypeScript as language;
- Spotify Playlist Guard API to interact with the application data using axios as HTTP client;
- Spotify Web API with spotify-web-api-node as client wrapper;
- node-cron for scheduling a cron job to execute the guard routine;
- RabbitMQ for message queuing of the routine using:
- Express as web framework to expose a status endpoint of the application.
- Render as cloud server host;
Also , the tools used in the development environment:
Requirements:
- Docker for deskop installed in your machine;
- Docker Compose (The Windows and Mac versions of Docker Desktop include Docker Compose in their installation, so you only need to install it separately if you are using the Linux version);
- NodeJS and npm installed in your machine;
- Spotify Playlist Guard API runnind on your machine - see the project`s repo for instructions on how to run it and its dependencies services as containers on your machine;
- A terminal of your choice.
Steps:
- Clone this repo on your local directory;
- In the terminal, enter the created directory and run the following command to install all the dependencies:
npm install -y
- Create a .env file based on the .env.example in this project and insert the values of the vars based on your development environment.
Note: When running both the app and the message broker as a containers, the RABBITMQ_HOST env var must be set to 'rabbitmq';
- Initialize the Docker app in your machine and run the following command at the root of your directory to build the image of the app, start the containers and intialize the them:
docker-compose up --build -V -d
The application will then be available at 'http://localhost:3030'
- Once the containers and volumes are created in your machine, simply use the commands to start and stop them:
docker-compose start
docker-compose stop
- Create a .env file based on the .env.example in this project and insert the values of the vars based on your development environment.
Note: When running the the app locally, the RABBITMQ_HOST env var must be set to 'localhost';
-
Remove the 'main' service of the docker-compose.yml file;
-
Initialize the Docker app in your machine and run the following command at the root of your directory to intialize the containers of the external services:
docker-compose up -d
- Run the following command to run the app in development mode:
npm run dev
- For a production-like running app, run the following commands:
npm run build
npm run start
The application will then be available at 'http://localhost:3030'
This project uses Convention Commit with AngularJS's commit message convention specifications for standard commit messages.
Spotify Playlist Guard is published under MIT license