mk-youtube-get-audio

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

YouTube Audio Download

YouTube音频下载

Download video audio file (best available format, no conversion).
下载视频音频文件(采用可用的最佳格式,无需转换)。

Quick Start

快速开始

/mk-youtube-get-audio <URL> [output_dir] [browser] [--force]
/mk-youtube-get-audio <URL> [output_dir] [browser] [--force]

Parameters

参数

ParameterRequiredDefaultDescription
URLYes-YouTube video URL
output_dirNo/tmp/monkey_knowledge/youtube/audioOutput directory for audio file
browserNoautoBrowser for cookies (chrome, firefox, safari, edge, brave)
--forceNofalseForce re-download even if cached file exists
参数是否必填默认值描述
URL-YouTube视频链接
output_dir/tmp/monkey_knowledge/youtube/audio音频文件的输出目录
browserauto用于获取Cookie的浏览器(chrome, firefox, safari, edge, brave)
--forcefalse即使存在缓存文件,强制重新下载

Examples

示例

  • /mk-youtube-get-audio https://youtube.com/watch?v=xxx
    - Download with auto cookie fallback
  • /mk-youtube-get-audio https://youtube.com/watch?v=xxx ~/Music
    - Save to custom directory
  • /mk-youtube-get-audio https://youtube.com/watch?v=xxx /tmp chrome
    - Use Chrome cookies
  • /mk-youtube-get-audio https://youtube.com/watch?v=xxx
    - 使用自动Cookie回退机制下载
  • /mk-youtube-get-audio https://youtube.com/watch?v=xxx ~/Music
    - 保存到自定义目录
  • /mk-youtube-get-audio https://youtube.com/watch?v=xxx /tmp chrome
    - 使用Chrome的Cookie

How it Works

工作原理

  1. Execute:
    {baseDir}/scripts/audio.sh "<URL>" "<output_dir>" "<browser>"
  2. First attempt: download without authentication
  3. If failed: retry with browser cookies (auto-detect or specified)
  4. Parse JSON output to get file path
┌─────────────────────────────┐
│   First attempt (no auth)   │
└──────────────┬──────────────┘
       ┌───────┴───────┐
       │               │
    Success         Failed
       │               │
       ▼               ▼
   [Return]    ┌─────────────────────┐
               │ Retry with cookies  │
               │ chrome → firefox →  │
               │ safari → edge →     │
               │ brave               │
               └──────────┬──────────┘
                  ┌───────┴───────┐
                  │               │
               Success         Failed
                  │               │
                  ▼               ▼
              [Return]        [Error]
  1. 执行命令:
    {baseDir}/scripts/audio.sh "<URL>" "<output_dir>" "<browser>"
  2. 首次尝试:无需认证直接下载
  3. 如果失败:使用浏览器Cookie重试(自动检测或指定浏览器)
  4. 解析JSON输出获取文件路径
┌─────────────────────────────┐
│   首次尝试(无认证)   │
└──────────────┬──────────────┘
       ┌───────┴───────┐
       │               │
    成功         失败
       │               │
       ▼               ▼
   [返回结果]    ┌─────────────────────┐
               │ 使用Cookie重试  │
               │ chrome → firefox →  │
               │ safari → edge →     │
               │ brave               │
               └──────────┬──────────┘
                  ┌───────┴───────┐
                  │               │
               成功         失败
                  │               │
                  ▼               ▼
              [返回结果]        [返回错误]

Output Format

输出格式

Success:
json
{
  "status": "success",
  "file_path": "/tmp/monkey_knowledge/youtube/audio/20091025__VIDEO_ID.m4a",
  "file_size": "5.2M",
  "cached": false,
  "video_id": "dQw4w9WgXcQ",
  "title": "Video Title",
  "channel": "Channel Name",
  "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
  "duration_string": "3:32"
}
Cache hit (returns existing file):
json
{
  "status": "success",
  "file_path": "/tmp/monkey_knowledge/youtube/audio/20091025__VIDEO_ID.m4a",
  "file_size": "5.2M",
  "cached": true,
  ...
}
Error:
json
{
  "status": "error",
  "message": "Download failed (tried with and without cookies)"
}
成功:
json
{
  "status": "success",
  "file_path": "/tmp/monkey_knowledge/youtube/audio/20091025__VIDEO_ID.m4a",
  "file_size": "5.2M",
  "cached": false,
  "video_id": "dQw4w9WgXcQ",
  "title": "视频标题",
  "channel": "频道名称",
  "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
  "duration_string": "3:32"
}
命中缓存(返回已存在的文件):
json
{
  "status": "success",
  "file_path": "/tmp/monkey_knowledge/youtube/audio/20091025__VIDEO_ID.m4a",
  "file_size": "5.2M",
  "cached": true,
  ...
}
错误:
json
{
  "status": "error",
  "message": "下载失败(已尝试带Cookie和不带Cookie的方式)"
}

