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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
 
2
  import streamlit as st
3
- from pySmartDL import SmartDL
4
  import platform
5
 
6
  def get_default_download_folder():
@@ -18,15 +19,15 @@ def get_default_download_folder():
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,7 +43,7 @@ def main():
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__":
 
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():
 
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}")
 
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__":