arnabbumba077 commited on
Commit
187461d
·
verified ·
1 Parent(s): 5477c4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -3,13 +3,13 @@ from pytube import YouTube
3
  import os
4
 
5
  # Function to download YouTube video
6
- def download_video(url, title):
7
  try:
8
  yt = YouTube(url)
9
- st.write("Video Title:", title)
10
  st.write("Downloading...")
11
- stream = yt.streams.filter(progressive=True, file_extension='mp4').first()
12
- download_path = os.path.join(os.path.expanduser("~\Downloads"), f"{title}.mp4")
13
  stream.download(output_path=download_path)
14
  st.success("Download completed successfully!")
15
  except Exception as e:
@@ -19,17 +19,12 @@ def download_video(url, title):
19
  st.title("YouTube Video Downloader")
20
 
21
  url = st.text_input("Enter YouTube Video URL:", "")
 
 
 
22
 
23
  if st.button("Download"):
24
  if url.strip() == "":
25
  st.warning("Please enter a YouTube video URL.")
26
  else:
27
- yt = YouTube(url)
28
- title = yt.title
29
- download_video(url, title)
30
-
31
- if 'url' in st.session_state and st.session_state.url.strip() != "":
32
- yt = YouTube(st.session_state.url)
33
- title = yt.title
34
- if st.button("Download Video"):
35
- download_video(st.session_state.url, title)
 
3
  import os
4
 
5
  # Function to download YouTube video
6
+ def download_video(url, selected_quality):
7
  try:
8
  yt = YouTube(url)
9
+ st.write("Video Title:", yt.title)
10
  st.write("Downloading...")
11
+ stream = yt.streams.filter(progressive=True, file_extension='mp4').get_by_resolution(selected_quality)
12
+ download_path = os.path.join(os.path.expanduser("~\Downloads"))
13
  stream.download(output_path=download_path)
14
  st.success("Download completed successfully!")
15
  except Exception as e:
 
19
  st.title("YouTube Video Downloader")
20
 
21
  url = st.text_input("Enter YouTube Video URL:", "")
22
+ quality_options = ["1080p", "720p", "480p", "360p"]
23
+
24
+ selected_quality = st.selectbox("Select Video Quality:", quality_options)
25
 
26
  if st.button("Download"):
27
  if url.strip() == "":
28
  st.warning("Please enter a YouTube video URL.")
29
  else:
30
+ download_video(url, selected_quality)