ytdl-sub/src/ytdl_sub/validators/audo_codec_validator.py
Jesse Bannon da70c725fc
[FEATURE] Support best codec type in audio_extract (#700)
Adds support to the `audio_extract` plugin (https://ytdl-sub.readthedocs.io/en/latest/config.html#audio-extract) to the following to grab the best audio format available:

```
audio_extract:
  codec: "best"
```
2023-09-02 00:50:26 -07:00

29 lines
895 B
Python

from typing import Dict
from typing import Set
from ytdl_sub.validators.string_select_validator import StringSelectValidator
AUDIO_CODEC_TYPES_EXTENSION_MAPPING: Dict[str, str] = {
"aac": "aac",
"flac": "flac",
"mp3": "mp3",
"m4a": "m4a",
"opus": "opus",
"vorbis": "ogg",
"wav": "wav",
}
AUDIO_CODEC_TYPES: Set[str] = set(AUDIO_CODEC_TYPES_EXTENSION_MAPPING.keys())
AUDIO_CODEC_EXTS: Set[str] = set(AUDIO_CODEC_TYPES_EXTENSION_MAPPING.values())
VIDEO_CODEC_EXTS: Set[str] = {"avi", "flv", "mkv", "mov", "mp4", "webm"}
class AudioTypeValidator(StringSelectValidator):
_expected_value_type_name = "codec"
_select_values = AUDIO_CODEC_TYPES.union({"best"}) # support 'best' in the audio extract plugin
class FileTypeValidator(StringSelectValidator):
_expected_value_type_name = "codec"
_select_values = AUDIO_CODEC_TYPES.union(VIDEO_CODEC_EXTS)