Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
|
| 6 |
+
def download_video(url):
|
| 7 |
+
if not url.strip():
|
| 8 |
+
return "URLを入力してください。"
|
| 9 |
+
|
| 10 |
+
# 保存ファイル名の先頭に日時を追加して重複を防ぐ
|
| 11 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 12 |
+
output_template = f"{timestamp}_動画.%(ext)s"
|
| 13 |
+
|
| 14 |
+
# yt-dlp コマンドの構築
|
| 15 |
+
command = [
|
| 16 |
+
"yt-dlp",
|
| 17 |
+
"-o", output_template,
|
| 18 |
+
"--write-thumbnail",
|
| 19 |
+
"-f", "mp4",
|
| 20 |
+
url
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
result = subprocess.run(command, capture_output=True, text=True)
|
| 25 |
+
if result.returncode != 0:
|
| 26 |
+
return f"エラーが発生しました:\n{result.stderr}"
|
| 27 |
+
else:
|
| 28 |
+
return f"ダウンロード完了:{output_template.replace('%(ext)s', 'mp4')}(サムネイルも保存されました)"
|
| 29 |
+
except Exception as e:
|
| 30 |
+
return f"例外が発生しました:{str(e)}"
|
| 31 |
+
|
| 32 |
+
# Gradio インターフェース作成
|
| 33 |
+
with gr.Blocks() as demo:
|
| 34 |
+
gr.Markdown("## 🎥 動画ダウンローダー(yt-dlp + Gradio)")
|
| 35 |
+
url_input = gr.Textbox(label="動画のURLを入力してください")
|
| 36 |
+
output_text = gr.Textbox(label="結果")
|
| 37 |
+
download_button = gr.Button("ダウンロード開始")
|
| 38 |
+
|
| 39 |
+
download_button.click(fn=download_video, inputs=[url_input], outputs=[output_text])
|
| 40 |
+
|
| 41 |
+
# アプリ起動
|
| 42 |
+
demo.launch()
|