Skip to main content

MCP Video Download URL Parser

这是一个基于MCP的视频下载工具,支持从抖音、TikTok等平台下载无水印视频。

功能特点

  • 支持从抖音、TikTok、哔哩哔哩等平台下载无水印视频
  • 使用Playwright模拟浏览器环境,绕过网站的防爬措施
  • 自动提取视频标题和下载链接
  • 支持自定义下载路径
  • 支持作为MCP服务运行

安装依赖

# 安装Python依赖
uv pip install -r requirements.txt

# 安装Playwright浏览器
playwright install

使用方法

作为MCP服务运行

uv run --index-url https://mirrors.aliyun.com/pypi/simple/ main.py

然后可以通过MCP调用download_video函数:

# MCP调用示例
result = await mcp_video_url_parser_download_video(url="https://v.douyin.com/your_video_id/", output_path="D:\\视频")

直接使用测试脚本

# 使用默认测试URL
uv run direct_test.py

# 指定视频URL
uv run direct_test.py "https://v.douyin.com/your_video_id/"

技术实现

本工具使用了两种方式来提取视频URL:

  1. Playwright模拟浏览器(主要方法):

    • 完全模拟真实浏览器环境
    • 自动访问snapany.com网站
    • 输入视频链接并点击提取按钮
    • 监听API响应或直接从页面提取视频元素
    • 绕过网站的防爬措施,如请求头验证、Cookie验证等
  2. API直接请求(备用方法):

    • 直接向snapany.com的API发送请求
    • 添加必要的请求头和参数
    • 处理多种可能的响应格式

防爬措施解决方案

snapany.com网站有严格的防爬措施,包括:

  1. 请求头验证:需要特定的请求头,如g-timestamp和g-footer
  2. Cookie验证:需要有效的会话Cookie
  3. 浏览器指纹:检查浏览器环境、Canvas指纹等
  4. 动态签名生成:可能基于多种因素动态生成签名

我们通过使用Playwright完全模拟浏览器环境,成功绕过了这些防爬措施。Playwright提供了真实的浏览器环境,包括JavaScript执行、Cookie管理和请求拦截等功能,使我们能够像真实用户一样与网站交互。

注意事项

  • 本工具仅用于学习和研究目的
  • 请遵守相关平台的使用条款和版权规定
  • 不要过于频繁地使用,以避免对目标网站造成压力

安装和执行

通过Smithery安装

要通过Smithery为Claude Desktop自动安装MCP Video Download URL Parser:

npx -y @smithery/cli install @tansunyj/mcp_video_download_url_parser --client claude

手动安装

  1. 克隆仓库:git clone https://github.com/tansunyj/mcp_video_download_url_parser.git
  2. 进入目录:cd mcp_video_download_url_parser
  3. 安装依赖:pip install -r requirements.txt
  4. 启动MCP服务器:python main.py

配置Claude Desktop或Cursor

  1. 添加以下配置:
{
    "mcpServers": {
        "video-url-parser": {
            "command": "python",
            "args": [
                "/path/to/mcp_video_download_url_parser/main.py"
            ],
            "env": {}
        }
    }
}

在魔塔社区(Cursor)部署配置

要在魔塔社区上部署此MCP服务,请按照以下步骤操作:

  1. 上传项目:将项目上传到魔塔社区平台

  2. 配置服务:在魔塔社区控制台中,找到"MCP服务配置"部分,添加以下配置信息:

{
  "name": "video-url-parser",
  "description": "视频下载解析工具",
  "version": "1.0.0",
  "main": "main.py",
  "requirements": ["playwright", "asyncio", "aiohttp", "beautifulsoup4"],
  "environmentVariables": {
    "DOWNLOAD_PATH": "./downloads"
  }
}
  1. 开启服务:在魔塔社区控制台中,找到已添加的服务,点击"开启服务"按钮

  2. 服务调用:在魔塔社区中,可以通过以下方式调用该服务:

# 调用示例
result = await mcp_video_url_parser_download_video(
    url="https://v.douyin.com/your_video_id/", 
    output_path="指定保存路径"
)
  1. 常见问题排查:
    • 确保所有依赖项都已正确安装
    • 检查环境变量是否正确配置
    • 若出现网络问题,请确认服务器能够访问视频平台网站
    • 若服务无法启动,检查日志获取详细错误信息

使用示例

配置完成后,可以使用如下提示:

  • "下载这个视频:[video_url]"
  • "将这个视频保存到D:/videos目录:[video_url]"

环境变量

  • DOWNLOAD_PATH:保存下载视频的路径(默认:./downloads)

开发

要参与开发:

git clone https://github.com/tansunyj/mcp_video_download_url_parser.git
cd mcp_video_download_url_parser
python -m pytest tests/

安全性

此MCP服务器在您的本地机器上运行。虽然它不执行任意代码,但在解析来自不受信任来源的URL时请小心。

致谢

本项目使用SnapAny.com的API进行视频解析和下载。

许可证

MIT许可证


GitHub repo

Metadata

Release files for mcp-video-download-url-parser 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-video-download-url-parser 0.1.0
File Size Uploaded Provenance
mcp_video_download_url_parser-0.1.0.tar.gz 131.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-video-download-url-parser 0.1.0
File Interpreter ABI Platform
mcp_video_download_url_parser-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 142.2 kB

Release files / mcp_video_download_url_parser-0.1.0.tar.gz

Download URL mcp_video_download_url_parser-0.1.0.tar.gz
Size 131.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cf99f3dc2dc90148ad2c36954639df9fd8ba4eaa3db2cbdd4a0fade7557125e1
BLAKE2b-256 checksum
How to use checksums
21485e1d0f97e6a7879c8da45125e192d03af512d7860548712b45b7d492427f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.7

Release files / mcp_video_download_url_parser-0.1.0-py3-none-any.whl

Download URL mcp_video_download_url_parser-0.1.0-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2e33752a1c5990d5f1f73a394ce00bdf403e5bf8c155f2b845dce76bc4a1f199
BLAKE2b-256 checksum
How to use checksums
36adee14e8c19bc50680f1135a02af37fb721506e84ccf2f3b4bdf1153f86604
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.7

Security for mcp-video-download-url-parser 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page