working directory getting cleaned

This commit is contained in:
Jesse Bannon 2022-11-30 00:20:48 -08:00
parent deb6de56b7
commit 959c5dfc9d
3 changed files with 24 additions and 9 deletions

View file

@ -208,11 +208,13 @@ class SubtitlesPlugin(Plugin[SubtitleOptions]):
entry=entry, entry=entry,
) )
# Delete any possible original subtitle files before conversion # Delete any possible original subtitle files before conversion
for possible_ext in SUBTITLE_EXTENSIONS: # Can happen for both file and embedded subs
possible_subs_file = ( for lang in langs:
Path(self.working_directory) / f"{entry.uid}.{lang}.{possible_ext}" for possible_ext in SUBTITLE_EXTENSIONS:
) possible_subs_file = (
FileHandler.delete(possible_subs_file) Path(self.working_directory) / f"{entry.uid}.{lang}.{possible_ext}"
)
FileHandler.delete(possible_subs_file)
return file_metadata return file_metadata

View file

@ -166,6 +166,12 @@ class SubscriptionDownload(BaseSubscription, ABC):
return plugins return plugins
@classmethod
def _cleanup_entry_files(cls, entry: Entry):
FileHandler.delete(entry.get_download_file_path())
FileHandler.delete(entry.get_download_thumbnail_path())
FileHandler.delete(entry.get_download_info_json_path())
def _post_process_entry( def _post_process_entry(
self, plugins: List[Plugin], dry_run: bool, entry: Entry, entry_metadata: FileMetadata self, plugins: List[Plugin], dry_run: bool, entry: Entry, entry_metadata: FileMetadata
): ):
@ -184,6 +190,9 @@ class SubscriptionDownload(BaseSubscription, ABC):
if self.maintain_download_archive: if self.maintain_download_archive:
self._enhanced_download_archive.save_download_mappings() self._enhanced_download_archive.save_download_mappings()
# Clean up any files that remain
self._cleanup_entry_files(entry=entry)
def _process_entry( def _process_entry(
self, plugins: List[Plugin], dry_run: bool, entry: Entry, entry_metadata: FileMetadata self, plugins: List[Plugin], dry_run: bool, entry: Entry, entry_metadata: FileMetadata
) -> None: ) -> None:
@ -278,9 +287,7 @@ class SubscriptionDownload(BaseSubscription, ABC):
plugins=plugins, dry_run=dry_run, entry=entry, entry_metadata=entry_metadata plugins=plugins, dry_run=dry_run, entry=entry, entry_metadata=entry_metadata
) )
FileHandler.delete(entry.get_download_file_path()) self._cleanup_entry_files(entry=entry)
FileHandler.delete(entry.get_download_thumbnail_path())
FileHandler.delete(entry.get_download_info_json_path())
for plugin in plugins: for plugin in plugins:
plugin.post_process_subscription() plugin.post_process_subscription()

View file

@ -24,6 +24,12 @@ from ytdl_sub.entries.variables.kwargs import UPLOAD_DATE
from ytdl_sub.entries.variables.kwargs import WEBPAGE_URL from ytdl_sub.entries.variables.kwargs import WEBPAGE_URL
@pytest.fixture
def working_directory() -> str:
with tempfile.TemporaryDirectory() as temp_dir:
yield temp_dir
@pytest.fixture @pytest.fixture
def subscription_name(working_directory) -> str: def subscription_name(working_directory) -> str:
name = "subscription_test" name = "subscription_test"