From de6b8c3b2a989404f2adf14388372de124a1bf19 Mon Sep 17 00:00:00 2001 From: "R. M" <50295204+glomatico@users.noreply.github.com> Date: Thu, 1 Dec 2022 18:42:54 -0300 Subject: [PATCH] music video overwrite prevention --- gamdl.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gamdl.py b/gamdl.py index f551320..ac11396 100644 --- a/gamdl.py +++ b/gamdl.py @@ -327,6 +327,15 @@ class Gamdl: return dirty_string.strip() + def get_final_location_overwrite_prevented_music_video(self, final_location): + count = 1 + while True: + if final_location.with_name(f'{final_location.stem} {count}.m4v').exists(): + count += 1 + else: + return final_location.with_name(f'{final_location.stem} {count}.m4v') + + def get_final_location(self, file_extension, tags): final_location = Path(self.final_path) if 'plID' in tags.keys(): @@ -342,6 +351,8 @@ class Gamdl: filename = self.get_sanizated_string(tags["©nam"][0]) final_location /= f'{self.get_sanizated_string(tags["©ART"][0], True)}/Unknown Album/' final_location /= f'{filename}{file_extension}' + if final_location.exists() and file_extension == '.m4v' and MP4(final_location).tags['cnID'][0] != tags['cnID'][0]: + final_location = self.get_final_location_overwrite_prevented_music_video(final_location) return final_location