File size: 1,599 Bytes
41c943c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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}")