Ajusta parametros

This commit is contained in:
LeoMortari
2025-09-28 19:35:14 -03:00
parent 9df4e20578
commit defe489f80

29
main.py
View File

@@ -159,7 +159,7 @@ def download_video(
quality_targets = {"low": 480, "medium": 720, "high": 1080}
qualidade = qualidade.lower()
if qualidade not in quality_targets:
raise HTTPException(status_code=400, detail="Qualidade deve ser: low, medium ou high")
@@ -171,15 +171,12 @@ def download_video(
unique_id = str(uuid.uuid4())
outtmpl = os.path.join(videos_dir, f"{unique_id}.%(ext)s")
# Expressão de formato robusta:
# 1) Tenta bestvideo até a altura desejada + bestaudio (mp4/m4a quando der)
# 2) Cai para best [altura<=] em um único arquivo
# 3) Finalmente qualquer best disponível
fmt_expr = (
f"bv*[height<={target_height}][ext=mp4]+ba[ext=m4a]/"
# tenta vídeo <= alvo + melhor áudio
f"bv*[height<={target_height}]+ba/"
f"b[height<={target_height}][ext=mp4]/"
# cai pra qualquer melhor vídeo <= alvo (progressivo se houver)
f"b[height<={target_height}]/"
# último recurso: qualquer best
f"b"
)
@@ -188,13 +185,17 @@ def download_video(
"quiet": True,
"no_warnings": True,
"ignoreerrors": False,
"no_color": True,
"noplaylist": True, # não tratar como playlist
"format": fmt_expr, # <<< chave da correção
"merge_output_format": "mp4", # força saída mp4 quando há merge
# NUNCA usar force_generic_extractor p/ YouTube
# NUNCA usar extract_flat aqui
# NÃO usar allow_unplayable_formats
"noplaylist": True,
"format": fmt_expr,
"merge_output_format": "mp4",
"force_ipv4": True,
"geo_bypass": True,
"extractor_args": {
"youtube": {
"player_client": ["android"],
"player_skip": ["webpage"]
}
},
}
try: