From b3c58db791676dbadd4388a54b6d41f1633a9607 Mon Sep 17 00:00:00 2001 From: Jordan Shatford Date: Tue, 17 Oct 2023 13:12:59 +1100 Subject: [PATCH] feat(core): simplify checking if download is audio or video Signed-off-by: Jordan Shatford --- core/ydcore/config/__init__.py | 22 ++++++++++------------ core/ydcore/models.py | 5 ----- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/core/ydcore/config/__init__.py b/core/ydcore/config/__init__.py index a21175a7..43750179 100644 --- a/core/ydcore/config/__init__.py +++ b/core/ydcore/config/__init__.py @@ -5,7 +5,6 @@ from ..models import AudioFormat from ..models import DownloadState from ..models import DownloadStatus -from ..models import DownloadType from ..models import VideoFormat from ..models import VideoWithOptions from ..models import VideoWithOptionsAndStatus @@ -54,26 +53,25 @@ def has_conflicts(self) -> bool: return False @property - def _download_type(self) -> DownloadType: - if self._video.options.format in VideoFormat: - return DownloadType.VIDEO - elif self._video.options.format in AudioFormat: - return DownloadType.AUDIO - else: - return DownloadType.VIDEO + def _is_audio_download(self) -> bool: + return self._video.options.format in AudioFormat + + @property + def _is_video_download(self) -> bool: + return self._video.options.format in VideoFormat @property def as_ytdlp_params(self) -> YoutubeDLParams: postprocessors: list[dict[str, str | bool | int]] = [] # Only append audio postprocessor if we are downloading audio format. - if self._download_type == DownloadType.AUDIO: + if self._is_audio_download: postprocessors.append({ 'key': 'FFmpegExtractAudio', 'preferredcodec': self._video.options.format.value, 'preferredquality': '192', }) # Only append video postprocessor if we are downloading video format. - if self._download_type == DownloadType.VIDEO: + if self._is_video_download: postprocessors.append( { 'key': 'FFmpegVideoConvertor', @@ -116,11 +114,11 @@ def _ytdlp_format(self) -> str: extension = options.format.value # bestvideo*[ext=X]+bestaudio/bestvideo*+bestaudio/best or # worstvideo*[ext=X]+worstaudio/worstvideo*+worstaudio/worst - if (self._download_type == DownloadType.VIDEO): + if self._is_video_download: proper_ext = f'{quality}video*[ext={extension}]+{quality}audio' return f'{proper_ext}/{quality}video*+{quality}audio/{quality}' # bestaudio[ext=X]/bestaudio/best or worstaudio[ext=X]/worstaudio/worst - elif (self._download_type == DownloadType.AUDIO): + elif self._is_audio_download: return f'{quality}audio[ext={extension}]/{quality}audio/{quality}' # Default to returning the quality (ie 'best' or 'worst') return quality diff --git a/core/ydcore/models.py b/core/ydcore/models.py index c8b374d5..faeb328d 100644 --- a/core/ydcore/models.py +++ b/core/ydcore/models.py @@ -37,11 +37,6 @@ class DownloadStatus(BaseModel): postprocessor: str | None = None -class DownloadType(str, enum.Enum): - AUDIO = 'audio' - VIDEO = 'video' - - class AudioFormat(str, enum.Enum): AAC = 'aac' FLAC = 'flac'