-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamlit_app.py
More file actions
68 lines (55 loc) · 2.26 KB
/
streamlit_app.py
File metadata and controls
68 lines (55 loc) · 2.26 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import streamlit as st
import os
from pytube import YouTube
from downloader import get_stream_info, download_video
def main():
st.set_page_config(
page_title="YouTube Video Downloader",
page_icon="📥",
layout="centered"
)
st.title("🎥 YouTube Video Downloader")
# URL Input
url = st.text_input("Enter YouTube Video URL", placeholder="https://youtu.be/...")
# Download directory selection
download_path = st.text_input(
"Download Path",
value=os.path.expanduser("~/Downloads"),
help="Select the directory where the video will be saved"
)
# Fetch and display stream information
if url:
try:
# Disable error messages
st.spinner("Fetching video streams...")
# Get YouTube object
yt = YouTube(url)
# Display basic video info
col1, col2 = st.columns(2)
with col1:
st.image(yt.thumbnail_url, caption="Video Thumbnail", width=300)
with col2:
st.write(f"**Title:** {yt.title}")
st.write(f"**Author:** {yt.author}")
st.write(f"**Length:** {yt.length} seconds")
# Get stream information
streams_info = get_stream_info(yt)
# Create a dataframe for stream selection
import pandas as pd
df = pd.DataFrame(streams_info)
st.dataframe(df, hide_index=True)
# Stream selection
selected_stream = st.selectbox(
"Select Download Stream",
range(len(streams_info)),
format_func=lambda x: f"{streams_info[x]['res']} | {streams_info[x]['type']} | {streams_info[x]['filesize']}"
)
# Download button
if st.button("Download Video", type="primary"):
with st.spinner("Downloading Video..."):
final_path = download_video(url, download_path, selected_stream)
st.success(f"Video downloaded successfully to {final_path}")
except Exception as e:
st.error(f"An error occurred: {str(e)}")
if __name__ == "__main__":
main()