[FEATURE] No longer require a config.yaml
This commit is contained in:
parent
545f186c46
commit
3d648c916a
6 changed files with 24 additions and 16 deletions
|
|
@ -11,7 +11,7 @@ from colorama import Fore
|
||||||
from yt_dlp.utils import sanitize_filename
|
from yt_dlp.utils import sanitize_filename
|
||||||
|
|
||||||
from ytdl_sub.cli.download_args_parser import DownloadArgsParser
|
from ytdl_sub.cli.download_args_parser import DownloadArgsParser
|
||||||
from ytdl_sub.cli.main_args_parser import parser
|
from ytdl_sub.cli.main_args_parser import parser, DEFAULT_CONFIG_FILE_NAME
|
||||||
from ytdl_sub.config.config_file import ConfigFile
|
from ytdl_sub.config.config_file import ConfigFile
|
||||||
from ytdl_sub.subscriptions.subscription import Subscription
|
from ytdl_sub.subscriptions.subscription import Subscription
|
||||||
from ytdl_sub.utils.exceptions import ExperimentalFeatureNotEnabled
|
from ytdl_sub.utils.exceptions import ExperimentalFeatureNotEnabled
|
||||||
|
|
@ -303,7 +303,14 @@ def main() -> List[Tuple[Subscription, FileHandlerTransactionLog]]:
|
||||||
args, extra_args = parser.parse_known_args()
|
args, extra_args = parser.parse_known_args()
|
||||||
|
|
||||||
# Load the config
|
# Load the config
|
||||||
config: ConfigFile = ConfigFile.from_file_path(args.config)
|
config: ConfigFile = ConfigFile(name="config", value={})
|
||||||
|
if args.config:
|
||||||
|
config = ConfigFile.from_file_path(args.config)
|
||||||
|
elif os.path.isfile(DEFAULT_CONFIG_FILE_NAME):
|
||||||
|
config = ConfigFile.from_file_path(DEFAULT_CONFIG_FILE_NAME)
|
||||||
|
else:
|
||||||
|
logger.debug("No config specified, using defaults")
|
||||||
|
|
||||||
transaction_logs: List[Tuple[Subscription, FileHandlerTransactionLog]] = []
|
transaction_logs: List[Tuple[Subscription, FileHandlerTransactionLog]] = []
|
||||||
|
|
||||||
# If transaction log file is specified, make sure we can open it
|
# If transaction log file is specified, make sure we can open it
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ from typing import List
|
||||||
from ytdl_sub import __local_version__
|
from ytdl_sub import __local_version__
|
||||||
from ytdl_sub.utils.logger import LoggerLevels
|
from ytdl_sub.utils.logger import LoggerLevels
|
||||||
|
|
||||||
|
DEFAULT_CONFIG_FILE_NAME: str = "config.yaml"
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
class CLIArgument:
|
class CLIArgument:
|
||||||
|
|
@ -86,8 +88,8 @@ def _add_shared_arguments(arg_parser: argparse.ArgumentParser, suppress_defaults
|
||||||
MainArguments.CONFIG.long,
|
MainArguments.CONFIG.long,
|
||||||
metavar="CONFIGPATH",
|
metavar="CONFIGPATH",
|
||||||
type=str,
|
type=str,
|
||||||
help="path to the config yaml, uses config.yaml if not provided",
|
# Default is set downstream
|
||||||
default=argparse.SUPPRESS if suppress_defaults else "config.yaml",
|
help=f"path to the config yaml, uses {DEFAULT_CONFIG_FILE_NAME} if not provided",
|
||||||
)
|
)
|
||||||
arg_parser.add_argument(
|
arg_parser.add_argument(
|
||||||
MainArguments.DRY_RUN.short,
|
MainArguments.DRY_RUN.short,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ from ytdl_sub.validators.file_path_validators import FilePathValidatorMixin
|
||||||
|
|
||||||
|
|
||||||
class ConfigFile(ConfigValidator):
|
class ConfigFile(ConfigValidator):
|
||||||
_required_keys = {"configuration", "presets"}
|
|
||||||
|
|
||||||
def __init__(self, name: str, value: Any):
|
def __init__(self, name: str, value: Any):
|
||||||
super().__init__(name, value)
|
super().__init__(name, value)
|
||||||
|
|
|
||||||
|
|
@ -96,8 +96,8 @@ class PersistLogsValidator(StrictDictValidator):
|
||||||
|
|
||||||
|
|
||||||
class ConfigOptions(StrictDictValidator):
|
class ConfigOptions(StrictDictValidator):
|
||||||
_required_keys = {"working_directory"}
|
|
||||||
_optional_keys = {
|
_optional_keys = {
|
||||||
|
"working_directory",
|
||||||
"umask",
|
"umask",
|
||||||
"dl_aliases",
|
"dl_aliases",
|
||||||
"persist_logs",
|
"persist_logs",
|
||||||
|
|
@ -112,8 +112,8 @@ class ConfigOptions(StrictDictValidator):
|
||||||
def __init__(self, name: str, value: Any):
|
def __init__(self, name: str, value: Any):
|
||||||
super().__init__(name, value)
|
super().__init__(name, value)
|
||||||
|
|
||||||
self._working_directory = self._validate_key(
|
self._working_directory = self._validate_key_if_present(
|
||||||
key="working_directory", validator=StringValidator
|
key="working_directory", validator=StringValidator, default=".ytdl-sub-temp-directory"
|
||||||
)
|
)
|
||||||
self._umask = self._validate_key_if_present(
|
self._umask = self._validate_key_if_present(
|
||||||
key="umask", validator=StringValidator, default="022"
|
key="umask", validator=StringValidator, default="022"
|
||||||
|
|
@ -244,14 +244,16 @@ class ConfigOptions(StrictDictValidator):
|
||||||
|
|
||||||
|
|
||||||
class ConfigValidator(StrictDictValidator):
|
class ConfigValidator(StrictDictValidator):
|
||||||
_required_keys = {"configuration", "presets"}
|
_optional_keys = {"configuration", "presets"}
|
||||||
|
|
||||||
def __init__(self, name: str, value: Any):
|
def __init__(self, name: str, value: Any):
|
||||||
super().__init__(name, value)
|
super().__init__(name, value)
|
||||||
self.config_options = self._validate_key("configuration", ConfigOptions)
|
self.config_options = self._validate_key_if_present(
|
||||||
|
"configuration", ConfigOptions, default={}
|
||||||
|
)
|
||||||
|
|
||||||
# Make sure presets is a dictionary. Will be validated in `PresetValidator`
|
# Make sure presets is a dictionary. Will be validated in `PresetValidator`
|
||||||
self.presets = self._validate_key("presets", LiteralDictValidator)
|
self.presets = self._validate_key_if_present("presets", LiteralDictValidator, default={})
|
||||||
|
|
||||||
# Ensure custom presets do not collide with prebuilt presets
|
# Ensure custom presets do not collide with prebuilt presets
|
||||||
for preset_name in self.presets.keys:
|
for preset_name in self.presets.keys:
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,11 @@ class TestView:
|
||||||
@pytest.mark.parametrize("split_chapters", [True, False])
|
@pytest.mark.parametrize("split_chapters", [True, False])
|
||||||
def test_view_from_cli(
|
def test_view_from_cli(
|
||||||
self,
|
self,
|
||||||
music_video_config_path,
|
|
||||||
output_directory,
|
output_directory,
|
||||||
split_chapters,
|
split_chapters,
|
||||||
):
|
):
|
||||||
|
|
||||||
args = f"--config {music_video_config_path} view "
|
args = f"view "
|
||||||
args += "--split-chapters " if split_chapters else ""
|
args += "--split-chapters " if split_chapters else ""
|
||||||
args += f"https://www.youtube.com/playlist?list=PLBsm_SagFMmdWnCnrNtLjA9kzfrRkto4i"
|
args += f"https://www.youtube.com/playlist?list=PLBsm_SagFMmdWnCnrNtLjA9kzfrRkto4i"
|
||||||
subscription_transaction_log = mock_run_from_cli(args=args)
|
subscription_transaction_log = mock_run_from_cli(args=args)
|
||||||
|
|
|
||||||
|
|
@ -150,19 +150,18 @@ class TestPlaylist:
|
||||||
)
|
)
|
||||||
|
|
||||||
@pytest.mark.parametrize("dry_run", [True, False])
|
@pytest.mark.parametrize("dry_run", [True, False])
|
||||||
def test_playlist_download_from_cli_sub(
|
def test_playlist_download_from_cli_sub_no_provided_config(
|
||||||
self,
|
self,
|
||||||
preset_dict_to_subscription_yaml_generator,
|
preset_dict_to_subscription_yaml_generator,
|
||||||
music_video_config_for_cli,
|
|
||||||
playlist_preset_dict,
|
playlist_preset_dict,
|
||||||
output_directory,
|
output_directory,
|
||||||
dry_run,
|
dry_run,
|
||||||
):
|
):
|
||||||
|
# No config needed when using only prebuilt presets
|
||||||
with preset_dict_to_subscription_yaml_generator(
|
with preset_dict_to_subscription_yaml_generator(
|
||||||
subscription_name="music_video_playlist_test", preset_dict=playlist_preset_dict
|
subscription_name="music_video_playlist_test", preset_dict=playlist_preset_dict
|
||||||
) as subscription_path:
|
) as subscription_path:
|
||||||
args = "--dry-run " if dry_run else ""
|
args = "--dry-run " if dry_run else ""
|
||||||
args += f"--config {music_video_config_for_cli} "
|
|
||||||
args += f"sub {subscription_path}"
|
args += f"sub {subscription_path}"
|
||||||
subscription_transaction_log = mock_run_from_cli(args=args)
|
subscription_transaction_log = mock_run_from_cli(args=args)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue