Skip to content

alirzglshn/spotify-room-controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎡 Music Rooms Controller

A real-time music room application built with Django REST Framework that integrates directly with the Spotify API. This project allows users to create music rooms, join existing rooms, and control music playback, all synced with their Spotify account.

Note: The frontend of this project is already implemented using Webpack (no API documentation needed here). You just need to connect your Spotify account to get started.

πŸš€ Features

Create & Join Rooms: Host your own music room or join someone else’s.

Spotify Integration: Play music directly in your Spotify account.

Control Playback: Play, pause, and manage the currently playing song.

Room Management: Hosts can allow guests to pause, skip songs, and vote on skipping.

Real-time Updates: See what’s currently playing in the room.

πŸ“¦ Project Structure backend/ # Django project root β”‚ β”œβ”€β”€ core/ # Main app for room management β”‚ β”œβ”€β”€ models.py # Room model β”‚ β”œβ”€β”€ serializers.py # Serializers for Room CRUD operations β”‚ β”œβ”€β”€ views.py # Room views (create, join, leave, update, get) β”‚ └── urls.py # Core app URLs β”‚ β”œβ”€β”€ spotify/ # Spotify integration app β”‚ β”œβ”€β”€ models.py # SpotifyToken model β”‚ β”œβ”€β”€ util.py # Helper functions for Spotify API β”‚ β”œβ”€β”€ views.py # Spotify authentication and playback views β”‚ β”œβ”€β”€ credentials.py # Spotify CLIENT_ID, CLIENT_SECRET, REDIRECT_URI β”‚ └── urls.py # Spotify app URLs β”‚ β”œβ”€β”€ frontend/ # Frontend app (Webpack) β”‚ └── urls.py β”‚ β”œβ”€β”€ backend/ # Django project settings β”‚ β”œβ”€β”€ settings.py β”‚ β”œβ”€β”€ urls.py β”‚ └── wsgi.py └── db.sqlite3 # SQLite database

⚑ How It Works

Create a Room

The creator becomes the host.

Host can configure room settings like allowing guests to pause or votes required to skip songs.

Join a Room

Use a unique room code to join an existing room.

Connect to Spotify

Log in to your Spotify account.

Music played in the room is synced with Spotify, meaning the songs are actually playing in your Spotify account.

Control Music

Hosts and allowed guests can play, pause, and skip tracks.

Real-time updates ensure everyone in the room sees the same song.

πŸ”§ Technology Stack

Backend: Django 4.2, Django REST Framework

Frontend: Webpack

Database: SQLite

Authentication: Spotify OAuth2 API

APIs: Spotify Web API for playback control

πŸ›  Setup

Clone the repository

git clone https://github.com/alirzglshn/spotify-room-controller.git cd spotify-room-controller

Create a virtual environment & install dependencies

python -m venv venv source venv/bin/activate # Linux / macOS venv\Scripts\activate # Windows pip install -r requirements.txt

Configure Spotify credentials

Add your CLIENT_ID, CLIENT_SECRET, and REDIRECT_URI in spotify/credentials.py.

Run migrations

python manage.py migrate

Run the development server

python manage.py runserver

Access the frontend

The frontend is handled via the frontend app and Webpack. Open your browser at http://127.0.0.1:8000 to start using the app.

🎯 Endpoints Overview (Backend)

While you don’t need API docs for the frontend, here’s a quick reference:

Core App (/core/)

GET /room - List all rooms

POST /create-room - Create a new room

GET /get-room?code=<room_code> - Get a specific room

POST /join-room - Join a room

POST /leave-room - Leave a room

PATCH /update-room - Update room settings

GET /user-in-room - Check which room the user is in

Spotify App (/spotify/)

GET /get-auth-url - Get Spotify OAuth URL

GET /redirect - Spotify OAuth callback

GET /is-authenticated - Check Spotify authentication

GET /current-song - Get currently playing song

PUT /play - Play current song

PUT /pause - Pause current song

⚠ Notes

This project requires Spotify Premium to control playback.

The frontend is prebuilt and fully functional with the backend.

Sessions are used to track users and hosts for room functionality.

THANKS FOR VIEWING THIS REPOSITORY

About

Real-time music room backend with Django REST Framework | Spotify API integration | CRUD, authentication, and playback control

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors