Skip to content

Commit

Permalink
ignore ytdlp MaxDownloadsReached
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Jul 9, 2024
1 parent e657481 commit 23c3028
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion daras_ai_v2/asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from daras_ai.image_input import upload_file_from_bytes, gs_url_to_uri
from daras_ai_v2 import settings
from daras_ai_v2.azure_asr import azure_asr
from daras_ai_v2.enum_selector_widget import BLANK_OPTION
from daras_ai_v2.exceptions import (
raise_for_status,
UserError,
Expand Down Expand Up @@ -980,6 +979,8 @@ def download_youtube_to_wav(youtube_url: str) -> bytes:
"--format", "bestaudio",
"--output", infile,
youtube_url,
# ignore MaxDownloadsReached - https://github.com/ytdl-org/youtube-dl/blob/a452f9437c8a3048f75fc12f75bcfd3eed78430f/youtube_dl/__init__.py#L468
ok_returncodes={101},
) # fmt:skip
# convert audio to single channel wav
ffmpeg("-i", infile, *FFMPEG_WAV_ARGS, outfile)
Expand Down
7 changes: 6 additions & 1 deletion daras_ai_v2/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import subprocess
import typing

import requests
from loguru import logger
Expand Down Expand Up @@ -81,11 +82,15 @@ def ffprobe(filename: str) -> dict:
return json.loads(text)


def call_cmd(*args, err_msg: str = "") -> str:
def call_cmd(
*args, err_msg: str = "", ok_returncodes: typing.Iterable[int] = ()
) -> str:
logger.info("$ " + " ".join(map(str, args)))
try:
return subprocess.check_output(args, stderr=subprocess.STDOUT, text=True)
except subprocess.CalledProcessError as e:
if e.returncode in ok_returncodes:
return e.output
err_msg = err_msg or f"{str(args[0]).capitalize()} Error"
try:
raise subprocess.SubprocessError(e.output) from e
Expand Down

0 comments on commit 23c3028

Please sign in to comment.