Ajusta parametros
This commit is contained in:
29
main.py
29
main.py
@@ -159,7 +159,7 @@ def download_video(
|
|||||||
|
|
||||||
quality_targets = {"low": 480, "medium": 720, "high": 1080}
|
quality_targets = {"low": 480, "medium": 720, "high": 1080}
|
||||||
qualidade = qualidade.lower()
|
qualidade = qualidade.lower()
|
||||||
|
|
||||||
if qualidade not in quality_targets:
|
if qualidade not in quality_targets:
|
||||||
raise HTTPException(status_code=400, detail="Qualidade deve ser: low, medium ou high")
|
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())
|
unique_id = str(uuid.uuid4())
|
||||||
outtmpl = os.path.join(videos_dir, f"{unique_id}.%(ext)s")
|
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 = (
|
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"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}]/"
|
f"b[height<={target_height}]/"
|
||||||
|
# último recurso: qualquer best
|
||||||
f"b"
|
f"b"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -188,13 +185,17 @@ def download_video(
|
|||||||
"quiet": True,
|
"quiet": True,
|
||||||
"no_warnings": True,
|
"no_warnings": True,
|
||||||
"ignoreerrors": False,
|
"ignoreerrors": False,
|
||||||
"no_color": True,
|
"noplaylist": True,
|
||||||
"noplaylist": True, # não tratar como playlist
|
"format": fmt_expr,
|
||||||
"format": fmt_expr, # <<< chave da correção
|
"merge_output_format": "mp4",
|
||||||
"merge_output_format": "mp4", # força saída mp4 quando há merge
|
"force_ipv4": True,
|
||||||
# NUNCA usar force_generic_extractor p/ YouTube
|
"geo_bypass": True,
|
||||||
# NUNCA usar extract_flat aqui
|
"extractor_args": {
|
||||||
# NÃO usar allow_unplayable_formats
|
"youtube": {
|
||||||
|
"player_client": ["android"],
|
||||||
|
"player_skip": ["webpage"]
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user