2
0
Fork 0

more work on account sessions

This commit is contained in:
Luca Bilke 2023-06-29 11:54:55 +02:00
parent fc5b58b274
commit 61de0b46d5
No known key found for this signature in database
GPG Key ID: 7B77C51E8C779E75
4 changed files with 64 additions and 1 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
auth.json auth.json
tidal-scraper/__pycache__

View File

@ -4,7 +4,7 @@ error_log = "error.log"
# Quality can be one of "master, lossless, high and low" # 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 # Keep in mind that you can only get the quality included in your tidal sub
quality = "lossless" quality = "lossless"
user_id = user_id = 188721652
dest_dir = "./downloads/" dest_dir = "./downloads/"
# The following templates are passed an artist, album and track object. # The following templates are passed an artist, album and track object.

View File

@ -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,
}

3
tidal-scraper/run.py Normal file
View File

@ -0,0 +1,3 @@
#!/bin/env python
import download