From 3abc18071301505290ec627029694ff42756c47d Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Tue, 3 Oct 2023 10:54:02 -0700 Subject: [PATCH] masdf --- .../subscriptions/base_subscription.py | 34 ++++--------------- .../enhanced_download_archive.py | 11 +++--- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/src/ytdl_sub/subscriptions/base_subscription.py b/src/ytdl_sub/subscriptions/base_subscription.py index 6ae830a9..a0ab94e5 100644 --- a/src/ytdl_sub/subscriptions/base_subscription.py +++ b/src/ytdl_sub/subscriptions/base_subscription.py @@ -1,6 +1,6 @@ -import os from abc import ABC from pathlib import Path +from typing import Optional from ytdl_sub.config.config_validator import ConfigOptions from ytdl_sub.config.preset import Preset @@ -47,39 +47,17 @@ class BaseSubscription(ABC): self._config_options = config_options self._preset_options = preset_options + migrated_file_name: Optional[str] = None + if migrated_file_name_option := self.output_options.migrated_download_archive_name: + migrated_file_name = self.overrides.apply_formatter(migrated_file_name_option) + self._enhanced_download_archive = EnhancedDownloadArchive( file_name=self.overrides.apply_formatter(self.output_options.download_archive_name), working_directory=self.working_directory, output_directory=self.output_directory, + migrated_file_name=migrated_file_name, ) - if self.output_options.migrated_download_archive_name: - migrated_download_archive = EnhancedDownloadArchive( - file_name=self.overrides.apply_formatter( - self.output_options.migrated_download_archive_name - ), - working_directory=self.working_directory, - output_directory=self.output_directory, - ) - - # If the migrated archive file does not exist, but the original does, then inject the - # migrated file name into the original one. That makes it save to the migrated one - if not os.path.isfile(migrated_download_archive.output_file_path) and os.path.isfile( - self._enhanced_download_archive.output_file_path - ): - logger.warning( - "ARCHIVE MIGRATION DETECTED, will write download archive file to %s", - self._enhanced_download_archive.output_file_path, - ) - self._enhanced_download_archive._file_name = migrated_download_archive.file_name - else: - logger.warning( - "Loading migrated archive file, can now replace " - "`output_options.download_archive` value with the contents of " - "`output_options.migrated_download_archive`" - ) - self._enhanced_download_archive = migrated_download_archive - @property def downloader_options(self) -> MultiUrlValidator: """ diff --git a/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py b/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py index cf2da045..82574c31 100644 --- a/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py +++ b/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py @@ -375,15 +375,14 @@ class EnhancedDownloadArchive: "`output_options.migrated_download_archive`" ) return DownloadMappings.from_file(migrated_mapping_file_path) - else: - logger.warning( - "MIGRATION DETECTED, will write archive file to %s", migrated_mapping_file_path - ) + + logger.warning( + "MIGRATION DETECTED, will write archive file to %s", migrated_mapping_file_path + ) if os.path.isfile(mapping_file_path): return DownloadMappings.from_file(json_file_path=mapping_file_path) - else: - return DownloadMappings() + return DownloadMappings() def __init__( self,