Spaces:
Sleeping
Sleeping
import streamlit as st | |
import youtube_dl | |
from huggingface_hub import download_file | |
st.title("YouTube Video Player") | |
video_url = st.text_input("Enter the YouTube video URL:") | |
if video_url: | |
with st.spinner("Downloading video..."): | |
# Download video using youtube-dl | |
ytdl_opts = { | |
"format": "best[ext=mp4]" | |
} | |
with youtube_dl.YoutubeDL(ytdl_opts) as ytdl: | |
info_dict = ytdl.extract_info(video_url, download=False) | |
video_title = info_dict.get("title", None) | |
video_id = info_dict.get("id", None) | |
# Download video from Hugging Face Spaces bucket | |
video_filename = f"{video_id}.mp4" | |
download_file(f"youtube/{video_filename}", video_filename) | |
# Create Spaces player to play local video | |
spaces_video = st.spaces.video(video_filename) | |
st.markdown(f"#### {video_title}") | |
spaces_video.play() |