From 2f100a319d231d943e31d3d7b51fb632645c3541 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Sat, 11 Mar 2023 23:48:35 -0800 Subject: [PATCH] working?!?! --- .../subscriptions/subscription_download.py | 21 +++++++----- tests/conftest.py | 4 +++ tests/e2e/youtube/test_channel.py | 34 +++++++++++++++++-- .../youtube/test_channel_full.json | 14 +++++++- .../youtube/test_channel_full.txt | 12 +++++++ 5 files changed, 72 insertions(+), 13 deletions(-) diff --git a/src/ytdl_sub/subscriptions/subscription_download.py b/src/ytdl_sub/subscriptions/subscription_download.py index c493ed72..8b20c91e 100644 --- a/src/ytdl_sub/subscriptions/subscription_download.py +++ b/src/ytdl_sub/subscriptions/subscription_download.py @@ -342,19 +342,22 @@ class SubscriptionDownload(BaseSubscription, ABC): for entry, file_names in entry_mapping: for file_name in file_names: - # Remove any subdirectory part of the file name - _, file_name_no_dirs = os.path.split(Path(file_name)) - ext = get_file_extension(file_name_no_dirs) + ext = get_file_extension(file_name) - FileHandler.copy( - src_file_path=Path(self.output_directory) / file_name, - dst_file_path=Path(self.working_directory) / f"{entry.uid}.{ext}", - ) + # NFO files will always get rewritten, so ignore + if ext == "nfo": + continue - yield entry + if not original_enhanced_download_archive.is_dry_run: + FileHandler.copy( + src_file_path=Path(self.output_directory) / file_name, + dst_file_path=Path(self.working_directory) / f"{entry.uid}.{ext}", + ) + + yield entry def reformat( - self, reformat_output_directory: str, dry_run: bool = False + self, reformat_output_directory: Path, dry_run: bool = False ) -> FileHandlerTransactionLog: original_enhanced_download_archive = self._enhanced_download_archive self._enhanced_download_archive = EnhancedDownloadArchive( diff --git a/tests/conftest.py b/tests/conftest.py index e15d9e19..66abf88a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -70,6 +70,10 @@ def output_directory() -> Path: with tempfile.TemporaryDirectory() as temp_dir: yield temp_dir +@pytest.fixture() +def reformat_directory() -> Path: + with tempfile.TemporaryDirectory() as temp_dir: + yield temp_dir @contextlib.contextmanager def assert_logs(logger: logging.Logger, expected_message: str, log_level: str = "debug"): diff --git a/tests/e2e/youtube/test_channel.py b/tests/e2e/youtube/test_channel.py index b7053f81..2b179076 100644 --- a/tests/e2e/youtube/test_channel.py +++ b/tests/e2e/youtube/test_channel.py @@ -1,4 +1,8 @@ +from pathlib import Path + import pytest +from yt_dlp.utils import sanitize_filename + from expected_download import assert_expected_downloads from expected_transaction_log import assert_transaction_log_matches @@ -8,7 +12,10 @@ from ytdl_sub.subscriptions.subscription import Subscription @pytest.fixture def channel_preset_dict(output_directory): return { - "preset": "tv_show", + "preset": [ + "tv_show", + "include_info_json", + ], "ytdl_options": { "format": "worst[ext=mp4]", # download the worst format so it is fast "max_views": 100000, # do not download the popular PJ concert @@ -44,17 +51,21 @@ class TestChannel: """ @pytest.mark.parametrize("dry_run", [True, False]) - def test_full_channel_download( + @pytest.mark.parametrize("reformat", [True, False]) + def test_full_channel_download_and_reformat( self, channel_as_tv_show_config, + music_video_config, channel_preset_dict, output_directory, + reformat_directory, dry_run, + reformat, ): full_channel_subscription = Subscription.from_dict( config=channel_as_tv_show_config, preset_name="pz", preset_dict=channel_preset_dict ) - transaction_log = full_channel_subscription.download(dry_run=dry_run) + transaction_log = full_channel_subscription.download(dry_run=dry_run and not reformat) assert_transaction_log_matches( output_directory=output_directory, transaction_log=transaction_log, @@ -65,3 +76,20 @@ class TestChannel: dry_run=dry_run, expected_download_summary_file_name="youtube/test_channel_full.json", ) + + if not reformat: + return + + reformat_directory = Path(reformat_directory) / sanitize_filename("Project / Zombie") + full_channel_subscription.reformat(reformat_output_directory=reformat_directory, dry_run=dry_run) + assert_transaction_log_matches( + output_directory=reformat_directory, + transaction_log=transaction_log, + transaction_log_summary_file_name="youtube/test_channel_full.txt", + ) + assert_expected_downloads( + output_directory=reformat_directory, + dry_run=dry_run, + expected_download_summary_file_name="youtube/test_channel_full.json", + ) + diff --git a/tests/resources/expected_downloads_summaries/youtube/test_channel_full.json b/tests/resources/expected_downloads_summaries/youtube/test_channel_full.json index dbfc6a6d..0f6bdc0e 100644 --- a/tests/resources/expected_downloads_summaries/youtube/test_channel_full.json +++ b/tests/resources/expected_downloads_summaries/youtube/test_channel_full.json @@ -1,40 +1,52 @@ { - "Project ⧸ Zombie/.ytdl-sub-pz-download-archive.json": "d385fc7b7a3b45240b9dbb70d63c7d0a", + "Project ⧸ Zombie/.ytdl-sub-pz-download-archive.json": "aadb59c92dcf14ee6617c77423a14584", "Project ⧸ Zombie/Season 2010/s2010.e081301 - Oblivion Mod "Falcor" p.1-thumb.jpg": "fb95b510681676e81c321171fc23143e", + "Project ⧸ Zombie/Season 2010/s2010.e081301 - Oblivion Mod "Falcor" p.1.info.json": "2a615e0e226f005ea4055cd9e0afffeb", "Project ⧸ Zombie/Season 2010/s2010.e081301 - Oblivion Mod "Falcor" p.1.mp4": "6aab51d2ebb374dc965970cbacd00bda", "Project ⧸ Zombie/Season 2010/s2010.e081301 - Oblivion Mod "Falcor" p.1.nfo": "265da8ee62357739c1b353e1a3b3e8e8", "Project ⧸ Zombie/Season 2010/s2010.e120201 - Oblivion Mod "Falcor" p.2-thumb.jpg": "8b32ee9c037fa669e444a0ac181525a1", + "Project ⧸ Zombie/Season 2010/s2010.e120201 - Oblivion Mod "Falcor" p.2.info.json": "31be1b16f32be5fab21077557d9c7c51", "Project ⧸ Zombie/Season 2010/s2010.e120201 - Oblivion Mod "Falcor" p.2.mp4": "4433a9932f0c3935cd9d339e281f38a9", "Project ⧸ Zombie/Season 2010/s2010.e120201 - Oblivion Mod "Falcor" p.2.nfo": "0f1c2209cd150ae3750658785d3d0495", "Project ⧸ Zombie/Season 2011/s2011.e020101 - Jesse's Minecraft Server [Trailer - Feb.1]-thumb.jpg": "b232d253df621aa770b780c1301d364d", + "Project ⧸ Zombie/Season 2011/s2011.e020101 - Jesse's Minecraft Server [Trailer - Feb.1].info.json": "f96c952990e3c6123c0ac989b7e66886", "Project ⧸ Zombie/Season 2011/s2011.e020101 - Jesse's Minecraft Server [Trailer - Feb.1].mp4": "36622668231135f717456ef960fc7a68", "Project ⧸ Zombie/Season 2011/s2011.e020101 - Jesse's Minecraft Server [Trailer - Feb.1].nfo": "5168a9d25ecfb6574ffa970d9e3aaabf", "Project ⧸ Zombie/Season 2011/s2011.e022701 - Jesse's Minecraft Server [Trailer - Feb.27]-thumb.jpg": "d17c379ea8b362f5b97c6b213b0342cb", + "Project ⧸ Zombie/Season 2011/s2011.e022701 - Jesse's Minecraft Server [Trailer - Feb.27].info.json": "6ba60421ba79262865743c030912d365", "Project ⧸ Zombie/Season 2011/s2011.e022701 - Jesse's Minecraft Server [Trailer - Feb.27].mp4": "692f5928b18d6d70db7b5314e08cdfd3", "Project ⧸ Zombie/Season 2011/s2011.e022701 - Jesse's Minecraft Server [Trailer - Feb.27].nfo": "5f350a38650dbd13e4cb7cfec5efa06e", "Project ⧸ Zombie/Season 2011/s2011.e032101 - Jesse's Minecraft Server [Trailer - Mar.21]-thumb.jpg": "e7830aa8a64b0cde65ba3f7e5fc56530", + "Project ⧸ Zombie/Season 2011/s2011.e032101 - Jesse's Minecraft Server [Trailer - Mar.21].info.json": "c34ca1f1dbdfcbb6882cf2f9282da908", "Project ⧸ Zombie/Season 2011/s2011.e032101 - Jesse's Minecraft Server [Trailer - Mar.21].mp4": "f5cb35da0e2ecedee9b74db1402be06d", "Project ⧸ Zombie/Season 2011/s2011.e032101 - Jesse's Minecraft Server [Trailer - Mar.21].nfo": "e9f90a9a7c01a2f319f354a08e4b9494", "Project ⧸ Zombie/Season 2011/s2011.e052901 - Project Zombie |Official Trailer| (IP: mc.projectzombie.beastnode.net)-thumb.jpg": "c956192a379b3661595c9920972d4819", + "Project ⧸ Zombie/Season 2011/s2011.e052901 - Project Zombie |Official Trailer| (IP: mc.projectzombie.beastnode.net).info.json": "c9d4a22d42f92a51083f99ea6d01becb", "Project ⧸ Zombie/Season 2011/s2011.e052901 - Project Zombie |Official Trailer| (IP: mc.projectzombie.beastnode.net).mp4": "9766181630b30e94a22e571c70a065f4", "Project ⧸ Zombie/Season 2011/s2011.e052901 - Project Zombie |Official Trailer| (IP: mc.projectzombie.beastnode.net).nfo": "bd025ccd4f7b5c37b46436a4c00bca24", "Project ⧸ Zombie/Season 2011/s2011.e063001 - Project Zombie |Fin|-thumb.jpg": "00ed383591779ffe98291de60f198fe9", + "Project ⧸ Zombie/Season 2011/s2011.e063001 - Project Zombie |Fin|.info.json": "c64503503fefd6841f438a98cfe18880", "Project ⧸ Zombie/Season 2011/s2011.e063001 - Project Zombie |Fin|.mp4": "2d6a06b4b8c4dac8d7c173362d9637a4", "Project ⧸ Zombie/Season 2011/s2011.e063001 - Project Zombie |Fin|.nfo": "258d3c994fbb95c575c6e4fa38097a55", "Project ⧸ Zombie/Season 2011/s2011.e112101 - Skyrim 'Ultra HD w⧸Mods' [PC]-thumb.jpg": "1718599d5189c65f7d8cf6acfa5ea851", + "Project ⧸ Zombie/Season 2011/s2011.e112101 - Skyrim 'Ultra HD w⧸Mods' [PC].info.json": "81f0bafd77a4f556ba6e813dfe65ad48", "Project ⧸ Zombie/Season 2011/s2011.e112101 - Skyrim 'Ultra HD w⧸Mods' [PC].mp4": "60c3221125afbef78990bdcead78a82d", "Project ⧸ Zombie/Season 2011/s2011.e112101 - Skyrim 'Ultra HD w⧸Mods' [PC].nfo": "3c5e407a428161b75474eea13a82e009", "Project ⧸ Zombie/Season 2012/s2012.e012301 - Project Zombie |Map Trailer|-thumb.jpg": "54ebe9df801b278fdd17b21afa8373a6", + "Project ⧸ Zombie/Season 2012/s2012.e012301 - Project Zombie |Map Trailer|.info.json": "b4b04b8a5f4e1da6de2406998e9fee92", "Project ⧸ Zombie/Season 2012/s2012.e012301 - Project Zombie |Map Trailer|.mp4": "2141f0f928d55e94fef7f7d3c7a4aca0", "Project ⧸ Zombie/Season 2012/s2012.e012301 - Project Zombie |Map Trailer|.nfo": "a0d59e102f06b93718ab20e0238b4f95", "Project ⧸ Zombie/Season 2013/s2013.e071901 - Project Zombie Rewind |Trailer|-thumb.jpg": "e29d49433175de8a761af35c5307791f", + "Project ⧸ Zombie/Season 2013/s2013.e071901 - Project Zombie Rewind |Trailer|.info.json": "0899bc4499c5a1576dd00710adf6fd66", "Project ⧸ Zombie/Season 2013/s2013.e071901 - Project Zombie Rewind |Trailer|.mp4": "3fb239f0a646e515bbaaeb6f6d5cdd69", "Project ⧸ Zombie/Season 2013/s2013.e071901 - Project Zombie Rewind |Trailer|.nfo": "45c5ee9108778ef506060cc9143a11e4", "Project ⧸ Zombie/Season 2018/s2018.e102901 - Jesse's Minecraft Server | Teaser Trailer-thumb.jpg": "705ca4e0d99b37e9ecdf6bfe4b90c59b", + "Project ⧸ Zombie/Season 2018/s2018.e102901 - Jesse's Minecraft Server | Teaser Trailer.info.json": "946afd5fd878cecf4e64c0b249fce89a", "Project ⧸ Zombie/Season 2018/s2018.e102901 - Jesse's Minecraft Server | Teaser Trailer.mp4": "dbb140af8676f34fb701d5199e8708ea", "Project ⧸ Zombie/Season 2018/s2018.e102901 - Jesse's Minecraft Server | Teaser Trailer.nfo": "fae653029be0d522d4a9443e5b876e07", "Project ⧸ Zombie/Season 2018/s2018.e110201 - Jesse's Minecraft Server | IP mc.jesse.id-thumb.jpg": "28d852ede73b879b9ebf9a061cfc7d46", "Project ⧸ Zombie/Season 2018/s2018.e110201 - Jesse's Minecraft Server | IP mc.jesse.id.en.srt": "3d2c4e7f65d2ca5e96da38ce7eecfc4e", + "Project ⧸ Zombie/Season 2018/s2018.e110201 - Jesse's Minecraft Server | IP mc.jesse.id.info.json": "2f03763c6e743afbc1a9b1e93f0121d3", "Project ⧸ Zombie/Season 2018/s2018.e110201 - Jesse's Minecraft Server | IP mc.jesse.id.mp4": "083e2e77e3e01218419531c08795c9c0", "Project ⧸ Zombie/Season 2018/s2018.e110201 - Jesse's Minecraft Server | IP mc.jesse.id.nfo": "1b4821d9fb021236e94d5394e21f44aa", "Project ⧸ Zombie/fanart.jpg": "129c6639b47299bc48062f0365e670ee", diff --git a/tests/resources/transaction_log_summaries/youtube/test_channel_full.txt b/tests/resources/transaction_log_summaries/youtube/test_channel_full.txt index 6b1b136b..b01f95c3 100644 --- a/tests/resources/transaction_log_summaries/youtube/test_channel_full.txt +++ b/tests/resources/transaction_log_summaries/youtube/test_channel_full.txt @@ -12,6 +12,7 @@ Files created: title: Project / Zombie {output_directory}/Season 2010 s2010.e081301 - Oblivion Mod "Falcor" p.1-thumb.jpg + s2010.e081301 - Oblivion Mod "Falcor" p.1.info.json s2010.e081301 - Oblivion Mod "Falcor" p.1.mp4 Video Tags: date: 2010-08-13 @@ -50,6 +51,7 @@ Files created: title: 2010-08-13 - Oblivion Mod "Falcor" p.1 year: 2010 s2010.e120201 - Oblivion Mod "Falcor" p.2-thumb.jpg + s2010.e120201 - Oblivion Mod "Falcor" p.2.info.json s2010.e120201 - Oblivion Mod "Falcor" p.2.mp4 Video Tags: date: 2010-12-02 @@ -89,6 +91,7 @@ Files created: year: 2010 {output_directory}/Season 2011 s2011.e020101 - Jesse's Minecraft Server [Trailer - Feb.1]-thumb.jpg + s2011.e020101 - Jesse's Minecraft Server [Trailer - Feb.1].info.json s2011.e020101 - Jesse's Minecraft Server [Trailer - Feb.1].mp4 Video Tags: date: 2011-02-01 @@ -129,6 +132,7 @@ Files created: title: 2011-02-01 - Jesse's Minecraft Server [Trailer - Feb.1] year: 2011 s2011.e022701 - Jesse's Minecraft Server [Trailer - Feb.27]-thumb.jpg + s2011.e022701 - Jesse's Minecraft Server [Trailer - Feb.27].info.json s2011.e022701 - Jesse's Minecraft Server [Trailer - Feb.27].mp4 Video Tags: date: 2011-02-27 @@ -207,6 +211,7 @@ Files created: title: 2011-02-27 - Jesse's Minecraft Server [Trailer - Feb.27] year: 2011 s2011.e032101 - Jesse's Minecraft Server [Trailer - Mar.21]-thumb.jpg + s2011.e032101 - Jesse's Minecraft Server [Trailer - Mar.21].info.json s2011.e032101 - Jesse's Minecraft Server [Trailer - Mar.21].mp4 Video Tags: date: 2011-03-21 @@ -285,6 +290,7 @@ Files created: title: 2011-03-21 - Jesse's Minecraft Server [Trailer - Mar.21] year: 2011 s2011.e052901 - Project Zombie |Official Trailer| (IP: mc.projectzombie.beastnode.net)-thumb.jpg + s2011.e052901 - Project Zombie |Official Trailer| (IP: mc.projectzombie.beastnode.net).info.json s2011.e052901 - Project Zombie |Official Trailer| (IP: mc.projectzombie.beastnode.net).mp4 Video Tags: date: 2011-05-29 @@ -343,6 +349,7 @@ Files created: title: 2011-05-29 - Project Zombie |Official Trailer| (IP: mc.projectzombie.beastnode.net) year: 2011 s2011.e063001 - Project Zombie |Fin|-thumb.jpg + s2011.e063001 - Project Zombie |Fin|.info.json s2011.e063001 - Project Zombie |Fin|.mp4 Video Tags: date: 2011-06-30 @@ -373,6 +380,7 @@ Files created: title: 2011-06-30 - Project Zombie |Fin| year: 2011 s2011.e112101 - Skyrim 'Ultra HD w⧸Mods' [PC]-thumb.jpg + s2011.e112101 - Skyrim 'Ultra HD w⧸Mods' [PC].info.json s2011.e112101 - Skyrim 'Ultra HD w⧸Mods' [PC].mp4 Video Tags: date: 2011-11-21 @@ -418,6 +426,7 @@ Files created: year: 2011 {output_directory}/Season 2012 s2012.e012301 - Project Zombie |Map Trailer|-thumb.jpg + s2012.e012301 - Project Zombie |Map Trailer|.info.json s2012.e012301 - Project Zombie |Map Trailer|.mp4 Video Tags: date: 2012-01-23 @@ -463,6 +472,7 @@ Files created: year: 2012 {output_directory}/Season 2013 s2013.e071901 - Project Zombie Rewind |Trailer|-thumb.jpg + s2013.e071901 - Project Zombie Rewind |Trailer|.info.json s2013.e071901 - Project Zombie Rewind |Trailer|.mp4 Video Tags: date: 2013-07-19 @@ -498,6 +508,7 @@ Files created: year: 2013 {output_directory}/Season 2018 s2018.e102901 - Jesse's Minecraft Server | Teaser Trailer-thumb.jpg + s2018.e102901 - Jesse's Minecraft Server | Teaser Trailer.info.json s2018.e102901 - Jesse's Minecraft Server | Teaser Trailer.mp4 Video Tags: date: 2018-10-29 @@ -543,6 +554,7 @@ Files created: year: 2018 s2018.e110201 - Jesse's Minecraft Server | IP mc.jesse.id-thumb.jpg s2018.e110201 - Jesse's Minecraft Server | IP mc.jesse.id.en.srt + s2018.e110201 - Jesse's Minecraft Server | IP mc.jesse.id.info.json s2018.e110201 - Jesse's Minecraft Server | IP mc.jesse.id.mp4 Video Tags: date: 2018-11-02