Filename Format

文件名格式

Files use unified naming with date prefix:
{YYYYMMDD}__{video_id}.{ext}
Example:
20091025__dQw4w9WgXcQ.m4a
文件采用统一命名格式,带有日期前缀:
{YYYYMMDD}__{video_id}.{ext}
示例:
20091025__dQw4w9WgXcQ.m4a

Browser Cookie Fallback

浏览器Cookie回退机制

When download fails (e.g., member-only or age-restricted content), the script automatically:
  1. Tries each browser: chrome → firefox → safari → edge → brave
  2. For Chrome: tries all profiles (Default, Profile 1, Profile 2, ...)
  3. Uses first successful browser/profile combination
Supported browsers:
BrowserParameterChrome Profile Support
Chrome
chrome
Yes (auto-detect all profiles)
Firefox
firefox
Default profile only
Safari
safari
Default profile only
Edge
edge
Default profile only
Brave
brave
Default profile only
当下载失败时(例如会员专属或年龄限制内容),脚本会自动:
  1. 尝试每个浏览器:chrome → firefox → safari → edge → brave
  2. 对于Chrome:尝试所有配置文件(Default, Profile 1, Profile 2, ...)
  3. 使用第一个成功的浏览器/配置文件组合
支持的浏览器:
浏览器参数值Chrome配置文件支持
Chrome
chrome
是(自动检测所有配置文件)
Firefox
firefox
仅默认配置文件
Safari
safari
仅默认配置文件
Edge
edge
仅默认配置文件
Brave
brave
仅默认配置文件

Use Cases

使用场景

  • Download audio for speech-to-text when video has no subtitles
  • Podcast or music download
  • Member-only or age-restricted content (with browser cookies)
  • 当视频没有字幕时,下载音频用于语音转文字
  • 播客或音乐下载
  • 会员专属或年龄限制内容(需借助浏览器Cookie)

Notes

注意事项

  • File caching: If audio file already exists for this video, it will be reused (returns
    cached: true
    )
  • Force refresh: Use
    --force
    flag to re-download even if cached file exists
  • Uses system yt-dlp/jq if available, otherwise auto-downloads on first run
  • No ffmpeg required (uses best available format without conversion)
  • Output format depends on source (typically m4a, webm, or opus)
  • Cookie fallback only activates when initial download fails
  • Using cookies may risk YouTube account suspension - use secondary account if needed
  • 文件缓存:如果该视频的音频文件已存在,将直接复用(返回
    cached: true
  • 强制刷新:使用
    --force
    标志可强制重新下载,即使缓存文件存在
  • 如果系统中已安装yt-dlp/jq则直接使用,否则首次运行时自动下载
  • 无需ffmpeg(采用可用的最佳格式,无需转换)
  • 输出格式取决于源文件(通常为m4a、webm或opus)
  • 仅当初始下载失败时,Cookie回退机制才会激活
  • 使用Cookie可能导致YouTube账号被封禁 - 如有需要请使用次要账号

Next Step

下一步操作

After downloading the audio, invoke
/mk-youtube-audio-transcribe
with the
file_path
from the output:
/mk-youtube-audio-transcribe <file_path> [model] [language]
Tip: If you know the video's language from
/mk-youtube-get-info
, pass it as the language parameter for better model auto-selection (e.g.,
zh
→ belle-zh,
ja
→ kotoba-ja).
下载音频后,使用输出中的
file_path
调用
/mk-youtube-audio-transcribe
命令:
/mk-youtube-audio-transcribe <file_path> [model] [language]
提示:如果通过
/mk-youtube-get-info
了解到视频的语言,可将其作为language参数传入,以获得更好的模型自动选择效果(例如:
zh
→ belle-zh,
ja
→ kotoba-ja)。