How nstrmx/django-media-player works
Project Type and Purpose
• This is a full‐stack web application combining:
• A Django (Python) web server (MVC/MVT pattern) for the admin UI, metadata management, and serving HTML/CSS/JS.
• A Rust actix-based microservice as a dedicated media streaming backend.
• A browser side with a shared Web Worker to handle media streaming and playback.
File Structure
• Top Level:
• media_app/ — Django project (settings, URLs, WSGI/ASGI).
• media_app/media/ — Django “media” app: models (Media, Audio, Video, Radio), views, templates, static files (CSS/JS), admin customization, management commands.
• stream_backend/ — Rust Cargo project (main.rs, handlers.rs) running on port 8080.
• requirements.txt, Cargo.toml — Python and Rust dependencies.
• Key architectural patterns:
• Django MVT (Models → Views → Templates + static assets).
• Microservice style: separate HTTP streaming service in Rust.
• Shared Web Worker for cross‐tab communication and chunked streaming.
Extract Insights from README
• Two servers: Django on 127.0.0.1:8000 for UI/admin and static assets; Rust actix on 127.0.0.1:8080 for range‐based media streaming.
• Workflow: Admin adds media via Django management command → media files stored on disk + metadata in DB → user UI loads player page → Worker fetches media chunks from Rust service.
Main Components and Their Relationships
a. Browser / Frontend
• HTML templates and static JS/CSS served by Django.
• Shared Web Worker (worker.js) coordinates streaming across tabs.
• Player UI (player.html + player_handler.js).
b. Django Web App
• URL routing → views.py → templates / static.
• Admin interface for content management.
• Models ↔ Database (e.g., SQLite or Postgres).
• Management command add_media to scan FS and populate DB.
c. Media Storage
• File System (MEDIA_ROOT): raw audio/video files on disk.
d. Rust Actix Streaming Service
• HTTP range requests from Worker to /stream/{media_id}.
• Handlers read from FS and stream bytes.
e. Database
• Stores metadata: file paths, play counts, etc.
Architectural Patterns & Design Principles
• Separation of concerns: UI vs. metadata API vs. streaming.
• Microservice for heavy I/O (Rust) outside of Django process.
• Shared Web Worker for efficient resource usage (single stream for multiple tabs).
• Django MVT enforces clean layering of models, views, templates.
Essential Elements
• Clear labels: e.g., “Django App”, “Media DB”, “Media FS”, “Rust Streaming Service”, “Browser Web Worker”.