music-kraken-core/src/music_kraken/database/song.py

44 lines
1.1 KiB
Python
Raw Normal View History

2022-11-21 14:40:41 +00:00
class Artist:
def __init__(self, artist_data) -> None:
self.artist_data
self.id = self.artist_data['id']
self.name = self.artist_data['name']
2022-11-21 14:44:59 +00:00
class Source:
def __init__(self, src_data) -> None:
self.src_data = src_data
self.src = self.src_data['src']
self.url = self.src_data['url']
2022-11-21 14:40:41 +00:00
class Song:
def __init__(self, json_response) -> None:
self.json_data = json_response
self.artists = [Artist(a) for a in self.json_data['artists']]
2022-11-21 14:44:59 +00:00
self.sources = []
for src in self.json_data['source']:
if src['src'] is None:
continue
self.sources.append(Source(src))
2022-11-21 14:40:41 +00:00
"""
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