DHEIVER commited on
Commit
3db65c1
·
verified ·
1 Parent(s): 5d37f14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -16
app.py CHANGED
@@ -1,27 +1,22 @@
1
  import gradio as gr
2
- from pytube import YouTube
3
  import os
4
 
5
  def download_youtube_video(url):
6
  try:
7
- # Criar um objeto YouTube
8
- yt = YouTube(url)
 
 
 
 
 
9
 
10
- # Selecionar a stream de maior resolução em formato MP4
11
- stream = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()
12
-
13
- # Verificar se a stream foi encontrada
14
- if not stream:
15
- return "Erro: Nenhuma stream MP4 disponível."
16
 
17
  # Fazer o download do vídeo
18
- output_path = stream.download(output_path="downloads")
19
-
20
- # Retornar o caminho do arquivo baixado
21
- return output_path
22
-
23
- except Exception as e:
24
- return f"Erro ao baixar o vídeo: {str(e)}"
25
 
26
  # Interface Gradio
27
  iface = gr.Interface(
 
1
  import gradio as gr
2
+ import yt_dlp as youtube_dl
3
  import os
4
 
5
  def download_youtube_video(url):
6
  try:
7
+ # Configurações do yt-dlp
8
+ ydl_opts = {
9
+ 'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best', # Forçar formato MP4
10
+ 'outtmpl': 'downloads/%(title)s.%(ext)s', # Salvar na pasta "downloads" com o título do vídeo
11
+ 'quiet': True, # Evitar logs desnecessários
12
+ 'no_warnings': True, # Ignorar avisos
13
+ }
14
 
15
+ # Criar a pasta de downloads, se não existir
16
+ os.makedirs("downloads", exist_ok=True)
 
 
 
 
17
 
18
  # Fazer o download do vídeo
19
+ with youtube_dl.YoutubeDL(
 
 
 
 
 
 
20
 
21
  # Interface Gradio
22
  iface = gr.Interface(