LibreTV

repository·main·Indexed 12 days ago

https://github.com/librespark/libretv

A free online video search and viewing platform featuring an integrated player system. It supports the Apple CMS V10 API format for custom video sources, provides a Node.js-based backend proxy, and can be deployed via Docker or Docker Compose. Key features include custom API management, content filtering, and a built-in player with keyboard shortcuts.

Tokens
4.3K
Snippets
10
Records
24
Agent score
96%

What's inside LibreTV

  1. Deploy LibreTV via Docker Compose

    main

    Use the following docker-compose.yml configuration to manage your LibreTV instance. You can customize the PASSWORD variable in the environment section.

    To start the service, run:

    docker compose up -d

    After starting, access the application at http://localhost:8899.

    services:
      libretv:
        image: bestzwei/libretv:latest
        container_name: libretv
        ports:
          - "8899:8080" # Maps internal 8080 to host 8899
        environment:
          - PASSWORD=${PASSWORD:-111111} # Defaults to 111111 if not provided
        restart: unless-stopped
  2. Set up a local development environment

    main

    LibreTV requires a Node.js environment to support its backend proxy features. Note that using simple static servers (like python -m http.server) will break video proxy functionality and prevent playback.

    Follow these steps to set up development:

    1. Copy the example environment file:
      cp .env.example .env
    2. Install dependencies:
      npm install
    3. Start the development server:
      npm run dev

    Access the app at http://localhost:8080. You can change the port by modifying the PORT variable in your .env file.

    # Set up .env file
    cp .env.example .env
    
    # Install dependencies
    npm install
    
    # Start development server
    npm run dev
  3. Deploy LibreTV via Docker

    main

    You can run LibreTV as a containerized application using Docker or Docker Compose. By default, the application listens on port 8889 (mapped from internal 8080).

    Important: You must set the PASSWORD environment variable to secure your instance.

    docker run -d \
      --name libretv \
      --restart unless-stopped \
      -p 8899:8080 \
      -e PASSWORD=your_password \
      bestzwei/libretv:latest
  4. Configure custom CMS API sources

    main

    LibreTV supports the standard Apple CMS V10 API format. To add a custom source, navigate to the settings panel in the UI and select Custom Interface (自定义接口).

    Required API Format:

    • Search Interface: https://example.com/api.php/provide/vod/?ac=videolist&wd={keyword}
    • Detail Interface: https://example.com/api.php/provide/vod/?ac=detail&ids={video_id}

    When adding the source in the settings panel, use the base URL: https://example.com/api.php/provide/vod

  5. Configure API selection and filtering

    main

    The application manages which video sources are queried using the selectedAPIs array, stored in localStorage.

    API Selection

    • Built-in APIs: Identified by their unique keys in the API_SITES object.
    • Custom APIs: Identified by the prefix custom_ followed by their index in the customAPIs array (e.g., custom_0, custom_1).

    Content Filtering

    • Yellow Content Filter: Controlled by the yellowFilterEnabled key in localStorage. When true, the search results are filtered against a list of banned keywords (e.g., '伦理片', '福利', '无码').
    • Adult API Restriction: If any API marked as adult is selected, the yellowFilterEnabled setting is automatically disabled and the toggle is locked to prevent conflicts.
    • Ad Filtering: Controlled by the key defined in PLAYER_CONFIG.adFilteringStorage (defaults to true).
  6. How LibreTV handles page rendering and passwords

    main

    LibreTV uses a template replacement mechanism to inject security credentials into static HTML files.

    When the server serves index.html or player.html, it looks for the placeholder {{PASSWORD}} within the file content.

    • If PASSWORD is configured in the environment, {{PASSWORD}} is replaced with the SHA-256 hash of that password.
    • If PASSWORD is empty, {{PASSWORD}} is replaced with an empty string.

    This allows the client-side application to perform authenticated requests (like using the proxy) by knowing the expected hash without the raw password being exposed in the source code.

  7. Manage custom API sources

    main

    LibreTV allows users to add, edit, and remove custom video API sources. Custom APIs are stored in localStorage under the key customAPIs. Each custom API object can include a name, url, detail (an optional parameter passed to the backend), and an isAdult flag.

    Custom API Object Schema

    When interacting with the system or inspecting localStorage, a custom API follows this structure:

    • name: String. The display name of the API.
    • url: String. The base URL of the API.
    • detail: String (optional). An additional parameter sent to the /api/detail endpoint.
    • isAdult: Boolean. If true, the API is categorized as adult content.

    To add a custom API via the UI, use addCustomApi(). To remove one, use removeCustomApi(index) where index is the position in the customAPIs array.

    // Example of a custom API object structure
    {
      "name": "My Custom Source",
      "url": "https://example.com/api",
      "detail": "some_detail_param",
      "isAdult": false
    }
  8. Deploy LibreTV using Docker Compose

    main

    You can deploy LibreTV using a docker-compose.yml file. The service runs the bestzwei/libretv:latest image and maps the internal port 8080 to the host port 8899 by default.

    To customize the deployment, you can use environment variables for the access password and configure a bind mount for persistent data storage.

    services:
      libretv:
        image: bestzwei/libretv:latest
        container_name: libretv
        ports:
          - "8899:8080"
        environment:
          - PASSWORD=${PASSWORD:-your_password}
        restart: unless-stopped
    
    volumes:
      libretv_data:
        driver: local
        driver_opts:
          type: none
          o: bind
          device: ${PWD:-.}/data
  9. Configure LibreTV server environment variables

    main

    The LibreTV backend server is configured via environment variables. These settings control security, proxy behavior, and server performance.

    Core Configuration

    • PORT: The port the server listens on (default: 8080).
    • PASSWORD: The password used for page rendering and proxy authentication. If set, the server will hash this value and inject it into HTML templates.
    • CORS_ORIGIN: Allowed origins for CORS requests (default: *).
    • DEBUG: Set to true to enable debug logging.

    Proxy & Security Configuration

    • REQUEST_TIMEOUT: Timeout for outgoing proxy requests in milliseconds (default: 5000).
    • MAX_RETRIES: Number of retries for failed proxy requests (default: 2).
    • CACHE_MAX_AGE: Cache duration for static files (default: 1d).
    • USER_AGENT: Custom User-Agent string for proxy requests.
    • BLOCKED_HOSTS: A comma-separated list of hostnames to prevent the proxy from accessing (e.g., localhost,127.0.0.1).
    • BLOCKED_IP_PREFIXES: A comma-separated list of IP prefixes to block (e.g., 192.168.,10.).
    • FILTERED_HEADERS: A comma-separated list of response headers to strip from proxied requests (default: content-security-policy,cookie,set-cookie,x-frame-options,access-control-allow-origin).
  10. Configure LibreTV persistent data storage via Docker volumes

    main

    To ensure data persistence, use a named volume with a bind mount. This maps the internal /app directory to a specific directory on your host machine.

    In the provided configuration, the libretv_data volume uses the local driver with bind options to point to a ./data folder in the current working directory.

    Configuration details:

    • Internal path: /app (do not modify this inside the container)
    • Host device path: ${PWD:-.}/data (you can change this to any path you prefer)
    services:
      libretv:
        volumes:
          - libretv_data:/app
    
    volumes:
      libretv_data:
        driver: local
        driver_opts:
          type: none
          o: bind
          device: ${PWD:-.}/data
  11. Configure LibreTV Docker port mapping

    main

    The LibreTV container listens on port 8080 internally. In the default docker-compose.yml configuration, this is mapped to host port 8899.

    To change the port you use to access the application, modify the ports section:

    ports:
      - "<HOST_PORT>:8080"