ccxccc
Update app.py
cb7758f verified
raw
history blame
2.33 kB
import streamlit as st
from pytube import YouTube
class YouTubeDownloader:
@staticmethod
def run():
st.title("YouTube Video Downloader")
# Header Layout
header_container = st.container()
with header_container:
st.write("")
st.write("## Welcome to our YouTube Downloader")
st.write("")
st.write("")
col1, col2 = st.columns(2)
if col1.button("Login", key="login_button"):
# Login button functionality
st.write("Redirecting to login page...")
if col2.button("Sign Up", key="signup_button"):
# Sign Up button functionality
st.write("Redirecting to sign up page")
st.write("")
st.write("")
url = st.text_input("Enter YouTube URL to download:")
if url:
YouTubeDownloader.validate_url(url)
with st.expander("Preview Video"):
st.video(url)
if st.button("Download"):
YouTubeDownloader.cleanup()
file_ = YouTubeDownloader.download_video(url)
st.video(file_)
YouTubeDownloader.helper_message()
st.markdown("App made by miles")
@staticmethod
def download_video(url):
with st.spinner("Downloading..."):
local_file = (
YouTube(url)
.streams.filter(progressive=True, file_extension="mp4")
.first()
.download()
)
st.success("Downloaded")
return local_file
@staticmethod
def validate_url(url):
import validators
if not validators.url(url):
st.error("Hi there 👋 URL seems invalid 👽")
st.stop()
@classmethod
def cleanup(cls):
import pathlib
import glob
junks = glob.glob("*.mp4")
for junk in junks:
pathlib.Path(junk).unlink()
@classmethod
def helper_message(cls):
st.write(
"> To save the video to the local computer, "
"click the vertical ... icon (aka hamburger button) in the bottom-right corner (in the video above) and click download."
)
if __name__ == "__main__":
YouTubeDownloader.run()