DHEIVER's picture
Update app.py
a88c09a verified
raw
history blame
1.49 kB
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()