Spaces:
Sleeping
Sleeping
Download cli.py from heebin/YoutubeScript: direct link, hf CLI and curl.
- Browser
- Download file 3.23 kB
-
https://huggingface.co/spaces/heebin/YoutubeScript/resolve/main/cli.py
- Command line
-
hf download hf://spaces/heebin/YoutubeScript/cli.py
-
curl -L -o cli.py https://huggingface.co/spaces/heebin/YoutubeScript/resolve/main/cli.py
3.23 kB
| #!/usr/bin/env python3 | |
| """YouTube Script Extractor - CLI.""" | |
| import argparse | |
| import os | |
| import sys | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| from transcriber import process_video | |
| def main(): | |
| parser = argparse.ArgumentParser( | |
| description="YouTube ์์์์ ์์ฑ์ธ์์ผ๋ก ์คํฌ๋ฆฝํธ๋ฅผ ์ถ์ถํฉ๋๋ค.", | |
| formatter_class=argparse.RawDescriptionHelpFormatter, | |
| epilog=""" | |
| ์ฌ์ฉ ์์: | |
| # Whisper API ์ฌ์ฉ (๋น ๋ฅด๊ณ ์ ํ) | |
| python cli.py "https://www.youtube.com/watch?v=..." --mode api | |
| # ๋ก์ปฌ Whisper ์ฌ์ฉ (๋ฌด๋ฃ) | |
| python cli.py "https://www.youtube.com/watch?v=..." --mode local --model base | |
| # SRT ์๋ง๋ง ์์ฑ | |
| python cli.py "https://www.youtube.com/watch?v=..." --format srt | |
| # ์ถ๋ ฅ ๋๋ ํ ๋ฆฌ ์ง์ | |
| python cli.py "https://www.youtube.com/watch?v=..." --output ./my_scripts | |
| """, | |
| ) | |
| parser.add_argument("url", help="YouTube ์์ URL") | |
| parser.add_argument( | |
| "--mode", | |
| choices=["api", "local"], | |
| default=os.environ.get("DEFAULT_MODE", "api"), | |
| help="๋ณํ ๋ชจ๋ (๊ธฐ๋ณธ: api)", | |
| ) | |
| parser.add_argument( | |
| "--api-key", | |
| default=None, | |
| help="OpenAI API ํค (๋ฏธ์ง์ ์ OPENAI_API_KEY ํ๊ฒฝ๋ณ์ ์ฌ์ฉ)", | |
| ) | |
| parser.add_argument( | |
| "--model", | |
| default=os.environ.get("DEFAULT_MODEL", "base"), | |
| choices=["tiny", "base", "small", "medium", "large"], | |
| help="๋ก์ปฌ Whisper ๋ชจ๋ธ ํฌ๊ธฐ (๊ธฐ๋ณธ: base)", | |
| ) | |
| parser.add_argument( | |
| "--format", | |
| default="txt,srt", | |
| help="์ถ๋ ฅ ํ์, ์ผํ๋ก ๊ตฌ๋ถ (๊ธฐ๋ณธ: txt,srt)", | |
| ) | |
| parser.add_argument( | |
| "--output", | |
| default="./output", | |
| help="์ถ๋ ฅ ๋๋ ํ ๋ฆฌ (๊ธฐ๋ณธ: ./output)", | |
| ) | |
| args = parser.parse_args() | |
| # API ํค ์ฒ๋ฆฌ | |
| api_key = args.api_key or os.environ.get("OPENAI_API_KEY") | |
| if args.mode == "api" and not api_key: | |
| print("์ค๋ฅ: API ๋ชจ๋์์๋ OpenAI API ํค๊ฐ ํ์ํฉ๋๋ค.") | |
| print(" --api-key ์ธ์๋ฅผ ์ฌ์ฉํ๊ฑฐ๋ OPENAI_API_KEY ํ๊ฒฝ๋ณ์๋ฅผ ์ค์ ํ์ธ์.") | |
| sys.exit(1) | |
| formats = [f.strip() for f in args.format.split(",")] | |
| def on_progress(msg: str): | |
| print(f" โ {msg}") | |
| print(f"YouTube Script Extractor") | |
| print(f" URL: {args.url}") | |
| print(f" ๋ชจ๋: {'Whisper API' if args.mode == 'api' else f'๋ก์ปฌ Whisper ({args.model})'}") | |
| print(f" ์ถ๋ ฅ: {', '.join(formats)}") | |
| print() | |
| try: | |
| result = process_video( | |
| url=args.url, | |
| mode=args.mode, | |
| api_key=api_key, | |
| model_size=args.model, | |
| output_dir=args.output, | |
| formats=formats, | |
| on_progress=on_progress, | |
| ) | |
| print() | |
| print(f"์ ๋ชฉ: {result['title']}") | |
| print(f"๊ฐ์ง๋ ์ธ์ด: {result['language']}") | |
| print(f"์์ฑ๋ ํ์ผ:") | |
| for fmt, path in result["files"].items(): | |
| print(f" [{fmt.upper()}] {path}") | |
| except KeyboardInterrupt: | |
| print("\n์ค๋จ๋์์ต๋๋ค.") | |
| sys.exit(130) | |
| except Exception as e: | |
| print(f"\n์ค๋ฅ ๋ฐ์: {e}") | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| main() | |