Files
ai-media-hub/worker/downloader.py
AI Assistant 4b8c2c0453
Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 3m7s
feat: AI 미디어 허브 초기 세팅 및 뼈대 코드 완성
2026-03-12 12:43:17 +09:00

41 lines
1.3 KiB
Python

import os
import sys
import argparse
import yt_dlp
def progress_hook(d):
if d['status'] == 'downloading':
percent = d.get('_percent_str', 'N/A')
print(f"PROGRESS: {percent}", flush=True)
def main():
parser = argparse.ArgumentParser(description="Media Downloader via yt-dlp")
parser.add_argument("url", help="URL of the media to download")
parser.add_argument("--start", help="Start time for crop (e.g. 00:01:00)", default=None)
parser.add_argument("--end", help="End time for crop (e.g. 00:02:30)", default=None)
args = parser.parse_args()
ydl_opts = {
'outtmpl': '/downloads/%(title)s.%(ext)s',
'progress_hooks': [progress_hook],
'quiet': True,
'no_warnings': True,
}
if args.start and args.end:
print(f"Applying crop from {args.start} to {args.end}")
# Note: In a real environment, you might use format sorting and postprocessors like FFmpeg directly.
# This is a sample placeholder for the structure.
# Try downloading
try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
print("Download started...")
ydl.download([args.url])
print("Download finished.")
except Exception as e:
print(f"Error starting download: {e}", file=sys.stderr)
if __name__ == "__main__":
main()