Spaces:
Running
Running
File size: 1,486 Bytes
091e634 3db65c1 091e634 3db65c1 a88c09a 3db65c1 a88c09a 091e634 a88c09a 091e634 |
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 |
import gradio as gr
import yt_dlp as youtube_dl
import os
def download_youtube_video(url):
try:
# Configurações do yt-dlp
ydl_opts = {
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best', # Forçar formato MP4
'outtmpl': 'downloads/%(title)s.%(ext)s', # Salvar na pasta "downloads" com o título do vídeo
'quiet': True, # Evitar logs desnecessários
'no_warnings': True, # Ignorar avisos
}
# Criar a pasta de downloads, se não existir
os.makedirs("downloads", exist_ok=True)
# Fazer o download do vídeo
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=True)
video_title = info.get('title', 'video')
video_ext = info.get('ext', 'mp4')
downloaded_file_path = f"downloads/{video_title}.{video_ext}"
# Retornar o caminho do vídeo baixado
return downloaded_file_path
except Exception as e:
return f"Erro ao baixar o vídeo: {str(e)}"
# Interface Gradio
iface = gr.Interface(
fn=download_youtube_video,
inputs=gr.Textbox(label="Link do YouTube", placeholder="Cole o link do vídeo aqui..."),
outputs=gr.Video(label="Vídeo Baixado"),
title="Download de Vídeos do YouTube",
description="Cole o link de um vídeo do YouTube para baixá-lo em formato MP4."
)
# Iniciar a interface
iface.launch() |