From 7b241d86551e848e28d335df334d24a2bd633254 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Tue, 22 Nov 2022 12:41:05 +0100 Subject: [PATCH] refactored using the song and src object instead of dict --- src/music_kraken/database/song.py | 43 +++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/src/music_kraken/database/song.py b/src/music_kraken/database/song.py index a49e70d..ab77df9 100644 --- a/src/music_kraken/database/song.py +++ b/src/music_kraken/database/song.py @@ -1,5 +1,31 @@ from typing import List +from ..utils.shared import * +import os + +class Target: + def __init__(self) -> None: + self._file = None + self._path = None + + def set_file(self, _file: str): + self._file = _file + + def get_file(self) -> str | None: + if self._file is None: + return None + return os.path.join(MUSIC_DIR, self._file) + + def set_path(self, _path: str): + self._path = _path + + def get_path(self) -> str | None: + if self._path is None: + return None + return os.path.join(MUSIC_DIR, self._path) + + file = property(fget=get_file, fset=set_file) + path = property(fget=get_path, fset=set_path) class Artist: def __init__(self, artist_data) -> None: @@ -20,20 +46,27 @@ class Song: def __init__(self, json_response) -> None: self.json_data = json_response + # initialize the data self.title = self.json_data['title'] self.artists = [Artist(a) for a in self.json_data['artists']] + self.isrc = self.json_data['isrc'] + # initialize the sources self.sources: List[Source] = [] for src in self.json_data['source']: if src['src'] is None: continue self.sources.append(Source(src)) - """ - artist - source - """ + + # initialize the target + self.target = Target() + self.target.file = self.json_data['file'] + self.target.path = self.json_data['path'] - def get_artist_names(self): + def has_isrc(self) -> bool: + return self.isrc is not None + + def get_artist_names(self) -> List[str]: return [a.name for a in self.aritsts] def __getitem__(self, item):