Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
from pytube import YouTube
|
|
|
3 |
|
4 |
class YouTubeDownloader:
|
5 |
@staticmethod
|
@@ -8,27 +9,38 @@ class YouTubeDownloader:
|
|
8 |
url = st.text_input("Enter YouTube URL to download:")
|
9 |
if url:
|
10 |
YouTubeDownloader.validate_url(url)
|
11 |
-
|
12 |
-
st.video
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
st.markdown("μ) https://www.youtube.com/watch?v=hXpNj1ChxRI ")
|
19 |
|
20 |
-
|
21 |
@staticmethod
|
22 |
def download_video(url):
|
23 |
-
|
24 |
-
|
25 |
-
YouTube(url)
|
26 |
-
.streams.filter(progressive=True, file_extension="mp4")
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
@staticmethod
|
34 |
def validate_url(url):
|
@@ -53,6 +65,5 @@ class YouTubeDownloader:
|
|
53 |
"μμ νλ©΄ μ°μΈ‘ νλ¨ ... λ²νΌμ ν΄λ¦νλ©΄ λ€μ΄λ‘λ ν μ μμ΅λλ€."
|
54 |
)
|
55 |
|
56 |
-
|
57 |
if __name__ == "__main__":
|
58 |
YouTubeDownloader.run()
|
|
|
1 |
import streamlit as st
|
2 |
from pytube import YouTube
|
3 |
+
from pytube.exceptions import VideoUnavailable
|
4 |
|
5 |
class YouTubeDownloader:
|
6 |
@staticmethod
|
|
|
9 |
url = st.text_input("Enter YouTube URL to download:")
|
10 |
if url:
|
11 |
YouTubeDownloader.validate_url(url)
|
12 |
+
try:
|
13 |
+
with st.expander("preview video"):
|
14 |
+
st.video(url)
|
15 |
+
if st.button("Download"):
|
16 |
+
YouTubeDownloader.cleanup()
|
17 |
+
file_ = YouTubeDownloader.download_video(url)
|
18 |
+
if file_: # file_ μ΄ Noneμ΄ μλ λλ§ λΉλμ€ νμ
|
19 |
+
st.video(file_)
|
20 |
+
YouTubeDownloader.helper_message()
|
21 |
+
except Exception as e:
|
22 |
+
st.error(f"Error: {str(e)}")
|
23 |
st.markdown("μ) https://www.youtube.com/watch?v=hXpNj1ChxRI ")
|
24 |
|
|
|
25 |
@staticmethod
|
26 |
def download_video(url):
|
27 |
+
try:
|
28 |
+
with st.spinner("Downloading..."):
|
29 |
+
yt = YouTube(url)
|
30 |
+
stream = yt.streams.filter(progressive=True, file_extension="mp4").first()
|
31 |
+
if stream:
|
32 |
+
local_file = stream.download()
|
33 |
+
st.success("Downloaded")
|
34 |
+
return local_file
|
35 |
+
else:
|
36 |
+
st.error("No suitable stream found for this video")
|
37 |
+
return None
|
38 |
+
except VideoUnavailable:
|
39 |
+
st.error("This video is unavailable")
|
40 |
+
return None
|
41 |
+
except Exception as e:
|
42 |
+
st.error(f"An error occurred: {str(e)}")
|
43 |
+
return None
|
44 |
|
45 |
@staticmethod
|
46 |
def validate_url(url):
|
|
|
65 |
"μμ νλ©΄ μ°μΈ‘ νλ¨ ... λ²νΌμ ν΄λ¦νλ©΄ λ€μ΄λ‘λ ν μ μμ΅λλ€."
|
66 |
)
|
67 |
|
|
|
68 |
if __name__ == "__main__":
|
69 |
YouTubeDownloader.run()
|