forked from Franky1/Streamlit-ffmpeg-Test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch.py
57 lines (44 loc) · 1.46 KB
/
watch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import streamlit as st
import yt_dlp
import os
import glob
import ffmpeg
def video_download(URL):
file_keep = "watch.py"
f1 = "requirements.txt"
f2 = "environment.yml"
files = os.listdir('./download/')
for file in files:
if file != file_keep and file != f1 and file != f2:
if os.path.isfile(file): # ファイルであるか確認
os.remove(file)
# カスタマイズしたオプションを設定
ydl_opts = {
'outtmpl': './download/video.mp4', # ファイル名と保存場所を指定
'format' :"bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4]",
'progress_hooks': [progress_hook],
}
# YoutubeDLインスタンスを作成してダウンロード
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
try:
ydl.download([URL])
except Exception as e:
print("Error")
def progress_hook(d):
progress = float()
if d['status'] == 'downloading':
progress = (f"ダウンロード: {d['filename']} - {d['_percent_str']}")
st.title("YouTubeを見る")
URL = st.text_input("URLを入力")
path = os.getcwd()
st.write(path)
if st.button("処理開始"):
video_download(URL)
file_select = "watch.py"
files = os.listdir('.')
dir_path = glob.glob("*mp4")
st.write(dir_path)
video_path = "".join(dir_path)
with open(video_path, 'rb') as video_file:
video_bytes = video_file.read()
st.video(video_bytes)