Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 3 |
import os
|
| 4 |
-
import time
|
| 5 |
|
| 6 |
# Streamlit ์ ๋ชฉ
|
| 7 |
st.title('YouTube Video Downloader')
|
|
@@ -12,12 +11,18 @@ youtube_url = st.text_input('Enter YouTube video URL')
|
|
| 12 |
if 'confirmed' not in st.session_state:
|
| 13 |
st.session_state.confirmed = False
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
if st.button('ํ์ธ'):
|
| 16 |
if youtube_url:
|
| 17 |
try:
|
| 18 |
-
|
| 19 |
-
st.session_state.
|
| 20 |
-
st.session_state.thumbnail_url =
|
| 21 |
st.session_state.confirmed = True
|
| 22 |
except Exception as e:
|
| 23 |
st.error(f"An error occurred: {e}")
|
|
@@ -28,45 +33,33 @@ if st.session_state.confirmed:
|
|
| 28 |
st.image(st.session_state.thumbnail_url, caption='Video Thumbnail', use_column_width=True)
|
| 29 |
|
| 30 |
# ํด์๋ ์ ํ
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def fetch_video_stream(youtube_url, resolution):
|
| 34 |
-
yt = st.session_state.yt
|
| 35 |
-
|
| 36 |
-
# ๋๋ ์ด ์ถ๊ฐ
|
| 37 |
-
time.sleep(2) # 2์ด ๋๋ ์ด
|
| 38 |
-
|
| 39 |
-
# ์ ํ๋ ํด์๋์ ๋น๋์ค ์คํธ๋ฆผ ์ ํ
|
| 40 |
-
stream = yt.streams.filter(res=resolution.replace('pHD', 'p'), progressive=True, file_extension='mp4').first()
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
| 48 |
|
| 49 |
# "์ถ์ถ" ๋ฒํผ ์ถ๊ฐ
|
| 50 |
if st.button('์ถ์ถ'):
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
# ๋ค์ด๋ก๋
|
| 58 |
-
download_path = stream.download()
|
| 59 |
-
st.session_state.download_path = download_path
|
| 60 |
-
st.success('Video downloaded successfully!')
|
| 61 |
-
st.video(download_path)
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import yt_dlp
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
# Streamlit ์ ๋ชฉ
|
| 6 |
st.title('YouTube Video Downloader')
|
|
|
|
| 11 |
if 'confirmed' not in st.session_state:
|
| 12 |
st.session_state.confirmed = False
|
| 13 |
|
| 14 |
+
def fetch_video_info(youtube_url):
|
| 15 |
+
ydl_opts = {}
|
| 16 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 17 |
+
info_dict = ydl.extract_info(youtube_url, download=False)
|
| 18 |
+
return info_dict
|
| 19 |
+
|
| 20 |
if st.button('ํ์ธ'):
|
| 21 |
if youtube_url:
|
| 22 |
try:
|
| 23 |
+
info_dict = fetch_video_info(youtube_url)
|
| 24 |
+
st.session_state.info_dict = info_dict
|
| 25 |
+
st.session_state.thumbnail_url = info_dict.get('thumbnail')
|
| 26 |
st.session_state.confirmed = True
|
| 27 |
except Exception as e:
|
| 28 |
st.error(f"An error occurred: {e}")
|
|
|
|
| 33 |
st.image(st.session_state.thumbnail_url, caption='Video Thumbnail', use_column_width=True)
|
| 34 |
|
| 35 |
# ํด์๋ ์ ํ
|
| 36 |
+
resolutions = ['1080p', '1080p60', '1080pHD', '720p']
|
| 37 |
+
resolution = st.selectbox('Select resolution', resolutions)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
def download_video(youtube_url, resolution):
|
| 40 |
+
ydl_opts = {
|
| 41 |
+
'format': f'bestvideo[height={resolution[:-1]}]+bestaudio/best[height={resolution[:-1]}]',
|
| 42 |
+
'outtmpl': 'downloaded_video.%(ext)s'
|
| 43 |
+
}
|
| 44 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 45 |
+
ydl.download([youtube_url])
|
| 46 |
|
| 47 |
# "์ถ์ถ" ๋ฒํผ ์ถ๊ฐ
|
| 48 |
if st.button('์ถ์ถ'):
|
| 49 |
+
try:
|
| 50 |
+
if resolution == '1080pHD':
|
| 51 |
+
resolution = '1080p' # yt-dlp์์ '1080pHD'๋ฅผ '1080p'๋ก ๋งคํ
|
| 52 |
+
download_video(youtube_url, resolution)
|
| 53 |
+
st.success('Video downloaded successfully!')
|
| 54 |
+
st.video('downloaded_video.mp4')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
# ๋ค์ด๋ก๋๋ ํ์ผ ์ ๊ณต (optional)
|
| 57 |
+
with open('downloaded_video.mp4', 'rb') as file:
|
| 58 |
+
st.download_button(
|
| 59 |
+
label="Download Video File",
|
| 60 |
+
data=file,
|
| 61 |
+
file_name='downloaded_video.mp4',
|
| 62 |
+
mime='video/mp4'
|
| 63 |
+
)
|
| 64 |
+
except Exception as e:
|
| 65 |
+
st.error(f"An error occurred during download: {e}")
|