YT-DLP Web Player 是一款由 Matszwe02 开发的基于 Web 的视频播放器,利用开源工具 yt-dlp 进行视频解析和下载。其解决了在线视频播放体验中的一些痛点,例如跨平台兼容性、自定义功能扩展等。在现有的在线视频平台中,因为版权和用户体验的考量,用户难以实现下载或深度定制功能;而以 yt-dlp 为核心的 Web播放器则打破了这些限制,允许用户通过网络链接直接播放视频且支持下载。
核心技术揭秘
YT-DLP Web Player 的核心技术和实现手段令人印象深刻。项目主要采用了 Flask 框架作为后端 API,前端则由 Vue.js 构建,两者共同协作确保了视频播放的无缝体验。
graph TD
A[用户请求视频链接] --> B[Flask API 收到请求]
B --> C{"解析视频链接"}
C -->|"结果"| Z1[D[视频流信息]]
D --> E[Vue.js 前端展示]
E --> F{"播放/下载选项"}
F -->|"播放"| G[视频播放]
F -->|"下载"| H[视频下载]
功能亮点与差异
YT-DLP Web Player 提供了一个高度可定制和灵活的视频播放解决方案,这使其区别于市场上其他类型的在线视频播放器。它的主要亮点包括:
docker run -p 5000:5000 matszwe02/ytdlp_web_player:stable
stable version, ready for everyday use
docker run -p 5000:5000 matszwe02/ytdlp_web_player:latest
latest version - may have new and experimental features
Or with Docker Compose:
Clone the repo
Run docker compose up
For automatic app updates, see compose.yml
To enable environment:
Uncomment:
# env_file:
# - src/.env
Copy src/example.env to src/.env, modify as needed
Run locally (Python)
Create and activate a virtual environment in src/ and install requirements.txt
optionally install ffmpeg and node/deno, otherwise they will be automatically installed to your venv
run main.py
To enable environment:
Copy src/example.env to src/.env, modify as needed
PC Application (Windows / Linux)
Due to the packaging of necessary python modules, yt-dlp update may break on older builds when yt-dlp updates its dependencies. In this case a manual app update is necessary
All configurable options are environment variables, set in src/.env (copy src/example.env and uncomment what you want to change).
See src/example.env for the full list.
Hardware Acceleration
FFmpeg automatically detects the best supported hardware encoder. NVIDIA NVENC is used when available, and transcoding automatically falls back to CPU (libx264) when hardware acceleration is unavailable or fails.
For NVIDIA GPU acceleration in Docker, install the NVIDIA Container Toolkit, uncomment the build block that uses Dockerfile.hwaccel and gpus: all in compose.yml, then run docker compose up --build.
Cookies (video streaming sites authentication)
Some video streaming websites need you to be logged in. With cookies you will be logged in to these websites automatically while using the app.
Create a src/cookies.txt file and enable it in compose.yml (if using Docker)
Install an extension such as Get cookies.txt LOCALLY and activate it on the desired website when logged in
full guide and explanation can be found in yt-dlp’s wiki
Copy the cookies and paste them into that file
If using extension, you can instead enable automatic sending of browser cookies in extension settings, they will be used automatically
Keep in mind that cookies work the same way as your account credentials - anyone having them may mess up your account.
I do not guarantee that cookies file is completely secure from accessing it through the player. Additionally yt-dlp uses them when playing videos on behalf of the provided account. So I only recommend putting throwaway accounts here.
HTTPS and exposing it to the internet
Some features (like extension and PWA) require HTTPS to work.
If you don’t own any HTTPS proxy, the easiest solution is to set PUBLISH_WITH_CLOUDFLARE environment variable to true and access it through the generated cloudflare link. With this link you can also access this app from anywhere in the world, without the need of port forwarding.
Link is generated and visible in app logs just before app starts.
Note that it is a temporary link that changes each time this app starts. For a more robust way, you need to set up your own proxy with HTTPS certificate.
Security notes
This app fetches and transcodes arbitrary URLs on behalf of anyone who can reach it, and has no built-in authentication. It blocks requests to local network addresses where it can, but this is best-effort. It is adviced that if you expose it to the global network, you take appropriate safety precautions, like isolating its LAN from the rest of your network.
Extension
YT-DLP Web Player provides an extension that replaces every video in allowed (in extension settings) domains with YT-DLP Player. That results with all of the default video players to be seamlessly replaced with YT-DLP Player
This extension will disable all media playback on the website, disable native player and create YT-DLP Player’s iframe in its place
There are 3 ways of running this extension:
Browser Extension
Additionally adds Open in YT-DLP Player context menu for all links. So you can right-click any link and it is opened in YT-DLP Player directly
This player fully supports Open Graph - sharing it through social media and messaging apps shows video’s title, thumbnail, and allows for direct playback
Embedding player
If you want to embed this player, use /iframe?url=... endpoint
Troubleshooting
I can’t install PWA / embed it as an iframe / extension does not load
You need a working HTTPS for this, see in HTTPS and exposing it to the internet. Some features will work when you run through HTTP from localhost, but it may not work properly.
I can’t play some videos
Check whether the site is supported by yt-dlp here.
You can even try to download yt-dlp and download that video with it, to ensure there is a way to download it.
If it appears to be supported, file a bug report with app logs.
Can this app do XYZ?
This readme does not mention every configuration option. See src/example.env and check if the feature you want is already settable. If not, I’m open for feature requests.
Other issues
Please file a bug report. Attach browser and app logs if relevant, app version, browser name, etc.
评论