From 3432ab13210ff31886593a00551d9d71e330081e Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Mon, 21 Nov 2022 15:40:41 +0100 Subject: [PATCH] continued --- src/music_kraken/database/database.py | 3 ++- src/music_kraken/database/song.py | 31 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/music_kraken/database/song.py diff --git a/src/music_kraken/database/database.py b/src/music_kraken/database/database.py index e262c08..d8d7e38 100644 --- a/src/music_kraken/database/database.py +++ b/src/music_kraken/database/database.py @@ -4,6 +4,7 @@ import logging import json import requests +from . import song class Database: def __init__(self, path_to_db: str, db_structure: str, db_structure_fallback: str, logger: logging.Logger, reset_anyways: bool = False): @@ -194,7 +195,7 @@ GROUP BY track.id; def get_custom_track(self, custom_where: list): query = Database.get_custom_track_query(custom_where=custom_where) - return [json.loads(i[0]) for i in self.cursor.execute(query)] + return [song.Song(json.loads(i[0])) for i in self.cursor.execute(query)] def get_track_metadata(self, musicbrainz_releasetrackid: str): # this would be vulnerable if musicbrainz_releasetrackid would be user input diff --git a/src/music_kraken/database/song.py b/src/music_kraken/database/song.py new file mode 100644 index 0000000..dd31023 --- /dev/null +++ b/src/music_kraken/database/song.py @@ -0,0 +1,31 @@ +class Artist: + def __init__(self, artist_data) -> None: + self.artist_data + + self.id = self.artist_data['id'] + self.name = self.artist_data['name'] + + +class Song: + def __init__(self, json_response) -> None: + self.json_data = json_response + + self.artists = [Artist(a) for a in self.json_data['artists']] + """ + artist + source + """ + + def get_artist_names(self): + return [a.name for a in self.aritsts] + + def __getitem__(self, item): + print(item) + print(self.json_data) + if item not in self.json_data: + return None + return self.json_data[item] + + def __setitem__(self, item, value): + print(item, value) + self.json_data[item] = value