This commit is contained in:
Jesse Bannon 2023-03-12 23:18:09 -07:00
parent b318bc737f
commit 2eeaf2b2b0
3 changed files with 99 additions and 16 deletions

View file

@ -1,5 +1,4 @@
import contextlib import contextlib
import copy
import json import json
import os import os
import shutil import shutil
@ -24,7 +23,6 @@ from ytdl_sub.utils.file_handler import FileMetadata
from ytdl_sub.utils.file_handler import get_file_extension from ytdl_sub.utils.file_handler import get_file_extension
from ytdl_sub.utils.thumbnail import convert_download_thumbnail from ytdl_sub.utils.thumbnail import convert_download_thumbnail
from ytdl_sub.ytdl_additions.enhanced_download_archive import DownloadMappings from ytdl_sub.ytdl_additions.enhanced_download_archive import DownloadMappings
from ytdl_sub.ytdl_additions.enhanced_download_archive import EnhancedDownloadArchive
def _get_split_plugin(plugins: List[Plugin]) -> Optional[Plugin]: def _get_split_plugin(plugins: List[Plugin]) -> Optional[Plugin]:
@ -157,14 +155,12 @@ class SubscriptionDownload(BaseSubscription, ABC):
try: try:
yield yield
finally: finally:
if self._enhanced_download_archive.is_dry_run: if not self._enhanced_download_archive.is_dry_run:
return for root, dir_names, filenames in os.walk(Path(self.output_directory), topdown=False):
for dir_name in dir_names:
for root, dir_names, filenames in os.walk(Path(self.output_directory), topdown=False): dir_path = Path(root) / dir_name
for dir_name in dir_names: if len(os.listdir(dir_path)) == 0:
dir_path = Path(root) / dir_name os.rmdir(dir_path)
if len(os.listdir(dir_path)) == 0:
os.rmdir(dir_path)
@contextlib.contextmanager @contextlib.contextmanager
def _subscription_download_context_managers(self) -> None: def _subscription_download_context_managers(self) -> None:
@ -370,14 +366,14 @@ class SubscriptionDownload(BaseSubscription, ABC):
entry_mapping.append((maybe_entry, download_mapping.file_names)) entry_mapping.append((maybe_entry, download_mapping.file_names))
for entry, file_names in entry_mapping: for entry, file_names in entry_mapping:
file_names_mtime: Dict[Path, float] = {} file_names_mtime: Dict[str, float] = {}
for file_name in file_names: for file_name in file_names:
ext = get_file_extension(file_name) ext = get_file_extension(file_name)
file_path = Path(self.output_directory) / file_name file_path = Path(self.output_directory) / file_name
working_directory_file_path = Path(self.working_directory) / f"{entry.uid}.{ext}" working_directory_file_path = Path(self.working_directory) / f"{entry.uid}.{ext}"
file_names_mtime[file_path] = os.path.getmtime(file_path) file_names_mtime[file_name] = os.path.getmtime(file_path)
# NFO files will always get rewritten, so ignore # NFO files will always get rewritten, so ignore
if ext == "nfo": if ext == "nfo":
@ -391,11 +387,13 @@ class SubscriptionDownload(BaseSubscription, ABC):
yield entry yield entry
for file_path, mtime in file_names_mtime.items(): for file_name, mtime in file_names_mtime.items():
# If the entry file_path is unchanged, then delete it since it was not part of the # If the entry file_path is unchanged, then delete it since it was not part of the
# reformat output # reformat output
if os.path.getmtime(file_path) == mtime: if os.path.getmtime(Path(self.output_directory) / file_name) == mtime:
FileHandler.delete(file_path) self._enhanced_download_archive._file_handler.delete_file_from_output_directory(
file_name
)
def update_with_info_json(self, dry_run: bool = False) -> FileHandlerTransactionLog: def update_with_info_json(self, dry_run: bool = False) -> FileHandlerTransactionLog:
plugins = self._initialize_plugins() plugins = self._initialize_plugins()

View file

@ -0,0 +1,82 @@
Files created:
----------------------------------------
{output_directory}/Season 2020
s2020.e000001 - Mock Entry --thumb.jpg
s2020.e000001 - Mock Entry -.info.json
s2020.e000001 - Mock Entry -.mp4
Video Tags:
date: 2020-08-07
episode_id: 1
genre: ytdl-sub
show: unit_plex_tv_show_by_date_season_by_year__episode_by_month_day_is_yt_1
synopsis:
https://20-3.com
The Description
title: 2020-08-07 - Mock Entry 20-3
year: 2020
s2020.e000002 - Mock Entry --thumb.jpg
s2020.e000002 - Mock Entry -.info.json
s2020.e000002 - Mock Entry -.mp4
Video Tags:
date: 2020-08-08
episode_id: 2
genre: ytdl-sub
show: unit_plex_tv_show_by_date_season_by_year__episode_by_month_day_is_yt_1
synopsis:
https://20-2.com
The Description
title: 2020-08-08 - Mock Entry 20-2
year: 2020
s2020.e000003 - Mock Entry --thumb.jpg
s2020.e000003 - Mock Entry -.info.json
s2020.e000003 - Mock Entry -.mp4
Video Tags:
date: 2020-08-08
episode_id: 3
genre: ytdl-sub
show: unit_plex_tv_show_by_date_season_by_year__episode_by_month_day_is_yt_1
synopsis:
https://20-1.com
The Description
title: 2020-08-08 - Mock Entry 20-1
year: 2020
{output_directory}/Season 2021
s2021.e000004 - Mock Entry --thumb.jpg
s2021.e000004 - Mock Entry -.info.json
s2021.e000004 - Mock Entry -.mp4
Video Tags:
date: 2021-08-08
episode_id: 4
genre: ytdl-sub
show: unit_plex_tv_show_by_date_season_by_year__episode_by_month_day_is_yt_1
synopsis:
https://21-1.com
The Description
title: 2021-08-08 - Mock Entry 21-1
year: 2021
Files modified:
----------------------------------------
{output_directory}
.ytdl-sub-subscription_test-download-archive.json
Files removed:
----------------------------------------
{output_directory}/Season 2020
s2020.e080701 - Mock Entry --thumb.jpg
s2020.e080701 - Mock Entry -.info.json
s2020.e080701 - Mock Entry -.mp4
s2020.e080801 - Mock Entry --thumb.jpg
s2020.e080801 - Mock Entry -.info.json
s2020.e080801 - Mock Entry -.mp4
s2020.e080802 - Mock Entry --thumb.jpg
s2020.e080802 - Mock Entry -.info.json
s2020.e080802 - Mock Entry -.mp4
{output_directory}/Season 2021
s2021.e080801 - Mock Entry --thumb.jpg
s2021.e080801 - Mock Entry -.info.json
s2021.e080801 - Mock Entry -.mp4

View file

@ -135,7 +135,10 @@ class TestPrebuiltTVShowPresets:
assert_transaction_log_matches( assert_transaction_log_matches(
output_directory=output_directory, output_directory=output_directory,
transaction_log=reformatted_transaction_log, transaction_log=reformatted_transaction_log,
transaction_log_summary_file_name=f"{reformatted_expected_summary_name}.txt", transaction_log_summary_file_name=(
f"{expected_summary_name}_reformatted_to_{reformatted_expected_summary_name}.txt"
),
regenerate_transaction_log=True
) )
assert_expected_downloads( assert_expected_downloads(
output_directory=output_directory, output_directory=output_directory,