remove more
This commit is contained in:
parent
126ed4716f
commit
14bbb5d887
3 changed files with 1 additions and 87 deletions
|
|
@ -12,7 +12,6 @@ from mergedeep import mergedeep
|
||||||
|
|
||||||
from ytdl_sub.config.config_validator import ConfigValidator
|
from ytdl_sub.config.config_validator import ConfigValidator
|
||||||
from ytdl_sub.config.plugin import Plugin
|
from ytdl_sub.config.plugin import Plugin
|
||||||
from ytdl_sub.config.preset_class_mappings import DownloadStrategyMapping
|
|
||||||
from ytdl_sub.config.preset_class_mappings import PluginMapping
|
from ytdl_sub.config.preset_class_mappings import PluginMapping
|
||||||
from ytdl_sub.config.preset_options import OptionsValidator
|
from ytdl_sub.config.preset_options import OptionsValidator
|
||||||
from ytdl_sub.config.preset_options import OutputOptions
|
from ytdl_sub.config.preset_options import OutputOptions
|
||||||
|
|
@ -39,10 +38,10 @@ from ytdl_sub.validators.validators import validation_exception
|
||||||
|
|
||||||
PRESET_KEYS = {
|
PRESET_KEYS = {
|
||||||
"preset",
|
"preset",
|
||||||
|
"download",
|
||||||
"output_options",
|
"output_options",
|
||||||
"ytdl_options",
|
"ytdl_options",
|
||||||
"overrides",
|
"overrides",
|
||||||
*DownloadStrategyMapping.sources(),
|
|
||||||
*PluginMapping.plugins(),
|
*PluginMapping.plugins(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ from typing import List
|
||||||
from typing import Type
|
from typing import Type
|
||||||
|
|
||||||
from ytdl_sub.config.plugin import Plugin
|
from ytdl_sub.config.plugin import Plugin
|
||||||
from ytdl_sub.downloaders.source_plugin import SourcePlugin
|
|
||||||
from ytdl_sub.downloaders.url.downloader import MultiUrlDownloader
|
|
||||||
from ytdl_sub.plugins.audio_extract import AudioExtractPlugin
|
from ytdl_sub.plugins.audio_extract import AudioExtractPlugin
|
||||||
from ytdl_sub.plugins.chapters import ChaptersPlugin
|
from ytdl_sub.plugins.chapters import ChaptersPlugin
|
||||||
from ytdl_sub.plugins.date_range import DateRangePlugin
|
from ytdl_sub.plugins.date_range import DateRangePlugin
|
||||||
|
|
@ -21,83 +19,6 @@ from ytdl_sub.plugins.subtitles import SubtitlesPlugin
|
||||||
from ytdl_sub.plugins.video_tags import VideoTagsPlugin
|
from ytdl_sub.plugins.video_tags import VideoTagsPlugin
|
||||||
|
|
||||||
|
|
||||||
class DownloadStrategyMapping:
|
|
||||||
"""
|
|
||||||
Maps downloader strategies defined in the preset to its respective downloader class
|
|
||||||
"""
|
|
||||||
|
|
||||||
_MAPPING: Dict[str, Dict[str, Type[SourcePlugin]]] = {
|
|
||||||
"download": {
|
|
||||||
"multi_url": MultiUrlDownloader,
|
|
||||||
"url": MultiUrlDownloader,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def sources(cls) -> List[str]:
|
|
||||||
"""
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
Available download sources
|
|
||||||
"""
|
|
||||||
return sorted(list(cls._MAPPING.keys()))
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _validate_is_source(cls, source: str) -> None:
|
|
||||||
"""
|
|
||||||
Ensure the source exists
|
|
||||||
"""
|
|
||||||
if source not in cls.sources():
|
|
||||||
raise ValueError(
|
|
||||||
f"Tried to use source '{source}' which does not exist. Available sources: "
|
|
||||||
f"{', '.join(cls.sources())}"
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def source_download_strategies(cls, source: str) -> List[str]:
|
|
||||||
"""
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
source
|
|
||||||
Name of the source
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
Available download strategies for the given source
|
|
||||||
"""
|
|
||||||
cls._validate_is_source(source)
|
|
||||||
return sorted(list(cls._MAPPING[source].keys()))
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _validate_is_download_strategy(cls, source: str, download_strategy: str) -> None:
|
|
||||||
"""
|
|
||||||
Ensure the download strategy for the given source exists
|
|
||||||
"""
|
|
||||||
if download_strategy not in cls.source_download_strategies(source):
|
|
||||||
raise ValueError(
|
|
||||||
f"Tried to use download strategy '{download_strategy}' with source '{source}', "
|
|
||||||
f"which does not exist. Available download strategies: "
|
|
||||||
f"{', '.join(cls.source_download_strategies(source))}"
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get(cls, source: str, download_strategy: str) -> Type[SourcePlugin]:
|
|
||||||
"""
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
source:
|
|
||||||
The source (i.e. 'youtube', 'soundcloud') of the downloader
|
|
||||||
download_strategy:
|
|
||||||
The download strategy name
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
The downloader class
|
|
||||||
"""
|
|
||||||
cls._validate_is_download_strategy(source, download_strategy)
|
|
||||||
return cls._MAPPING[source][download_strategy]
|
|
||||||
|
|
||||||
|
|
||||||
class PluginMapping:
|
class PluginMapping:
|
||||||
"""
|
"""
|
||||||
Maps plugins defined in the preset to its respective plugin class
|
Maps plugins defined in the preset to its respective plugin class
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import pytest
|
||||||
|
|
||||||
from ytdl_sub.config.config_file import ConfigFile
|
from ytdl_sub.config.config_file import ConfigFile
|
||||||
from ytdl_sub.config.preset import PRESET_KEYS
|
from ytdl_sub.config.preset import PRESET_KEYS
|
||||||
from ytdl_sub.config.preset_class_mappings import DownloadStrategyMapping
|
|
||||||
from ytdl_sub.config.preset_class_mappings import PluginMapping
|
from ytdl_sub.config.preset_class_mappings import PluginMapping
|
||||||
from ytdl_sub.utils.exceptions import ValidationException
|
from ytdl_sub.utils.exceptions import ValidationException
|
||||||
|
|
||||||
|
|
@ -57,11 +56,6 @@ class TestConfigFilePartiallyValidatesPresets:
|
||||||
if plugin not in excluded_plugins:
|
if plugin not in excluded_plugins:
|
||||||
self._partial_validate({plugin: {}})
|
self._partial_validate({plugin: {}})
|
||||||
|
|
||||||
@pytest.mark.parametrize("source", DownloadStrategyMapping.sources())
|
|
||||||
def test_success__empty_sources(self, source: str):
|
|
||||||
for download_strategy in DownloadStrategyMapping.source_download_strategies(source):
|
|
||||||
self._partial_validate({source: {"download_strategy": download_strategy}})
|
|
||||||
|
|
||||||
def test_error__bad_preset_section(self):
|
def test_error__bad_preset_section(self):
|
||||||
self._partial_validate(
|
self._partial_validate(
|
||||||
preset_dict={"does_not_exist": "lol"},
|
preset_dict={"does_not_exist": "lol"},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue