Video Download with Korean Auto-Title
User wants a video from a URL saved to NAS with a short Korean title derived from the video content. Pipeline:
- yt-dlp downloads the video to
G:\내 드라이브\NAS폴더\NASfolder\동영상저장asplatform_<id>.mp4 - ffmpeg extracts 6 keyframes at 10%, 25%, 40%, 55%, 70%, 85% of duration (or 8/20/32/44/56/68s for 80s videos)
- delegate_task (leaf) uses
vision_analyzeto look at the frames and produce a Korean title (5–12 chars, no Windows-illegal chars, no "영상"/"동영상" suffix) - Rename to
platform_<Korean title>.mp4and clean up temp thumbs
Default save path
G:\내 드라이브\NAS폴더\NASfolder\동영상저장
Platform detection (for filename prefix)
x.comortwitter.com→x_youtube.comoryoutu.be→youtube_instagram.com→instagram_tiktok.com→tiktok_- Otherwise →
video_
Key commands
Download:
yt-dlp "<URL>" -o "G:/내 드라이브/NAS폴더/NASfolder/동영상저장/<platform>_<%(id)s>.%(ext)s"
(Note: include %(id)s placeholder so the initial filename is unique; the rename step replaces it.)
Extract keyframes (ffmpeg):
import os, subprocess
FFMPEG = r"C:\Users\okya1\AppData\Local\Microsoft\WinGet\Packages\Gyan.FFmpeg_Microsoft.Winget.Source_8wekyb3d8bbwe\ffmpeg-8.1.1-full_build\bin\ffmpeg.exe"
# Adjust the 6 timestamps based on video duration
# For ~80s video, use 8/20/32/44/56/68. For unknown length, compute from duration.
times = [8, 20, 32, 44, 56, 68] # seconds
for i, t in enumerate(times):
subprocess.run([FFMPEG, "-y", "-ss", str(t), "-i", video_path,
"-frames:v", "1", "-q:v", "3", f"frame_{i:02d}.jpg"])
Compute frame times for arbitrary video length:
duration = 80.666 # from ffprobe
times = [duration * p for p in [0.10, 0.25, 0.40, 0.55, 0.70, 0.85]]
Vision analysis prompt to delegate_task (leaf):
너는 영상 키프레임 6장을 보고 그 영상에 어울리는 짧은 한글 제목을 만드는 역할이야.
## 입력
영상은 <platform> URL에서 받은 <duration>짜리 영상이고, 6장의 키프레임이 다음 위치에 있어:
- C:\Users\okya1\AppData\Local\Temp\x_thumbs_<id>\frame_00.jpg (8s)
- ... (frame_01 ~ frame_05)
vision_analyze 도구로 각 프레임을 보고 영상 내용을 파악해줘. (6장 다 안 봐도 되지만 시간대별로 다르니 가능하면 6장 다 봐)
## 출력 형식
제목: <한글 제목 5~12자>
근거: <어떤 장면인지 한 줄 설명>
## 제약
- 한글로만 작성 (영어, 숫자는 불가피할 때만)
- 5~12자 이내, 공백 포함 가능
- 파일명용이므로 Windows 파일명에 안 되는 문자(< > : " / \ | ? *) 사용 금지
- "영상", "동영상" 같은 메타 단어 금지
Rename (Windows-safe sanitize):
import os, re
src = r"G:\내 드라이브\NAS폴더\NASfolder\동영상저장\x_<id>.mp4"
raw_title = "<subagent output>"
safe = re.sub(r'[<>:"/\\|?*]', '', raw_title).strip()
safe = re.sub(r'\s+', ' ', safe)
dst = rf"G:\내 드라이브\NAS폴더\NASfolder\동영상저장\x_{safe}.mp4"
os.rename(src, dst)
Pitfalls
- ffmpeg can't open Korean paths on Windows — even via Python subprocess, ffmpeg fails with "Illegal byte sequence" on paths containing 한글. Workaround: copy the source to an ASCII temp path (e.g.
%TEMP%\yt_conv\in.webm), convert there,shutil.movethe result back to the 한글 destination, then clean up. Note the copy+convert can take >5 min for long videos — run the ffmpeg convert as a background terminal job or a written-out .py script, not inside execute_code (which has a hard timeout). - yt-dlp goes stale fast — "Signature extraction failed" / "Only images are available" means the installed yt-dlp is outdated vs YouTube's player changes. Fix with
pip install -U yt-dlp(check version withyt-dlp --version) and retry. - MSYS path gotcha: When using
-owith absolute Windows paths in git-bash, yt-dlp can create files with literal\c\Users\...as a filename in cwd instead of resolving the path. Workaround: use forward slashes in-otemplate and verify withos.path.existsafter. - Merged files: Twitter videos come as two separate HLS streams (video + audio) and yt-dlp merges them. Don't pass
-f best(gets a warning); omit format selection so it picks best video+audio and merges. - Korean filenames on Windows: File system supports them fine. Just sanitize the 9 illegal chars.
- Long videos: Don't extract all keyframes at fixed times — scale to
duration * [0.1, 0.25, 0.4, 0.55, 0.7, 0.85]. - Subagent returns prefix: The leaf subagent may wrap output in markdown. Parse out the line starting with
제목:and use the value after it.
Verification checklist
os.path.exists(final_path)after rename → True- File size matches the download
- Thumbnail dir cleaned up (
%TEMP%\x_thumbs_*removed)