arnabbumba077 commited on
Commit
a6b0cbe
·
verified ·
1 Parent(s): f7e4d90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -8
app.py CHANGED
@@ -1,12 +1,32 @@
 
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}")
@@ -22,8 +42,8 @@ def main():
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()
 
1
+ import os
2
  import streamlit as st
3
+ from pySmartDL import SmartDL
4
+ import platform
5
 
6
+ def get_default_download_folder():
7
+ system_platform = platform.system()
8
+ if system_platform == "Windows":
9
+ return os.path.join(os.path.expanduser("~"), "Downloads")
10
+ elif system_platform == "Linux":
11
+ return os.path.join(os.path.expanduser("~"), "Downloads")
12
+ elif system_platform == "Darwin":
13
+ return os.path.join(os.path.expanduser("~"), "Downloads")
14
+ elif system_platform == "Android":
15
+ return "/storage/emulated/0/Download" # Default Downloads folder path on Android
16
+ else:
17
+ raise NotImplementedError("Platform not supported")
18
+
19
+ def download_video(url):
20
  try:
21
+ # Create a SmartDL object with the video URL
22
+ dl = SmartDL(url, progress_bar=False)
23
+ # Start the download
24
+ dl.start()
25
+ # Get the destination path where the file was downloaded
26
+ dest_path = dl.get_dest()
27
+ # Move the downloaded file to the default download folder
28
+ default_download_folder = get_default_download_folder()
29
+ os.rename(dest_path, os.path.join(default_download_folder, os.path.basename(dest_path)))
30
  st.success("Video downloaded successfully!")
31
  except Exception as e:
32
  st.error(f"An error occurred: {e}")
 
42
  if video_url.strip() == "":
43
  st.warning("Please enter a valid YouTube URL.")
44
  else:
45
+ # Download the video to the default download folder
46
+ download_video(video_url)
47
 
48
  if __name__ == "__main__":
49
  main()