Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import streamlit as st
|
|
| 2 |
import os
|
| 3 |
import yt_dlp
|
| 4 |
import psutil
|
|
|
|
| 5 |
|
| 6 |
# Function to get disk usage information
|
| 7 |
def get_disk_info():
|
|
@@ -27,7 +28,7 @@ def update_disk_info():
|
|
| 27 |
update_disk_info()
|
| 28 |
|
| 29 |
# Streamlit input fields
|
| 30 |
-
|
| 31 |
quality = st.selectbox("Select the desired quality:", ['4320', '2160', '1440', '1080', '720', '480'])
|
| 32 |
save_file_name = st.text_input("Enter the save file name (without extension):")
|
| 33 |
|
|
@@ -40,6 +41,27 @@ ydl_opts = {
|
|
| 40 |
'outtmpl': f'{save_file_name}.%(ext)s', # Save the video with the specified name
|
| 41 |
}
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
if st.button("Download"):
|
| 44 |
with st.spinner("Downloading... Please wait."):
|
| 45 |
try:
|
|
|
|
| 2 |
import os
|
| 3 |
import yt_dlp
|
| 4 |
import psutil
|
| 5 |
+
from youtube_search import VideosSearch
|
| 6 |
|
| 7 |
# Function to get disk usage information
|
| 8 |
def get_disk_info():
|
|
|
|
| 28 |
update_disk_info()
|
| 29 |
|
| 30 |
# Streamlit input fields
|
| 31 |
+
query = st.text_input("Enter search query or YouTube URL:")
|
| 32 |
quality = st.selectbox("Select the desired quality:", ['4320', '2160', '1440', '1080', '720', '480'])
|
| 33 |
save_file_name = st.text_input("Enter the save file name (without extension):")
|
| 34 |
|
|
|
|
| 41 |
'outtmpl': f'{save_file_name}.%(ext)s', # Save the video with the specified name
|
| 42 |
}
|
| 43 |
|
| 44 |
+
# Search for videos if a query is entered
|
| 45 |
+
if query:
|
| 46 |
+
if not query.startswith("http"):
|
| 47 |
+
# If the query is not a URL, search for videos
|
| 48 |
+
st.markdown("### Search Results:")
|
| 49 |
+
videos_search = VideosSearch(query, limit=5)
|
| 50 |
+
results = videos_search.result()['result']
|
| 51 |
+
video_urls = [f"https://www.youtube.com/watch?v={video['id']}" for video in results]
|
| 52 |
+
|
| 53 |
+
for i, video in enumerate(results):
|
| 54 |
+
st.write(f"{i + 1}. **{video['title']}** ({video['duration']})")
|
| 55 |
+
st.write(f" Channel: {video['channel']['name']}")
|
| 56 |
+
st.write(f" URL: {video_urls[i]}")
|
| 57 |
+
st.write("\n")
|
| 58 |
+
|
| 59 |
+
selected_video_index = st.number_input("Select video number to download:", min_value=1, max_value=len(results), step=1) - 1
|
| 60 |
+
url = video_urls[selected_video_index]
|
| 61 |
+
else:
|
| 62 |
+
# If the query is a URL, use it directly
|
| 63 |
+
url = query
|
| 64 |
+
|
| 65 |
if st.button("Download"):
|
| 66 |
with st.spinner("Downloading... Please wait."):
|
| 67 |
try:
|