Spaces:
Sleeping
Sleeping
Update app.py
Browse files126 unmodified lines1271281291301311321331341351361371381396 unmodified lines1461471481491501511521531541551561571581591601611621631641651661671681691701714 unmodified lines176177178179180181126 unmodified linestry:print(f" 📥 Iniciando download...")# Lista de formatos em ordem de prioridade (do melhor para aceitável)format_options = ["best[height<=720][ext=mp4]", # Ideal"best[height<=720]", # Sem exigir MP4"best[height<=480][ext=mp4]", # Resolução menor"best[height<=480]", # Resolução menor, qualquer formato"best", # Qualquer vídeo disponível]for idx, fmt in enumerate(format_options, 1):6 unmodified lines"--no-warnings","--no-check-certificate","--no-playlist","--socket-timeout", "30",video_url]try:result = subprocess.run(cmd, capture_output=True, text=True, timeout=300)if os.path.exists(output_path) and os.path.getsize(output_path) > 100000:size_mb = os.path.getsize(output_path) / 1024 / 1024print(f" ✅ Download OK: {size_mb:.1f}MB (formato: {fmt})")return Trueelse:print(f" ⚠️ Formato '{fmt}' falhou, tentando próximo...")# Limpar arquivo parcialif os.path.exists(output_path):os.remove(output_path)continueexcept subprocess.TimeoutExpired:print(f" ⏱️ Timeout no formato '{fmt}', tentando próximo...")if os.path.exists(output_path):os.remove(output_path)continue4 unmodified linesexcept Exception as e:print(f" ❌ Erro crítico no download: {e}")return Falsedef convert_video(input_file, output_60s, output_120s):126 unmodified lines1271281291301311321331341351361371386 unmodified lines1451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811824 unmodified lines187188189190191192193194126 unmodified linestry:print(f" 📥 Iniciando download...")# Lista de formatos em ordem de prioridadeformat_options = ["bestvideo[height<=720][ext=mp4]+bestaudio[ext=m4a]/best[height<=720][ext=mp4]","bestvideo[height<=720]+bestaudio/best[height<=720]","bestvideo[height<=480]+bestaudio/best[height<=480]","best[ext=mp4]/best",]for idx, fmt in enumerate(format_options, 1):6 unmodified lines"--no-warnings","--no-check-certificate","--no-playlist","--user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36","--referer", "https://www.youtube.com/","--extractor-args", "youtube:player_client=android","--socket-timeout", "30","--retries", "3","--fragment-retries", "3",video_url]try:result = subprocess.run(cmd, capture_output=True, text=True, timeout=300)# Mostrar stdout e stderr para debugif result.stdout:print(f" STDOUT: {result.stdout[:500]}")if result.stderr:print(f" STDERR: {result.stderr[:500]}")if os.path.exists(output_path) and os.path.getsize(output_path) > 100000:size_mb = os.path.getsize(output_path) / 1024 / 1024print(f" ✅ Download OK: {size_mb:.1f}MB (formato: {fmt})")return Trueelse:print(f" ⚠️ Formato '{fmt}' falhou")print(f" Return code: {result.returncode}")# Limpar arquivo parcialif os.path.exists(output_path):os.remove(output_path)continueexcept subprocess.TimeoutExpired:print(f" ⏱️ Timeout no formato '{fmt}'")if os.path.exists(output_path):os.remove(output_path)continue4 unmodified linesexcept Exception as e:print(f" ❌ Erro crítico no download: {e}")import tracebacktraceback.print_exc()return Falsedef convert_video(input_file, output_60s, output_120s):
app.py+21-8