ytdl-sub/src/ytdl_sub/utils/ffmpeg.py
Jesse Bannon 1620c3a42d
youtube.download_strategy split_video (#76)
* youtube.download_strategy split_video

* almost working, need to deal with track_title and other overwrites

* working test

* ci ffmpeg

* sudo -f

* fix code block
2022-06-18 23:12:10 -07:00

35 lines
1 KiB
Python

import subprocess
from typing import List
from ytdl_sub.utils.exceptions import ValidationException
from ytdl_sub.utils.logger import Logger
logger = Logger.get(name="ffmpeg")
class FFMPEG:
@classmethod
def _ensure_installed(cls):
try:
subprocess.check_output(["which", "ffmpeg"])
except subprocess.CalledProcessError as subprocess_error:
raise ValidationException(
"Trying to use a feature which requires ffmpeg, but it cannot be found"
) from subprocess_error
@classmethod
def run(cls, ffmpeg_args: List[str]) -> None:
"""
Runs an ffmpeg command. Should not include 'ffmpeg' as the beginning argument.
Parameters
----------
ffmpeg_args:
Arguments to pass to ffmpeg. Each one will be separated by a space.
"""
cls._ensure_installed()
cmd = ["ffmpeg"]
cmd.extend(ffmpeg_args)
logger.debug("Running %s", " ".join(cmd))
subprocess.run(cmd, check=True)