Downloader TikTok Videos
Overview
Downloader TikTok Videos downloads the latest video (or multiple videos) from a public TikTok
account using yt-dlp. Read this documentation fully before writing any code or running commands.
Prerequisites
This skill requires yt-dlp (and optionally ffmpeg for audio/video merging).
⚠️ The commands below modify your host environment (install packages system-wide).
Run them only if yt-dlp is not already installed and you are comfortable doing so.
CODEBLOCK0
Operation Types
This skill supports four operation types. Determine which one(s) the user needs:
- 1. Quick Download — Download the latest video from an account
- Bulk Download — Download the N most recent videos
- Metadata Only — Retrieve info/stats without downloading the video
- Direct Video URL — Download from a specific video URL
Workflows
1. Quick Download — Latest Video from an Account
When to use: User provides a @username or profile URL
Steps:
- 1. Normalize the username (strip
@ if present) - Build the profile URL: INLINECODE1
- Fetch metadata for the latest video (
--playlist-items 1 --no-download) - Show the user the video info (title, date, duration)
- Download with the optimal command
- Confirm success and provide the file path
Command:
CODEBLOCK1
Verify the result:
CODEBLOCK2
2. Bulk Download — N Most Recent Videos
When to use: User wants multiple videos
Steps:
- 1. Ask how many videos (if not specified, default = 5)
- Build the command with INLINECODE3
- Add
--download-archive to avoid duplicates - Download with progress output
- List downloaded files
Command:
CODEBLOCK3
3. Metadata Only
When to use: User wants video info without downloading
Read: references/metadata.md for all available fields and the full command
Quick command:
CODEBLOCK4
4. Direct Video URL
When to use: User provides a direct video URL
Command:
CODEBLOCK5
Common Errors
| Error | Cause | Fix |
|---|
| INLINECODE6 | TikTok rate limiting | Add INLINECODE7 |
| INLINECODE8 |
Outdated yt-dlp |
pip install -U yt-dlp --break-system-packages |
|
Private account | Private account | Use
--cookies-from-browser chrome if logged in ⚠️ exports session cookies — keep them private |
|
No video formats | Geo-restriction | Add
--geo-bypass |
|
Sign in required | Restricted content | Provide cookies via
--cookies cookies.txt ⚠️ treat this file like a password |
|
Merge requires ffmpeg | ffmpeg missing |
apt-get install ffmpeg -y |
⚠️ Cookie security note: Browser cookies exported via --cookies-from-browser or cookies.txt
contain active session tokens. Never share these files, commit them to version control, or pass
them to untrusted scripts. Delete them after use if no longer needed.
Username Normalization
CODEBLOCK6
Reference Files
Load these references as needed:
references/metadata.md
- - When: Fetching metadata, working with JSON fields
- Contains: All available yt-dlp fields, print format examples, JSON export
references/advanced.md
- - When: Watermark removal, cookies, proxy, custom headers
- Contains: Advanced techniques, restriction bypass, full yt-dlp options
KBLICENSE.txt
- - When: Questions about usage rights or Terms of Service
- Contains: Usage conditions, permitted and prohibited uses
Output Guidelines
- - Always display metadata before downloading (title, date, duration)
- Confirm the downloaded file path
- Show the final file size
- On error, propose the fix directly
Example Queries
Quick download:
- - "Download the latest video from @someaccount"
- "Get the latest TikTok post from myaccount"
- "Download the last video from https://www.tiktok.com/@user"
Bulk download:
- - "Download the 5 latest videos from @user"
- "Get the last 10 videos from @account"
Metadata:
- - "Give me the info on the latest video from @user"
- "What is the title and date of the last post from @account"
Direct URL:
- - "Download this TikTok video: https://www.tiktok.com/@user/video/123456"
下载器 TikTok 视频
概述
下载器 TikTok 视频使用 yt-dlp 从公开 TikTok 账号下载最新视频(或多个视频)。在编写任何代码或运行命令之前,请完整阅读本文档。
前置条件
此技能需要 yt-dlp(以及可选的 ffmpeg 用于音视频合并)。
⚠️ 以下命令会修改您的主机环境(系统范围安装软件包)。
仅在 yt-dlp 尚未安装且您愿意执行的情况下运行。
bash
pip install -U yt-dlp --break-system-packages # Linux 系统 Python
或
pip install -U yt-dlp # virtualenv / macOS
yt-dlp --version # 验证安装
操作类型
此技能支持四种操作类型。确定用户需要哪一种:
- 1. 快速下载 — 下载账号的最新视频
- 批量下载 — 下载最新的 N 个视频
- 仅元数据 — 获取信息/统计数据而不下载视频
- 直接视频链接 — 从特定视频链接下载
工作流程
1. 快速下载 — 账号最新视频
使用场景: 用户提供 @用户名 或个人资料链接
步骤:
- 1. 规范化用户名(去除 @ 如果存在)
- 构建个人资料链接:https://www.tiktok.com/@{username}
- 获取最新视频的元数据(--playlist-items 1 --no-download)
- 向用户展示视频信息(标题、日期、时长)
- 使用最佳命令下载
- 确认成功并提供文件路径
命令:
bash
yt-dlp \
--playlist-items 1 \
--format bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best \
--merge-output-format mp4 \
--output ./%(uploaderid)s%(uploaddate)s%(id)s.%(ext)s \
https://www.tiktok.com/@{username}
验证结果:
bash
ls -lh ./*.mp4
2. 批量下载 — 最新的 N 个视频
使用场景: 用户想要多个视频
步骤:
- 1. 询问视频数量(如果未指定,默认 = 5)
- 使用 --playlist-items 1-N 构建命令
- 添加 --download-archive 以避免重复
- 显示下载进度
- 列出下载的文件
命令:
bash
yt-dlp \
--playlist-items 1-{N} \
--format bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best \
--merge-output-format mp4 \
--download-archive ./tiktok_archive.txt \
--output ./%(uploaderid)s/%(uploaddate)s_%(id)s.%(ext)s \
https://www.tiktok.com/@{username}
3. 仅元数据
使用场景: 用户想要视频信息而不下载
阅读: references/metadata.md 获取所有可用字段和完整命令
快速命令:
bash
yt-dlp \
--playlist-items 1 \
--skip-download \
--write-info-json \
--print %(uploaderid)s | %(uploaddate)s | %(duration)ss | %(view_count)s views | %(title)s \
https://www.tiktok.com/@{username}
4. 直接视频链接
使用场景: 用户提供直接视频链接
命令:
bash
yt-dlp \
--format bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best \
--merge-output-format mp4 \
--output ./%(uploaderid)s%(id)s.%(ext)s \
{video_url}
常见错误
| 错误 | 原因 | 修复 |
|---|
| HTTP Error 403 | TikTok 速率限制 | 添加 --sleep-interval 3 --max-sleep-interval 6 |
| Unable to extract |
yt-dlp 版本过旧 | pip install -U yt-dlp --break-system-packages |
| Private account | 私密账号 | 如果已登录,使用 --cookies-from-browser chrome ⚠️ 导出会话 cookie — 请保密 |
| No video formats | 地理限制 | 添加 --geo-bypass |
| Sign in required | 受限内容 | 通过 --cookies cookies.txt 提供 cookie ⚠️ 将此文件视为密码 |
| Merge requires ffmpeg | 缺少 ffmpeg | apt-get install ffmpeg -y |
⚠️ Cookie 安全提示: 通过 --cookies-from-browser 或 cookies.txt 导出的浏览器 cookie 包含活跃的会话令牌。切勿共享这些文件、将其提交到版本控制或传递给不可信的脚本。如果不再需要,请在使用后删除。
用户名规范化
python
接受所有以下格式:
@myaccount → myaccount
myaccount → myaccount
https://www.tiktok.com/@myaccount → myaccount
def normalize(input_str):
if tiktok.com/@ in input_str:
return input_str.split(tiktok.com/@)[-1].split(/)[0]
return input_str.lstrip(@).strip()
参考文件
根据需要加载这些参考文件:
references/metadata.md
- - 使用场景:获取元数据、处理 JSON 字段
- 包含:所有可用的 yt-dlp 字段、打印格式示例、JSON 导出
references/advanced.md
- - 使用场景:去除水印、cookie、代理、自定义请求头
- 包含:高级技术、绕过限制、完整的 yt-dlp 选项
KBLICENSE.txt
- - 使用场景:关于使用权限或服务条款的问题
- 包含:使用条件、允许和禁止的使用方式
输出指南
- - 始终在下载前显示元数据(标题、日期、时长)
- 确认下载的文件路径
- 显示最终文件大小
- 出现错误时,直接提出修复方案
示例查询
快速下载:
- - 下载 @someaccount 的最新视频
- 获取 myaccount 的最新 TikTok 帖子
- 下载 https://www.tiktok.com/@user 的最新视频
批量下载:
- - 下载 @user 的 5 个最新视频
- 获取 @account 的最后 10 个视频
元数据:
- - 给我 @user 最新视频的信息
- @account 最后帖子的标题和日期是什么
直接链接:
- - 下载这个 TikTok 视频:https://www.tiktok.com/@user/video/123456