refactored using the song and src object instead of dict

This commit is contained in:
Lars Noack 2022-11-22 12:41:05 +01:00
parent 2293269151
commit 7b241d8655

View File

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