I want to create a web app in python that allows me to play a youtube videos(that have subtitles offcourse) However I want to have an option where we can customise the size of the subtitle and change color or make the text bold italics underline etc and while this is not a neccessar feature it would also be good if it can have differnet colors depending on different speakers do you get what I am saying also share any additional features you think would be good to add or whether it is possible to make this entirely in python
To upload files, please first save the app
import streamlit as st
import youtube_dl
st.title("YouTube Video Player with Customizable Subtitles")
# Function to extract subtitles using youtube_dl
def get_subtitles(video_url):
ydl_opts = {
'format': 'best',
'noplaylist': True,
'writesubtitles': True,
'subtitleslangs': ['en'],
'outtmpl': '%(id)s.%(ext)s',
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
info_dict = ydl.extract_info(video_url, download=True)
subtitles = info_dict.get('subtitles', None)
return subtitles
video_url = st.text_input("Enter YouTube Video URL:")
if video_url:
st.video(video_url)
subtitles = get_subtitles(video_url)
if subtitles:
st.write("Subtitles: ")
# Displaying available subtitle languages
for lang, subtitle in subtitles.items():
st.write(f"- Language: {lang}")
# Example customization options
subtitle_size = st.slider("Select subtitle size:", 12, 40, 18)
is_bold = st.checkbox("Bold")
is_italic = st.checkbox("Italic")
is_underline = st.checkbox("Underline")
color = st.color_picker("Choose subtitle color:", '#FFFFFF')
st.write(f"Subtitle size: {subtitle_size}px, Bold: {is_bold}, Italic: {is_italic}, Underline: {is_underline}, Color: {color}")
# This part would involve additional JS/CSS for dynamic updates
else:
st.write("No subtitles found for this video.")
st.write("## Additional Features:")
st.write("- Option to select different speakers and color-code subtitles based on their identities.")
st.write("- Background opacity options for subtitles.")
st.write("- Adjustable playback speed.")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?