Spaces:
Runtime error
Runtime error
Download app.py from SkyDataSoluction/BaixarVideoYouTube: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/spaces/SkyDataSoluction/BaixarVideoYouTube/resolve/main/app.py
- Command line
-
hf download hf://spaces/SkyDataSoluction/BaixarVideoYouTube/app.py
-
curl -L -o app.py https://huggingface.co/spaces/SkyDataSoluction/BaixarVideoYouTube/resolve/main/app.py
1.6 kB
| import streamlit as st | |
| import yt_dlp | |
| import os | |
| st.set_page_config(page_title="Streamlit Video Downloader", page_icon="🎬") | |
| st.title("🎬 Downloader de Vídeos") | |
| url_usuario = st.text_input("Insira o link do YouTube:") | |
| if st.button("Gerar Download"): | |
| if url_usuario: | |
| try: | |
| # Limpa a URL de parâmetros extras de playlist | |
| url_limpa = url_usuario.split("&")[0] | |
| ydl_opts = { | |
| 'format': 'best[ext=mp4]/best', | |
| 'outtmpl': 'video_final.%(ext)s', | |
| # Emula o cliente Android para evitar erros de indisponibilidade | |
| 'extractor_args': {'youtube': {'player_client': ['android']}}, | |
| 'quiet': True, | |
| } | |
| # Vincula os cookies caso o arquivo tenha sido subido | |
| if os.path.exists('cookies.txt'): | |
| ydl_opts['cookiefile'] = 'cookies.txt' | |
| with st.spinner("Processando..."): | |
| with yt_dlp.YoutubeDL(ydl_opts) as ydl: | |
| info = ydl.extract_info(url_limpa, download=True) | |
| filename = ydl.prepare_filename(info) | |
| st.success("✅ Processamento concluído!") | |
| with open(filename, "rb") as f: | |
| st.download_button( | |
| label="📥 SALVAR VÍDEO", | |
| data=f, | |
| file_name=f"{info.get('title', 'video')}.mp4", | |
| mime="video/mp4" | |
| ) | |
| except Exception as e: | |
| st.error(f"Ocorreu um erro: {e}") |