more refactoring
This commit is contained in:
parent
f46a1f3e98
commit
b97fb3b7f9
3 changed files with 41 additions and 27 deletions
|
|
@ -11,7 +11,6 @@ from ytdl_sub.config.preset_options import Overrides
|
|||
from ytdl_sub.downloaders.ytdl_options_builder import YTDLOptionsBuilder
|
||||
from ytdl_sub.entries.entry import Entry
|
||||
from ytdl_sub.plugins.plugin import Plugin
|
||||
from ytdl_sub.plugins.plugin import PluginOptions
|
||||
from ytdl_sub.ytdl_additions.enhanced_download_archive import DownloadArchiver
|
||||
from ytdl_sub.ytdl_additions.enhanced_download_archive import EnhancedDownloadArchive
|
||||
|
||||
|
|
@ -19,20 +18,20 @@ BaseDownloaderValidator = OptionsValidator
|
|||
BaseDownloaderOptionsT = TypeVar("BaseDownloaderOptionsT", bound=BaseDownloaderValidator)
|
||||
|
||||
|
||||
class BaseDownloaderPluginOptions(PluginOptions):
|
||||
_optional_keys = {"no-op"}
|
||||
|
||||
|
||||
class BaseDownloaderPlugin(Plugin[BaseDownloaderOptionsT], Generic[BaseDownloaderOptionsT], ABC):
|
||||
class BaseDownloaderPlugin(Plugin[BaseDownloaderOptionsT], ABC):
|
||||
"""
|
||||
Plugins that get added automatically by using a downloader. Downloader options
|
||||
are the plugin options.
|
||||
"""
|
||||
def __init__(
|
||||
self,
|
||||
downloader_options: BaseDownloaderOptionsT,
|
||||
overrides: Overrides,
|
||||
enhanced_download_archive: EnhancedDownloadArchive,
|
||||
):
|
||||
super().__init__(
|
||||
# Downloader plugins do not have exposed YAML options, so keep it blank.
|
||||
# Use init instead.
|
||||
plugin_options=BaseDownloaderPluginOptions(name=self.__class__.__name__, value={}),
|
||||
# Downloader plugins use download options as their plugin options
|
||||
plugin_options=downloader_options,
|
||||
overrides=overrides,
|
||||
enhanced_download_archive=enhanced_download_archive,
|
||||
)
|
||||
|
|
@ -63,9 +62,14 @@ class BaseDownloader(DownloadArchiver, Generic[BaseDownloaderOptionsT], ABC):
|
|||
def download(self, entry: Entry) -> Entry:
|
||||
"""The function to perform the download of all media entries"""
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def added_plugins(self) -> List[BaseDownloaderPlugin]:
|
||||
# pylint: disable=unused-argument
|
||||
@classmethod
|
||||
def added_plugins(
|
||||
cls,
|
||||
downloader_options: BaseDownloaderOptionsT,
|
||||
enhanced_download_archive: EnhancedDownloadArchive,
|
||||
overrides: Overrides,
|
||||
) -> List[BaseDownloaderPlugin]:
|
||||
"""Add these plugins from the Downloader to the subscription"""
|
||||
return []
|
||||
|
||||
# pylint: enable=no-self-use
|
||||
# pylint: enable=unused-argument
|
||||
|
|
|
|||
|
|
@ -87,18 +87,19 @@ class URLDownloadState:
|
|||
class UrlDownloaderThumbnailPlugin(BaseDownloaderPlugin):
|
||||
def __init__(
|
||||
self,
|
||||
downloader_options: DownloaderValidator,
|
||||
overrides: Overrides,
|
||||
enhanced_download_archive: EnhancedDownloadArchive,
|
||||
collection_urls: List[UrlValidator],
|
||||
):
|
||||
super().__init__(
|
||||
downloader_options=downloader_options,
|
||||
overrides=overrides,
|
||||
enhanced_download_archive=enhanced_download_archive,
|
||||
)
|
||||
self._thumbnails_downloaded: Set[str] = set()
|
||||
self._collection_url_mapping: Dict[str, UrlValidator] = {
|
||||
self.overrides.apply_formatter(collection_url.url): collection_url
|
||||
for collection_url in collection_urls
|
||||
for collection_url in downloader_options.collection_validator.urls.list
|
||||
}
|
||||
|
||||
def _download_parent_thumbnails(
|
||||
|
|
@ -185,18 +186,19 @@ class UrlDownloaderThumbnailPlugin(BaseDownloaderPlugin):
|
|||
class UrlDownloaderCollectionVariablePlugin(BaseDownloaderPlugin):
|
||||
def __init__(
|
||||
self,
|
||||
downloader_options: DownloaderValidator,
|
||||
overrides: Overrides,
|
||||
enhanced_download_archive: EnhancedDownloadArchive,
|
||||
collection_urls: List[UrlValidator],
|
||||
):
|
||||
super().__init__(
|
||||
downloader_options=downloader_options,
|
||||
overrides=overrides,
|
||||
enhanced_download_archive=enhanced_download_archive,
|
||||
)
|
||||
self._thumbnails_downloaded: Set[str] = set()
|
||||
self._collection_url_mapping: Dict[str, UrlValidator] = {
|
||||
self.overrides.apply_formatter(collection_url.url): collection_url
|
||||
for collection_url in collection_urls
|
||||
for collection_url in downloader_options.collection_validator.urls.list
|
||||
}
|
||||
|
||||
def modify_entry_metadata(self, entry: Entry) -> Optional[Entry]:
|
||||
|
|
@ -218,7 +220,13 @@ class BaseUrlDownloader(BaseDownloader[BaseDownloaderOptionsT], ABC):
|
|||
and should translate that to list of Entry objects.
|
||||
"""
|
||||
|
||||
def added_plugins(self) -> List[Plugin]:
|
||||
@classmethod
|
||||
def added_plugins(
|
||||
cls,
|
||||
downloader_options: BaseDownloaderOptionsT,
|
||||
enhanced_download_archive: EnhancedDownloadArchive,
|
||||
overrides: Overrides,
|
||||
) -> List[Plugin]:
|
||||
"""
|
||||
Adds
|
||||
1. URL thumbnail download plugin
|
||||
|
|
@ -226,14 +234,14 @@ class BaseUrlDownloader(BaseDownloader[BaseDownloaderOptionsT], ABC):
|
|||
"""
|
||||
return [
|
||||
UrlDownloaderThumbnailPlugin(
|
||||
overrides=self.overrides,
|
||||
enhanced_download_archive=self._enhanced_download_archive,
|
||||
collection_urls=self.collection.urls.list,
|
||||
downloader_options=downloader_options,
|
||||
overrides=overrides,
|
||||
enhanced_download_archive=enhanced_download_archive,
|
||||
),
|
||||
UrlDownloaderCollectionVariablePlugin(
|
||||
overrides=self.overrides,
|
||||
enhanced_download_archive=self._enhanced_download_archive,
|
||||
collection_urls=self.collection.urls.list,
|
||||
downloader_options=downloader_options,
|
||||
overrides=overrides,
|
||||
enhanced_download_archive=enhanced_download_archive,
|
||||
),
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -275,7 +275,11 @@ class SubscriptionDownload(BaseSubscription, ABC):
|
|||
directory.
|
||||
"""
|
||||
self._enhanced_download_archive.reinitialize(dry_run=dry_run)
|
||||
plugins = self._initialize_plugins()
|
||||
plugins = self._initialize_plugins() + self.downloader_class.added_plugins(
|
||||
downloader_options=self.downloader_options,
|
||||
enhanced_download_archive=self._enhanced_download_archive,
|
||||
overrides=self.overrides,
|
||||
)
|
||||
|
||||
subscription_ytdl_options = SubscriptionYTDLOptions(
|
||||
preset=self._preset_options,
|
||||
|
|
@ -292,8 +296,6 @@ class SubscriptionDownload(BaseSubscription, ABC):
|
|||
metadata_ytdl_options=subscription_ytdl_options.metadata_builder(),
|
||||
overrides=self.overrides,
|
||||
)
|
||||
# This could be cleaned up....
|
||||
plugins.extend(downloader.added_plugins())
|
||||
|
||||
with self._subscription_download_context_managers():
|
||||
for entry in downloader.download_metadata():
|
||||
|
|
|
|||
Loading…
Reference in a new issue