Files
hmo 04db423416 Initial commit: skills library
- 70 skills with code and documentation
- Add .gitignore (ignore __pycache__, output/, temp/, venv/)
- Clean up test intermediates and caches
2026-04-26 19:27:40 +08:00

180 lines
4.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
name: youtube-downloader
description: 使用 Savenow API 下载 YouTube 视频/音频。调用第三方 API 直接获取下载链接,无需 cookies。当用户提到下载 YouTube、视频下载、YT 下载时触发此技能。
---
# YouTube Downloader Skill
使用 Savenow API 下载 YouTube 视频/音频的技能。
## 概述
- **API 来源**: 从 Chrome 插件 "Youtube Tools All in one" (Tampermonkey 脚本) 提取
- **API 服务**: savenow.to / lbserver.xyz
- **API Key**: `dfcb6d76f2f6a9894gjkege8a4ab232222` (来自插件内置)
- **无需 cookies**: 直接通过 API 调用,无需登录验证
- **稳定性**: 已验证可用,视频和音频都能下载
## 适用场景
- 下载 YouTube 视频(mp4, webm 等格式)
- 下载 YouTube 音频(mp3, flac, m4a 等格式)
- 无需 cookies / 登录验证
## 核心参数
- **API Base**: `https://p.savenow.to``https://p.lbserver.xyz`
- **API Key**: `dfcb6d76f2f6a9894gjkege8a4ab232222` (来自 Tampermonkey 插件 Youtube Tools All in one)
- **备用 API**: `https://dub.io` (通过 `https://dubs.io/wp-json/tools/v1/download-video`)
## 视频格式
| format 值 | 说明 |
|-----------|------|
| 144 | 144p Mp4 |
| 240 | 240p Mp4 |
| 360 | 360p Mp4 |
| 480 | 480p Mp4 |
| 720 | 720p HD Mp4 |
| 1080 | 1080p FULL HD Mp4 |
| 4k | 2160p 4K WEBM |
| 8k | 4320p 8K WEBM |
## 音频格式
| format 值 | 说明 |
|-----------|------|
| mp3 | Audio MP3 |
| m4a | Audio M4A |
| flac | Audio FLAC |
| wav | Audio WAV |
| aac | Audio AAC |
| opus | Audio OPUS |
| ogg | Audio OGG |
## 使用方法
### 1. 请求下载
```bash
curl "https://p.savenow.to/ajax/download.php?copyright=0&allow_extended_duration=1&format=mp3&url=VIDEO_URL&api=API_KEY"
```
返回 JSON
```json
{
"success": true,
"id": "1CXjdNLFuewLXLBpOMu3BGJ",
"title": "视频标题",
"info": {
"title": "视频标题"
},
"progress_url": "https://p.savenow.to/api/progress?id=1CXjdNLFuewLXLBpOMu3BGJ"
}
```
**获取标题(Python**
```python
import json
import re
with open('response.json', 'rb') as f:
content = f.read()
match = re.search(rb'"title":"([^"]+)"', content)
escaped = match.group(1).decode('ascii')
title = bytes(escaped, 'ascii').decode('unicode_escape')
# title 就是视频标题
```
参数说明:
- `format`: 视频或音频格式
- `url`: YouTube 视频 URL
- `api`: API Key: `dfcb6d76f2f6a9894gjkege8a4ab232222`
- `copyright`: 0
- `allow_extended_duration`: 1
返回 JSON
```json
{
"success": true,
"id": "1CXjdNLFuewLXLBpOMu3BGJ",
"progress_url": "https://p.savenow.to/api/progress?id=1CXjdNLFuewLXLBpOMu3BGJ"
}
```
### 2. 轮询下载链接
```bash
curl "https://p.savenow.to/api/progress?id=VIDEO_ID"
```
`success: 1``progress: 1000` 时,返回 `download_url`
### 3. 下载文件
```bash
curl -L -o output.mp3 "DOWNLOAD_URL"
```
## Python 示例
```python
import requests
import time
API_KEY = 'dfcb6d76f2f6a9894gjkege8a4ab232222'
BASE_URL = 'https://p.savenow.to'
def download_youtube(url, format='mp3', output_path='output.mp3'):
# 1. 请求下载
params = {
'copyright': '0',
'allow_extended_duration': '1',
'format': format,
'url': url,
'api': API_KEY
}
resp = requests.get(f'{BASE_URL}/ajax/download.php', params=params)
data = resp.json()
if not data.get('success'):
raise Exception(f'Request failed: {data}')
progress_id = data['id']
progress_url = data['progress_url']
# 2. 轮询直到完成
while True:
time.sleep(3)
resp = requests.get(progress_url)
status = resp.json()
if status.get('success') == 1 and status.get('progress') == 1000:
download_url = status['download_url']
break
# 3. 下载文件
resp = requests.get(download_url, stream=True)
with open(output_path, 'wb') as f:
for chunk in resp.iter_content(chunk_size=8192):
f.write(chunk)
return output_path
# 使用
download_youtube('https://www.youtube.com/watch?v=VIDEO_ID', 'mp3', 'video.mp3')
```
## 注意事项
1. **API 不稳定时**: 会自动尝试备用 API (`p.lbserver.xyz`)
2. **下载链接有效期**: 获取后尽快下载
3. **支持地区**: API 可能因地区不同而有差异
4. **商业用途**: API 为免费使用,但有商业合作联系方式
## 参考
- 插件源码: `Youtube Tools All in one local download mp3 mp4`
- API 来源: `savenow.to`