From 1371b2f88fec29e2863d2bf8c2054f687bcecbf7 Mon Sep 17 00:00:00 2001
From: Luca Bilke <bilke@tralios.de>
Date: Mon, 26 Jun 2023 17:01:57 +0200
Subject: [PATCH] transferring new script

---
 tidal_scrape.py | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100755 tidal_scrape.py

diff --git a/tidal_scrape.py b/tidal_scrape.py
new file mode 100755
index 0000000..3e4bb74
--- /dev/null
+++ b/tidal_scrape.py
@@ -0,0 +1,45 @@
+#!/bin/python3
+import tidalapi
+import json
+import sys
+from datetime import datetime
+
+config = tidalapi.Config(quality=tidalapi.Quality.lossless)
+session = tidalapi.Session(config)
+
+try:
+    with open("auth.json", "rb") as f:
+        a = json.load(f)
+        a.expiry_time = datetime.strptime(a.expiry_time, "%y-%m-%d %H:%M:%S")
+        session.load_oauth_session(
+            a.token_type, a.access_token, a.refresh_token, a.expiry_time
+        )
+except (OSError, IndexError):
+    session.login_oauth_simple()
+
+if session.check_login():
+    with open("auth.json", "w") as f:
+        json.dump(
+            {
+                "token_type": session.token_type,
+                "access_token": session.access_token,
+                "refresh_token": session.refresh_token,
+                "expiry_time": session.expiry_time,
+            },
+            f,
+        )
+else:
+    sys.exit("Failed to log in")
+
+user = session.get_user()
+# albums = user.Favorites.albums()
+# tracks = user.Favorites.tracks()
+# artists = user.Favorites.artists()
+#
+# for album in albums:
+#     if album.artist not in artists:
+#         user.Favorites.add_artist(album.artist.id)
+#
+# for track in tracks:
+#     if track.album not in albums:
+#         user.Favorites.add_album(track.album.id)