фикс2
This commit is contained in:
parent
09347b45ec
commit
5dac739e17
1 changed files with 75 additions and 54 deletions
|
|
@ -187,10 +187,16 @@ async def download_and_convert(
|
||||||
temp_template = output_path.parent / f"temp_{output_path.name}.%(ext)s"
|
temp_template = output_path.parent / f"temp_{output_path.name}.%(ext)s"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
formats_to_try = [
|
||||||
|
'bestaudio[ext=m4a]/bestaudio[ext=webm]/bestaudio/best',
|
||||||
|
'bestaudio/best',
|
||||||
|
]
|
||||||
|
|
||||||
|
async def _run_yt_dlp(format_selector: str):
|
||||||
cmd = [
|
cmd = [
|
||||||
'yt-dlp',
|
'yt-dlp',
|
||||||
'-x', # Извлечь аудио
|
'-x', # Извлечь аудио
|
||||||
'-f', 'bestaudio[ext=m4a]/bestaudio[ext=webm]/bestaudio/best',
|
'-f', format_selector,
|
||||||
'--hls-prefer-ffmpeg',
|
'--hls-prefer-ffmpeg',
|
||||||
'--audio-format', 'mp3',
|
'--audio-format', 'mp3',
|
||||||
'--audio-quality', '0', # Лучшее качество
|
'--audio-quality', '0', # Лучшее качество
|
||||||
|
|
@ -211,7 +217,7 @@ async def download_and_convert(
|
||||||
if config.ytdlp_force_ipv4:
|
if config.ytdlp_force_ipv4:
|
||||||
cmd.append('--force-ipv4')
|
cmd.append('--force-ipv4')
|
||||||
|
|
||||||
logger.info(f"Downloading {url}")
|
logger.info(f"Downloading {url} with format: {format_selector}")
|
||||||
|
|
||||||
process = await asyncio.create_subprocess_exec(
|
process = await asyncio.create_subprocess_exec(
|
||||||
*cmd,
|
*cmd,
|
||||||
|
|
@ -241,12 +247,27 @@ async def download_and_convert(
|
||||||
await process.wait()
|
await process.wait()
|
||||||
await stderr_task
|
await stderr_task
|
||||||
await stdout_task
|
await stdout_task
|
||||||
|
return process.returncode, list(stderr_tail) + list(stdout_tail)
|
||||||
|
|
||||||
if process.returncode != 0:
|
last_tail: list[str] = []
|
||||||
|
for fmt in formats_to_try:
|
||||||
|
returncode, tail_lines = await _run_yt_dlp(fmt)
|
||||||
|
last_tail = tail_lines
|
||||||
|
if returncode == 0:
|
||||||
|
break
|
||||||
|
tail_text = "\n".join(tail_lines[-12:]) if tail_lines else ""
|
||||||
|
if "Requested format is not available" in tail_text:
|
||||||
|
logger.warning("yt-dlp format unavailable, retrying with fallback")
|
||||||
|
continue
|
||||||
logger.error("yt-dlp failed")
|
logger.error("yt-dlp failed")
|
||||||
tail_lines = list(stderr_tail) + list(stdout_tail)
|
if tail_text:
|
||||||
if tail_lines:
|
raise Exception(f"Ошибка скачивания: yt-dlp завершился с ошибкой\n{tail_text}")
|
||||||
tail_text = "\n".join(tail_lines[-12:])
|
raise Exception("Ошибка скачивания: yt-dlp завершился с ошибкой")
|
||||||
|
|
||||||
|
if returncode != 0:
|
||||||
|
logger.error("yt-dlp failed")
|
||||||
|
if last_tail:
|
||||||
|
tail_text = "\n".join(last_tail[-12:])
|
||||||
raise Exception(f"Ошибка скачивания: yt-dlp завершился с ошибкой\n{tail_text}")
|
raise Exception(f"Ошибка скачивания: yt-dlp завершился с ошибкой\n{tail_text}")
|
||||||
raise Exception("Ошибка скачивания: yt-dlp завершился с ошибкой")
|
raise Exception("Ошибка скачивания: yt-dlp завершился с ошибкой")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue