File size: 1,773 Bytes
a6b0cbe 9430c4d a6b0cbe 9430c4d a6b0cbe 9430c4d a6b0cbe 4185844 9430c4d 4185844 a6b0cbe 9430c4d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import os
import streamlit as st
from pySmartDL import SmartDL
import platform
def get_default_download_folder():
system_platform = platform.system()
if system_platform == "Windows":
return os.path.join(os.path.expanduser("~"), "Downloads")
elif system_platform == "Linux":
return os.path.join(os.path.expanduser("~"), "Downloads")
elif system_platform == "Darwin":
return os.path.join(os.path.expanduser("~"), "Downloads")
elif system_platform == "Android":
return "/storage/emulated/0/Download" # Default Downloads folder path on Android
else:
raise NotImplementedError("Platform not supported")
def download_video(url):
try:
# Create a SmartDL object with the video URL
dl = SmartDL(url, progress_bar=False)
# Start the download
dl.start()
# Get the destination path where the file was downloaded
dest_path = dl.get_dest()
# Move the downloaded file to the default download folder
default_download_folder = get_default_download_folder()
os.rename(dest_path, os.path.join(default_download_folder, os.path.basename(dest_path)))
st.success("Video downloaded successfully!")
except Exception as e:
st.error(f"An error occurred: {e}")
def main():
st.title("YouTube Video Downloader")
# Input field for entering YouTube URL
video_url = st.text_input("Enter YouTube URL:")
# Button to trigger the download
if st.button("Download"):
if video_url.strip() == "":
st.warning("Please enter a valid YouTube URL.")
else:
# Download the video to the default download folder
download_video(video_url)
if __name__ == "__main__":
main()
|