From 0d6de77db17475badc12603d771d6c0fa662cd64 Mon Sep 17 00:00:00 2001
From: Luca Bilke <luca@snaile.de>
Date: Tue, 27 Jun 2023 16:56:19 +0200
Subject: [PATCH] fix duplicate detection

---
 tidal_scrape.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tidal_scrape.py b/tidal_scrape.py
index 7565349..3913372 100755
--- a/tidal_scrape.py
+++ b/tidal_scrape.py
@@ -85,13 +85,7 @@ def download_track(
         dl_path = f"{DL_PATH}/{track.track_num}{track_name}.part"  # type: ignore[reportOptionalMemberAccess]
         dest_path = f"{DEST_PATH}/{artist_name}/{album_name}/{track.track_num} {track_name}"  # type: ignore[reportOptionalMemberAccess]
 
-        if os.path.exists(dest_path) and SKIP_DOWNLOADED:
-            print(dest_path + " exists!")
-            print("Skipping downloaded song")
-            return False, "Skipping downloaded song"
-
         stream = track.stream()
-
         stream.manifest = json.loads(base64.b64decode(stream.manifest))
         url = stream.manifest["urls"][0]
         if '.flac' in url:
@@ -101,6 +95,12 @@ def download_track(
                 dest_path += '.mp4'
             else:
                 dest_path += '.m4a'
+
+        if os.path.exists(dest_path) and SKIP_DOWNLOADED:
+            print(dest_path + " exists!")
+            print("Skipping downloaded song")
+            return False, "Skipping downloaded song"
+
         try:
             key = stream.manifest["keyId"]
         except KeyError: