continued

This commit is contained in:
Lars Noack 2022-11-21 15:40:41 +01:00
parent 58626a7d99
commit 3432ab1321
2 changed files with 33 additions and 1 deletions

View File

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

View File

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