continued
This commit is contained in:
parent
58626a7d99
commit
3432ab1321
@ -4,6 +4,7 @@ import logging
|
|||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from . import song
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
def __init__(self, path_to_db: str, db_structure: str, db_structure_fallback: str, logger: logging.Logger, reset_anyways: bool = False):
|
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):
|
def get_custom_track(self, custom_where: list):
|
||||||
query = Database.get_custom_track_query(custom_where=custom_where)
|
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):
|
def get_track_metadata(self, musicbrainz_releasetrackid: str):
|
||||||
# this would be vulnerable if musicbrainz_releasetrackid would be user input
|
# this would be vulnerable if musicbrainz_releasetrackid would be user input
|
||||||
|
31
src/music_kraken/database/song.py
Normal file
31
src/music_kraken/database/song.py
Normal 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
|
Loading…
Reference in New Issue
Block a user