DHEIVER's picture
Create app.py
091e634 verified
raw
history blame
1.19 kB
import gradio as gr
from pytube import YouTube
import os
def download_youtube_video(url):
try:
# Criar um objeto YouTube
yt = YouTube(url)
# Selecionar a stream de maior resolução em formato MP4
stream = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()
# Verificar se a stream foi encontrada
if not stream:
return "Erro: Nenhuma stream MP4 disponível."
# Fazer o download do vídeo
output_path = stream.download(output_path="downloads")
# Retornar o caminho do arquivo baixado
return output_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."
)
# Criar a pasta de downloads, se não existir
os.makedirs("downloads", exist_ok=True)
# Iniciar a interface
iface.launch()