Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,29 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
|
4 |
-
def
|
5 |
-
"""Fetches video details using pytube, handling potential errors."""
|
6 |
try:
|
7 |
-
yt =
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
return None, None
|
14 |
-
except pytube.exceptions.PytubeError as e:
|
15 |
st.error(f"An error occurred: {e}")
|
16 |
-
return None, None
|
17 |
-
|
18 |
-
def download_video(streams, selected_quality):
|
19 |
-
"""Downloads the video based on user selection, handling potential errors."""
|
20 |
-
try:
|
21 |
-
stream = streams.get_by_resolution(selected_quality)
|
22 |
-
stream.download()
|
23 |
-
st.success(f"Video downloaded successfully!")
|
24 |
-
except pytube.exceptions.PytubeError as e:
|
25 |
-
st.error(f"Download failed: {e}")
|
26 |
|
27 |
def main():
|
28 |
-
"""Builds the Streamlit app with user interface and download functionality."""
|
29 |
st.title("YouTube Video Downloader")
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
download_video(streams, selected_quality)
|
42 |
|
43 |
if __name__ == "__main__":
|
44 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
+
from pytube import YouTube
|
3 |
|
4 |
+
def download_video(url, save_path):
|
|
|
5 |
try:
|
6 |
+
yt = YouTube(url)
|
7 |
+
streams = yt.streams.filter(progressive=True, file_extension="mp4")
|
8 |
+
highest_res_stream = streams.get_highest_resolution()
|
9 |
+
highest_res_stream.download(output_path=save_path)
|
10 |
+
st.success("Video downloaded successfully!")
|
11 |
+
except Exception as e:
|
|
|
|
|
12 |
st.error(f"An error occurred: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
def main():
|
|
|
15 |
st.title("YouTube Video Downloader")
|
16 |
+
|
17 |
+
# Input field for entering YouTube URL
|
18 |
+
video_url = st.text_input("Enter YouTube URL:")
|
19 |
+
|
20 |
+
# Button to trigger the download
|
21 |
+
if st.button("Download"):
|
22 |
+
if video_url.strip() == "":
|
23 |
+
st.warning("Please enter a valid YouTube URL.")
|
24 |
+
else:
|
25 |
+
# Download the video
|
26 |
+
download_video(video_url, "./downloads")
|
|
|
27 |
|
28 |
if __name__ == "__main__":
|
29 |
main()
|