Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,32 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
-
from
|
|
|
3 |
|
4 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
try:
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
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
|
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()
|