From ba693e214b4f45d791331fe7e37ae77266548928 Mon Sep 17 00:00:00 2001
From: rlaphoenix <rlaphoenix@pm.me>
Date: Fri, 1 Mar 2024 03:03:12 +0000
Subject: [PATCH] refactor(Track): Remove swap() method and it's uses

Re-using the same track path and file name with a different output file, is not ideal as the files contents are different and the target file name specifies what processing it had done on it, which is useful during debugging when browsing the temp directory.
---
 devine/core/tracks/subtitle.py |  2 +-
 devine/core/tracks/track.py    | 32 +-------------------------------
 devine/core/tracks/video.py    |  5 ++---
 3 files changed, 4 insertions(+), 35 deletions(-)

diff --git a/devine/core/tracks/subtitle.py b/devine/core/tracks/subtitle.py
index 6ab4d02..036dc10 100644
--- a/devine/core/tracks/subtitle.py
+++ b/devine/core/tracks/subtitle.py
@@ -214,7 +214,7 @@ class Subtitle(Track):
 
             output_path.write_text(subtitle_text, encoding="utf8")
 
-        self.swap(output_path)
+        self.path = output_path
         self.codec = codec
 
         if callable(self.OnConverted):
diff --git a/devine/core/tracks/track.py b/devine/core/tracks/track.py
index 2025d7d..33d8188 100644
--- a/devine/core/tracks/track.py
+++ b/devine/core/tracks/track.py
@@ -299,8 +299,7 @@ class Track:
             else:
                 raise
 
-        self.swap(output_path)
-        self.move(original_path)
+        self.path = output_path
 
     def move(self, target: Union[Path, str]) -> bool:
         """
@@ -330,34 +329,5 @@ class Track:
 
         return success
 
-    def swap(self, target: Union[Path, str]) -> bool:
-        """
-        Delete the Track's file and swap to the Target file.
-
-        Raises:
-            TypeError: If the target argument is not the expected type.
-            OSError: If the file somehow failed to move.
-
-        Returns True if the swap succeeded, or False if the track is not yet downloaded,
-        or the target path does not exist.
-        """
-        if not isinstance(target, (str, Path)):
-            raise TypeError(f"Expected {target} to be a {Path} or {str}, not {type(target)}")
-
-        target = Path(target)
-
-        if not target.exists() or not self.path:
-            return False
-
-        self.path.unlink()
-
-        moved_to = Path(shutil.move(target, self.path))
-        success = moved_to.resolve() == self.path.resolve()
-
-        if not success:
-            return False
-
-        return self.move(target)
-
 
 __all__ = ("Track",)
diff --git a/devine/core/tracks/video.py b/devine/core/tracks/video.py
index c7cacc5..b3728c8 100644
--- a/devine/core/tracks/video.py
+++ b/devine/core/tracks/video.py
@@ -200,8 +200,7 @@ class Video(Track):
             str(output_path)
         ], check=True)
 
-        self.swap(output_path)
-        self.move(original_path)
+        self.path = output_path
 
     def ccextractor(
         self, track_id: Any, out_path: Union[Path, str], language: Language, original: bool = False
@@ -335,7 +334,7 @@ class Video(Track):
 
         log.info(" + Removed")
 
-        self.swap(cleaned_path)
+        self.path = cleaned_path
 
         return True