arnabbumba077 commited on
Commit
6de6818
·
verified ·
1 Parent(s): 236e101

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -40
app.py CHANGED
@@ -1,50 +1,26 @@
1
- import os
2
- import shutil
3
  import streamlit as st
4
  from pytube import YouTube
5
- import platform
6
-
7
- def get_default_download_folder():
8
- system_platform = platform.system()
9
- if system_platform == "Windows":
10
- return os.path.join(os.path.expanduser("~"), "Downloads")
11
- elif system_platform == "Linux":
12
- return os.path.join(os.path.expanduser("~"), "Downloads")
13
- elif system_platform == "Darwin":
14
- return os.path.join(os.path.expanduser("~"), "Downloads")
15
- elif system_platform == "Android":
16
- return "/storage/emulated/0/Download" # Default Downloads folder path on Android
17
- else:
18
- raise NotImplementedError("Platform not supported")
19
 
 
20
  def download_video(url):
21
  try:
22
  yt = YouTube(url)
23
- streams = yt.streams.filter(progressive=True, file_extension="mp4")
24
- highest_res_stream = streams.get_highest_resolution()
25
- # Download the video
26
- save_path = os.path.join(os.getcwd(), yt.title + '.mp4')
27
- highest_res_stream.download(output_path=os.getcwd(), filename=yt.title)
28
- # Move the downloaded file to the default download folder
29
- default_download_folder = get_default_download_folder()
30
- shutil.move(save_path, os.path.join(default_download_folder, yt.title + '.mp4'))
31
- st.success("Video downloaded successfully!")
32
  except Exception as e:
33
  st.error(f"An error occurred: {e}")
34
 
35
- def main():
36
- st.title("YouTube Video Downloader")
37
-
38
- # Input field for entering YouTube URL
39
- video_url = st.text_input("Enter YouTube URL:")
40
-
41
- # Button to trigger the download
42
- if st.button("Download"):
43
- if video_url.strip() == "":
44
- st.warning("Please enter a valid YouTube URL.")
45
- else:
46
- # Download the video and move it to the default download folder
47
- download_video(video_url)
48
 
49
- if __name__ == "__main__":
50
- main()
 
 
 
 
 
 
1
  import streamlit as st
2
  from pytube import YouTube
3
+ import os
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
+ # Function to download YouTube video
6
  def download_video(url):
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').first()
12
+ stream.download(output_path=os.path.expanduser("~\Downloads"))
13
+ st.success("Download completed successfully!")
 
 
 
 
14
  except Exception as e:
15
  st.error(f"An error occurred: {e}")
16
 
17
+ # Streamlit UI
18
+ st.title("YouTube Video Downloader")
19
+
20
+ url = st.text_input("Enter YouTube Video URL:", "")
 
 
 
 
 
 
 
 
 
21
 
22
+ if st.button("Download"):
23
+ if url.strip() == "":
24
+ st.warning("Please enter a YouTube video URL.")
25
+ else:
26
+ download_video(url)