diff --git a/src/music_kraken/objects/target.py b/src/music_kraken/objects/target.py index e2e4546..09b25d4 100644 --- a/src/music_kraken/objects/target.py +++ b/src/music_kraken/objects/target.py @@ -51,3 +51,12 @@ class Target(DatabaseObject): def create_path(self): self._path.mkdir(parents=True, exist_ok=True) + + def copy_content(self, copy_to: "Target"): + if not self.exists: + return + + with open(self.file_path, "rb") as read_from: + copy_to.create_path() + with open(self.file_path, "wb") as write_to: + write_to.write(read_from.read()) diff --git a/src/music_kraken/pages/abstract.py b/src/music_kraken/pages/abstract.py index e0819b4..a79f9e9 100644 --- a/src/music_kraken/pages/abstract.py +++ b/src/music_kraken/pages/abstract.py @@ -312,6 +312,19 @@ class Page: if song.target_collection.empty: return + target: Target + if any(target.exists for target in song.target_collection): + existing_target: Target + for existing_target in song.target_collection: + if existing_target.exists: + break + + for target in song.target_collection: + if target is existing_target: + continue + + existing_target.copy_content(target) + sources = song.source_collection.get_sources_from_page(cls.SOURCE_TYPE) if len(sources) == 0: return