From 61de0b46d516b69e50693ff2ce4484df3285ed85 Mon Sep 17 00:00:00 2001
From: Luca Bilke <bilke@tralios.de>
Date: Thu, 29 Jun 2023 11:54:55 +0200
Subject: [PATCH] more work on account sessions

---
 .gitignore               |  2 ++
 conf.toml                |  2 +-
 tidal-scraper/account.py | 58 ++++++++++++++++++++++++++++++++++++++++
 tidal-scraper/run.py     |  3 +++
 4 files changed, 64 insertions(+), 1 deletion(-)
 create mode 100644 tidal-scraper/run.py

diff --git a/.gitignore b/.gitignore
index 36e5af9..9c03f71 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
 auth.json
+
+tidal-scraper/__pycache__
\ No newline at end of file
diff --git a/conf.toml b/conf.toml
index e17fb19..f27ef16 100644
--- a/conf.toml
+++ b/conf.toml
@@ -4,7 +4,7 @@ error_log = "error.log"
 # Quality can be one of "master, lossless, high and low"
 # Keep in mind that you can only get the quality included in your tidal sub
 quality = "lossless"
-user_id = 
+user_id = 188721652
 
 dest_dir = "./downloads/"
 # The following templates are passed an artist, album and track object.
diff --git a/tidal-scraper/account.py b/tidal-scraper/account.py
index e69de29..ba549d6 100644
--- a/tidal-scraper/account.py
+++ b/tidal-scraper/account.py
@@ -0,0 +1,58 @@
+import json
+from tidalapi import session, user, playlist, media, album, artist
+from helper import CONF
+
+ALBUM = 1
+ARTIST = 2
+PLAYLIST = 3
+TRACK = 4
+
+
+
+class account:
+    def __init__(self, user_id: int, quality: str):
+        match quality:
+            case "master":
+                q = session.Quality.master
+            case "lossless":
+                q = session.Quality.lossless
+            case "high":
+                q = session.Quality.high
+            case "low":
+                q = session.Quality.low
+            case _:
+                raise Exception("Quality misconfigured in conf.toml")
+        config = session.Config(quality=q)
+        self.user_id = user_id
+        self.session = session.Session(config)
+        self.favorites = user.Favorites(self.session, CONF['user_id'])
+        self._state = {
+            "albums": {},
+            "artists": {},
+            "playlists": {},
+            "tracks": {},
+        }
+
+    @staticmethod
+    def create_obj_state(
+        obj: playlist.Playlist | media.Track | album.Album | artist.Artist,
+        downloaded: bool = False,
+    ) -> dict[str, int | bool]:
+
+        match type(obj):
+            case album.Album:
+                obj_type = ALBUM
+            case artist.Artist:
+                obj_type = ARTIST
+            case playlist.Playlist:
+                obj_type = PLAYLIST
+            case media.Track:
+                obj_type = TRACK
+            case _:
+                raise Exception("Incorrect object type received")
+
+        return {
+            "id": obj.id,
+            "type": obj_type,
+            "downloaded": downloaded,
+        }
diff --git a/tidal-scraper/run.py b/tidal-scraper/run.py
new file mode 100644
index 0000000..0197a16
--- /dev/null
+++ b/tidal-scraper/run.py
@@ -0,0 +1,3 @@
+#!/bin/env python
+import download
+