MoonTVPlus Documentation

repository·main·Indexed 25 days ago

https://github.com/mtvpls/moontvplus

An enhanced video aggregation player based on MoonTV v100. Features include external player support, WebGPU-powered video super-resolution (Anime4K), bullet chat systems, Douban comment scraping, and custom source scripting. Built with Next.js 14, Tailwind CSS, and TypeScript, it supports deployment via Docker, Cloudflare Workers, and EdgeOne Pages, with an optional Android TV WebView shell.

Tokens
14.8K
Snippets
9
Records
77
Agent score
84%

What's inside MoonTVPlus

  1. Overview of MoonTVPlus

    main

    MoonTVPlus is an enhanced video aggregation player developed based on MoonTV v100. It provides a powerful viewing experience with features like external player support, video super-resolution, bullet chat (danmaku) systems, and Douban comment scraping.

    Important Note: Upon deployment, the project is a 'shell'—it does not include built-in video or live stream sources. Users must collect and provide their own sources.

  2. Understand MoonTVPlus Android TV build variants

    main

    The project provides two main engine types and two compatibility levels:

    Engine Types

    • webview: Uses the system's built-in Android WebView. This results in a smaller APK size but depends on the device's installed WebView version. The User-Agent for these builds includes MoonTVPlusAndroidTV WebView.
    • gecko: Includes the GeckoView browser engine. Use this if the system WebView is too old to support the Next.js pages used by MoonTVPlus.

    Compatibility Levels

    • android6plus: Targets MIN_SDK 23 (Android 6+).
    • android5plus: Targets MIN_SDK 21 (Android 5+).

    Key Features

    • Locked to landscape mode.
    • Supports Android TV Launcher.
    • Allows plain HTTP access.
    • Allows mixed content (loading HTTP video/images on HTTPS pages).
  3. MoonTVPlus Key Features

    main

    MoonTVPlus includes several advanced features for an enhanced media experience:

    • External Player Support: Jump to players like PotPlayer, VLC, MPV, MX Player, nPlayer, and IINA.
    • Video Super-Resolution (Anime4K): Real-time video quality enhancement using WebGPU (supports 1.5x, 2x, 3x, and 4x super-resolution).
    • Bullet Chat (Danmaku) System: Search, match, and load bullet chats with persistence and blocking support.
    • Douban Comment Scraping: Automatically fetches and displays Douban movie short reviews with pagination.
    • Custom Video Source Scripts: (Experimental) Define custom logic for video sources, searching, details, and playback parsing.
    • Custom Ad-Blocking: Ability to write custom code for enhanced ad-blocking.
    • Watch Room: (Experimental) Supports multi-person synchronized viewing, real-time chat, and voice calls.
    • M3U8 Downloads: Supports merging m3u8 fragments for browser-based downloading or local playback.
    • Server-side Offline Download: Supports downloading video files to the server with breakpoint resume support.
    • Private Library: Integration with OpenList, Emby, or Xiaoya to create a personal media library.
    • Multi-source Aggregated Search: Returns results from all sources in a single search.
    • PWA Support: Offline caching and installation as a desktop/home screen app for a native mobile experience.
    • Smart Ad-Skipping: Automatically skips slice ads in videos.
  4. Write a video source script for MoonTVPlus

    main

    To add a new video source, you must implement a script that returns an object containing specific lifecycle hooks. The script must follow a specific structure to handle source management, searching, recommendations, details, and URL resolution.

    return {
      meta: {
        name: '示例脚本',
        author: 'admin'
      },
    
      async getSources(ctx) {
        return [{ id: 'default', name: '默认源' }];
      },
    
      async search(ctx, { keyword, page, sourceId }) {
        return {
          list: [],
          page,
          pageCount: 1,
          total: 0
        };
      },
    
      async recommend(ctx, { page }) {
        return {
          list: [],
          page: page || 1,
          pageCount: 1,
          total: 0
        };
      },
    
      async detail(ctx, { id, sourceId }) {
        return {
          id,
          title: '',
          poster: '',
          year: '',
          desc: '',
          playbacks: [
            {
              sourceId,
              sourceName: '默认源',
              episodes: [],
              episodes_titles: []
            }
          ]
        };
      },
    
      async resolvePlayUrl(ctx, { playUrl, sourceId, episodeIndex }) {
        return {
          url: playUrl,
          type: 'auto',
          headers: {}
        };
      }
    };
  5. Deploy to EdgeOne Pages via GitHub Actions

    main

    Deploy MoonTVPlus to Tencent Cloud EdgeOne Pages using automated GitHub Actions. This requires an EdgeOne account and either a Turso or Upstash Redis instance.

    1. Prerequisites

    • Tencent Cloud EdgeOne account
    • Forked repository on GitHub
    • EdgeOne API Token
    • Turso (recommended) or Upstash Redis instance

    2. Configuration

    Add the following secrets to your GitHub repository:

    Required Secrets:

    • EDGEONE_API_TOKEN: Your EdgeOne API Token.
    • USERNAME: Admin username.
    • PASSWORD: Admin password.
    • NEXT_PUBLIC_STORAGE_TYPE: Set to turso or upstash.

    If using Turso:

    • TURSO_URL: Your Turso database URL (e.g., libsql://your-db.turso.io).
    • TURSO_TOKEN: Your Turso access token.
    • Note: Run pnpm init:turso to initialize the schema (requires TURSO_URL and TURSO_TOKEN env vars).

    If using Upstash:

    • UPSTASH_URL: Your Upstash Redis URL.
    • UPSTASH_TOKEN: Your Upstash Redis token.

    3. Deployment

    • Go to the Actions tab and select the Deploy to EdgeOne workflow.
    • Click Run workflow.
    • project_name defaults to moontvplus.
    • area defaults to overseas (global, excluding mainland China); use global for all regions.
    • sync_environment is enabled by default to sync secrets to the EdgeOne project.
  6. Configure Telegram Bot and Webhook

    main

    To enable Telegram integration (login, binding, and notifications), follow these steps:

    1. Create a bot via @BotFather in Telegram to obtain TELEGRAM_BOT_TOKEN and your bot's username.
    2. Set the following environment variables and restart the service:
      • TELEGRAM_BOT_TOKEN
      • TELEGRAM_BOT_USERNAME
      • TELEGRAM_WEBHOOK_SECRET (a random long string).
    3. If your server cannot connect directly to Telegram, configure TELEGRAM_API_PROXY (system proxy) or TELEGRAM_API_BASE_URL (reverse proxy base URL).
    4. Set the Webhook. You can use the 'One-click Webhook Setup' in the Telegram Bot admin page, or manually call the Telegram API using the command below.
  7. Deploy via Docker Compose

    main

    MoonTVPlus can be deployed using Docker with several storage backends. Choose the backend that fits your needs.

    Uses Apache Kvrocks for storage. Ensure the mounted data directory has 777 permissions to avoid database creation failures.

    services:
      moontv-core:
        image: ghcr.io/mtvpls/moontvplus:latest
        container_name: moontv-core
        restart: on-failure
        ports:
          - '3000:3000'
        environment:
          - USERNAME=admin
          - PASSWORD=admin_password
          - NEXT_PUBLIC_STORAGE_TYPE=kvrocks
          - KVROCKS_URL=redis://moontv-kvrocks:6666
        networks:
          - moontv-network
        depends_on:
          - moontv-kvrocks
      moontv-kvrocks:
        image: apache/kvrocks
        container_name: moontv-kvrocks
        restart: unless-stopped
        volumes:
          - kvrocks-data:/var/lib/kvrocks/db
        networks:
          - moontv-network
    networks:
      moontv-network:
        driver: bridge
    volumes:
      kvrocks-data:

    Option 2: SQLite (D1 compatible)

    Uses a local SQLite file. Requires a volume mount for persistence.

    services:
      moontv-core:
        image: ghcr.io/mtvpls/moontvplus:latest
        container_name: moontv-core
        restart: on-failure
        ports:
          - '3000:3000'
        environment:
          - USERNAME=admin
          - PASSWORD=admin_password
          - NEXT_PUBLIC_STORAGE_TYPE=d1
          - SQLITE_DB_PATH=/app/.data/moontv.db
        volumes:
          - ./data:/app/.data

    Option 3: Redis

    Note: There is a risk of data loss if persistence is not configured.

    services:
      moontv-core:
        image: ghcr.io/mtvpls/moontvplus:latest
        container_name: moontv-core
        restart: on-failure
        ports:
          - '3000:3000'
        environment:
          - USERNAME=admin
          - PASSWORD=admin_password
          - NEXT_PUBLIC_STORAGE_TYPE=redis
          - REDIS_URL=redis://moontv-redis:6379
        networks:
          - moontv-network
        depends_on:
          - moontv-redis
      moontv-redis:
        image: redis:alpine
        container_name: moontv-redis
        restart: unless-stopped
        networks:
          - moontv-network
        volumes:
          - ./data:/data
    networks:
      moontv-network:
        driver: bridge

    Option 4: Upstash

    Requires an Upstash Redis instance.

    services:
      moontv-core:
        image: ghcr.io/mtvpls/moontvplus:latest
        container_name: moontv-core
        restart: on-failure
        ports:
          - '3000:3000'
        environment:
          - USERNAME=admin
          - PASSWORD=admin_password
          - NEXT_PUBLIC_STORAGE_TYPE=upstash
          - UPSTASH_URL=YOUR_UPSTASH_HTTPS_ENDPOINT
          - UPSTASH_TOKEN=YOUR_UPSTASH_TOKEN

    Lite Image

    Use ghcr.io/mtvpls/moontvplus-lite:latest for a smaller footprint. Limitations:

    • Does not support the built-in viewing room service.
    • Does not support SQLite (NEXT_PUBLIC_STORAGE_TYPE=d1) automatic initialization.
  8. Build MoonTVPlus Android TV locally

    main

    To build the application locally using Gradle, use the assemble tasks and pass the BASE_URL parameter.

    For a system WebView build:

    gradle assembleWebviewDebug -PBASE_URL="http://192.168.1.10:3000"

    For a GeckoView engine build:

    gradle assembleGeckoDebug -PBASE_URL="http://192.168.1.10:3000"
    gradle assembleWebviewDebug -PBASE_URL="http://192.168.1.10:3000"
    gradle assembleGeckoDebug -PBASE_URL="http://192.168.1.10:3000"
  9. Automatically update MoonTVPlus containers

    main

    To keep your MoonTVPlus deployment up to date, you can use automated container update tools:

    • Watchtower: Use watchtower to automatically update your image containers.
    • Docker Compose UIs: Tools like dockge or komodo include built-in features for automatic updates.
  10. Deploy an external Watch Room server

    main

    If you are deploying MoonTVPlus on platforms like Vercel that do not support WebSocket servers, or if you want to host the Watch Room independently, you must use an external server. It is recommended to use the watch-room-server project.

    Configuration Steps:

    1. Deploy the external server following the watch-room-server documentation.
    2. Set the following environment variables in your MoonTVPlus deployment:
    WATCH_ROOM_ENABLED=true
    WATCH_ROOM_SERVER_TYPE=external
    WATCH_ROOM_EXTERNAL_SERVER_URL=wss://your-watch-room-server.com
    WATCH_ROOM_EXTERNAL_SERVER_AUTH=your_secure_token
    1. Restart your MoonTVPlus application.