FastAPI IPTV Service

A FastAPI application for managing IPTV content delivery, including playlist and EPG management, user authentication, and content serving. It uses Redis for user management, Vercel Blob Storage for content storage, and provides a secure way to serve IPTV playlists and EPG files.

Features

  • IPTV playlist (.m3u/.m3u8) and EPG (.xml/.xml.gz) file hosting
  • Secure content delivery with user authentication
  • Admin interface for content and user management
  • Health check endpoint (/health)
  • Interactive API documentation
  • Redis-based user management
  • Vercel Blob Storage integration
  • Dockerized deployment support
  • Static frontend for service information

Prerequisites

  • Python 3.12+
  • uv (for dependency management)
  • Docker (optional)
  • Redis instance (local or Upstash)
  • Vercel Blob Storage account

Installation

Manual Installation

  1. Clone the repository:

    git clone <repository-url>
    cd <repository-directory>
    
  2. Install dependencies:

    pip install uv
    uv sync
    
  3. Configure Environment Variables: Create a .env file:

    SUPER_ADMIN_USER=admin
    SUPER_ADMIN_PASSWORD=adminpassword
    USE_LOCAL_REDIS=true
    LOCAL_REDIS_URL=redis://localhost:6379
    KV_REST_API_TOKEN=your_upstash_token
    KV_REST_API_URL=your_upstash_url
    BLOB_READ_WRITE_TOKEN=your_vercel_blob_token
    CONTENT_PATH=./content
    

Docker Installation

  1. Build the image:

    docker build -t iptv-server .
    
  2. Run with Docker:

    docker run -d \
      --name iptv-server \
      -p 8000:8000 \
      -v ./content:/content \
      --env-file .env \
      iptv-server
    

API Endpoints

Admin Endpoints

  • POST /admin/register - Register new users (superadmin only)
  • DELETE /admin/users/{username} - Delete users (superadmin only)
  • POST /admin/playlist - Upload playlist files
  • DELETE /admin/playlist/{filename} - Delete playlist files
  • POST /admin/epg - Upload EPG files
  • DELETE /admin/epg/{filename} - Delete EPG files

Content Endpoints

  • GET /content/playlist/{filename} - Access playlist files (authenticated)
  • GET /content/epg/{filename} - Access EPG files (authenticated)

Other Endpoints

  • GET /health - Service health check
  • GET /docs - Swagger UI documentation
  • GET /redoc - ReDoc documentation

Authentication

The service uses HTTP Basic Authentication with two levels:

  1. Superadmin Authentication: Required for admin operations (user management, content uploads)
  2. User Authentication: Required for accessing content

Authentication can be provided via:

  • HTTP Basic Auth headers
  • Query parameters (for IPTV player compatibility)

Storage

  • User Data: Stored in Redis (local or Upstash)
  • Content Files: Stored in Vercel Blob Storage
  • Static Files: Served from local filesystem

Project Structure

src/
├── main.py           # Application entry point
├── config.py         # Configuration management
├── models/           # Data models
├── routers/          # API routes
│   ├── admin.py      # Admin endpoints
│   └── content.py    # Content serving endpoints
├── static/           # Static frontend files
└── utils/            # Utility functions
    ├── admin.py      # Admin operations
    ├── auth.py       # Authentication
    └── database.py   # Database operations

Development

Run the development server:

uvicorn src.main:app --host 0.0.0.0 --port 8000 --reload

License

MIT License - See LICENSE file for details.

Description
No description provided
Readme MIT 221 KiB
Languages
Python 81.2%
HTML 17.1%
Dockerfile 1.7%