Skip to content

Build smart playlists, based on tracks' audio analysis, and other parameters. Filter newest tracks, that go together well in a DJ set.

License

Notifications You must be signed in to change notification settings

smartplaylist/smartplaylist-backend

Repository files navigation

spotify-grabtrack

Development

  1. cp .env-template .env and edit environment variables
  2. Run ./dev/setup_local_development.sh from the root directory
  3. Access Admier: http://localhost:8080/?pgsql=db&username=postgres
  4. Open RabbitMQ GUI: http://localhost:15672/. Default credentials are guest/guest
  5. Open the web app: http://localhost:3001/

It will run Postgres, Rabbit, Redis for caching requests, RedisInsights for a GUI for Redis, a REST API server and a web app.

Restore database from production

Database backups are stored in the ~./pg_backup directory on the production server. To restore a database locally, run the ./dev/restore_db.sh script.

Deployment

Code is deployed using GitHub Actions. To deploy a new version, simply push a new tag following the semantic versioning format api-vX.Y.Z (or app-vX.Y.Z). The workflows are defined in .github/workflows.

  1. Update version info in deployment/.dependencies file.

  2. Tag and push your commit, this will trigger the GitHub Action workflow (replace api with app when needed)

    git tag api-vX.Y.Z
    git push origin api-vX.Y.Z

Workflows call deployment scripts on a production server. Deployment scripts are

  • deployment/deploy_api.sh
  • deployment/deploy_app.sh

Deployment scripts are not updated automatically, you need to update them manually. Deployment scripts are called using webhook tool installed on the production server. Read more about webhook configuration in deployment/README.md.

Working with PostgreSQL

  • Backup: docker exec -ti spotify-grabtrack_db_1 pg_dump -U postgres -W -F c spotify -f /pg_backup/2022-03-31-backup.psql
  • Restore: docker exec -ti spotify-grabtrack_db_1 pg_restore -U postgres -d spotify /pg_backup/2022-03-30-backup.psql

Or

  • Login to db Docker: docker exec -ti spotify-grabtrack_db_1 bash --login
  • Backup database: pg_dump -U postgres -W -F c spotify > /pgdata/2022-03-31-backup.psql
  • Restore: pg_restore -U postgres -d pg_import_test /pgdata/2022-03-31-backup.psql

Rename database

  1. docker exec -ti spotify-grabtrack_db_1 bash --login
  2. psql -U postgres
  3. \connect postgres
  4. ALTER DATABASE old_spotify RENAME TO spotify;

Work with alembic (database migrations)

  1. Have the stack working (you need a running database) docker-compose -f stack.yml up -d
  2. docker build -t alembic-image ./db
  3. docker run -ti -v $(pwd)/db:/db --rm --network smartplaylist_network alembic-image alembic revision -m "Create indexes on tracks"
  4. Run migrations docker run -ti -v $(pwd)/db:/db --rm --network smartplaylist_network alembic-image alembic upgrade head
  5. Undo last migration docker run -ti -v $(pwd)/db:/db --rm --network smartplaylist_network alembic-image alembic downgrade -1

Running the listeners

Listeners are checking for Rabbit messages and downloading artist, album and track data from Spotify API.

  1. Get followed artists docker run -ti --rm --network smartplaylist_network -p 8083:8083 -v $(pwd)/app/src:/app --env-file .env smartplaylist/app pipenv run python sync_followed_artists.py
  2. Run related artists listener: docker run -ti --network smartplaylist_network -v $(pwd)/app/src:/app --env-file .env --rm smartplaylist/app pipenv run python get_related_artists.py
  3. Get albums docker run -ti --network smartplaylist_network -v $(pwd)/app/src:/app --env-file .env --rm smartplaylist/app pipenv run python get_albums.py
  4. Get album details docker run -ti --network smartplaylist_network -v $(pwd)/app/src:/app --env-file .env --rm smartplaylist/app pipenv run python get_album_details.py
  5. Get track details docker run -ti --network smartplaylist_network -v $(pwd)/app/src:/app --env-file .env --rm smartplaylist/app pipenv run python get_track_details.py
  6. Update database stats docker run -ti --network smartplaylist_network -v $(pwd)/app/src:/app --env-file .env --rm smartplaylist/app pipenv run python update_db_stats.py

Get oAuth token

After running sync_followed_artists.py you will be asked to open an URL and paste the URL you were redirected to to obtain the oAuth token.

Remember, your Spotify Developer application in https://developer.spotify.com/dashboard/applications needs to have "Redirect URI" configured and same with env SPOTIPY_REDIRECT_URI

About

Build smart playlists, based on tracks' audio analysis, and other parameters. Filter newest tracks, that go together well in a DJ set.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages