π΅ 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