Download app.py from Geek7/dl: direct link, hf CLI and curl.
- Browser
- Download file 2.05 kB
-
https://huggingface.co/spaces/Geek7/dl/resolve/main/app.py
- Command line
-
hf download hf://spaces/Geek7/dl/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Geek7/dl/resolve/main/app.py
2.05 kB
| import streamlit as st | |
| from pytube import YouTube | |
| hide_streamlit_style = """ | |
| <style> | |
| #MainMenu {visibility: hidden;} | |
| footer {visibility: hidden;} | |
| .stApp{ | |
| background-image: linear-gradient(115deg,#FFAF00,#FFC500,#FFD600,#FCED00,#F9F380,#F6F7CD); | |
| animation: rotate 7s linear infinite; | |
| } | |
| @keyframes rotate { | |
| 100%{ | |
| filter: hue-rotate(-360deg) | |
| } | |
| } | |
| </style> | |
| """ | |
| st.markdown(hide_streamlit_style, unsafe_allow_html=True) | |
| class YouTubeDownloader: | |
| def run(): | |
| st.header("") | |
| url = st.text_input("Enter Here") | |
| start_button = st.button("Start") | |
| if start_button: | |
| if url: | |
| YouTubeDownloader.validate_url(url) | |
| with st.expander("preview video"): | |
| st.video(url) | |
| YouTubeDownloader.cleanup() | |
| file_ = YouTubeDownloader.download_video(url) | |
| st.video(file_) | |
| YouTubeDownloader.helper_message() | |
| st.markdown("") | |
| 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 | |
| def validate_url(url): | |
| import validators | |
| if not validators.url(url): | |
| st.error("Hi there ๐ URL seems invalid ๐ฝ") | |
| st.stop() | |
| def cleanup(cls): | |
| import pathlib | |
| import glob | |
| junks = glob.glob("*.mp4") | |
| for junk in junks: | |
| pathlib.Path(junk).unlink() | |
| def helper_message(cls): | |
| st.write( | |
| "> To save 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() | |