Provides options to make ytdl-sub look more 'human-like' to protect from throttling. For range-based values, a random number will be chosen within the range to avoid sleeps looking scripted.
Usage:
```
throttle_protection:
sleep_per_download_s:
min: 2.2
max: 10.8
sleep_per_subscription_s:
min: 9.0
max: 14.1
max_downloads_per_subscription:
min: 10
max: 36
subscription_download_probability: 1.0
```
79 lines
2.6 KiB
Python
79 lines
2.6 KiB
Python
from typing import Dict
|
|
from typing import List
|
|
from typing import Type
|
|
|
|
from ytdl_sub.config.plugin import Plugin
|
|
from ytdl_sub.plugins.audio_extract import AudioExtractPlugin
|
|
from ytdl_sub.plugins.chapters import ChaptersPlugin
|
|
from ytdl_sub.plugins.date_range import DateRangePlugin
|
|
from ytdl_sub.plugins.embed_thumbnail import EmbedThumbnailPlugin
|
|
from ytdl_sub.plugins.file_convert import FileConvertPlugin
|
|
from ytdl_sub.plugins.format import FormatPlugin
|
|
from ytdl_sub.plugins.internal.view import ViewPlugin
|
|
from ytdl_sub.plugins.match_filters import MatchFiltersPlugin
|
|
from ytdl_sub.plugins.music_tags import MusicTagsPlugin
|
|
from ytdl_sub.plugins.nfo_tags import NfoTagsPlugin
|
|
from ytdl_sub.plugins.output_directory_nfo_tags import OutputDirectoryNfoTagsPlugin
|
|
from ytdl_sub.plugins.regex import RegexPlugin
|
|
from ytdl_sub.plugins.split_by_chapters import SplitByChaptersPlugin
|
|
from ytdl_sub.plugins.subtitles import SubtitlesPlugin
|
|
from ytdl_sub.plugins.throttle_protection import ThrottleProtectionPlugin
|
|
from ytdl_sub.plugins.video_tags import VideoTagsPlugin
|
|
|
|
|
|
class PluginMapping:
|
|
"""
|
|
Maps plugins defined in the preset to its respective plugin class
|
|
"""
|
|
|
|
_MAPPING: Dict[str, Type[Plugin]] = {
|
|
"_view": ViewPlugin,
|
|
"audio_extract": AudioExtractPlugin,
|
|
"date_range": DateRangePlugin,
|
|
"embed_thumbnail": EmbedThumbnailPlugin,
|
|
"file_convert": FileConvertPlugin,
|
|
"format": FormatPlugin,
|
|
"match_filters": MatchFiltersPlugin,
|
|
"music_tags": MusicTagsPlugin,
|
|
"video_tags": VideoTagsPlugin,
|
|
"nfo_tags": NfoTagsPlugin,
|
|
"output_directory_nfo_tags": OutputDirectoryNfoTagsPlugin,
|
|
"regex": RegexPlugin,
|
|
"subtitles": SubtitlesPlugin,
|
|
"chapters": ChaptersPlugin,
|
|
"split_by_chapters": SplitByChaptersPlugin,
|
|
"throttle_protection": ThrottleProtectionPlugin,
|
|
}
|
|
|
|
@classmethod
|
|
def plugins(cls) -> List[str]:
|
|
"""
|
|
Returns
|
|
-------
|
|
Available download sources
|
|
"""
|
|
return sorted(list(cls._MAPPING.keys()))
|
|
|
|
@classmethod
|
|
def get(cls, plugin: str) -> Type[Plugin]:
|
|
"""
|
|
Parameters
|
|
----------
|
|
plugin
|
|
Name of the plugin
|
|
|
|
Returns
|
|
-------
|
|
The plugin class
|
|
|
|
Raises
|
|
------
|
|
ValueError
|
|
Raised if the plugin does not exist
|
|
"""
|
|
if plugin not in cls.plugins():
|
|
raise ValueError(
|
|
f"Tried to use plugin '{plugin}' that does not exist. Available plugins: "
|
|
f"{', '.join(cls.plugins())}"
|
|
)
|
|
return cls._MAPPING[plugin]
|