refactored using the song and src object instead of dict
This commit is contained in:
parent
2293269151
commit
7b241d8655
@ -1,5 +1,31 @@
|
|||||||
from typing import List
|
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:
|
class Artist:
|
||||||
def __init__(self, artist_data) -> None:
|
def __init__(self, artist_data) -> None:
|
||||||
@ -20,20 +46,27 @@ class Song:
|
|||||||
def __init__(self, json_response) -> None:
|
def __init__(self, json_response) -> None:
|
||||||
self.json_data = json_response
|
self.json_data = json_response
|
||||||
|
|
||||||
|
# initialize the data
|
||||||
self.title = self.json_data['title']
|
self.title = self.json_data['title']
|
||||||
self.artists = [Artist(a) for a in self.json_data['artists']]
|
self.artists = [Artist(a) for a in self.json_data['artists']]
|
||||||
|
self.isrc = self.json_data['isrc']
|
||||||
|
|
||||||
|
# initialize the sources
|
||||||
self.sources: List[Source] = []
|
self.sources: List[Source] = []
|
||||||
for src in self.json_data['source']:
|
for src in self.json_data['source']:
|
||||||
if src['src'] is None:
|
if src['src'] is None:
|
||||||
continue
|
continue
|
||||||
self.sources.append(Source(src))
|
self.sources.append(Source(src))
|
||||||
"""
|
|
||||||
artist
|
# initialize the target
|
||||||
source
|
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]
|
return [a.name for a in self.aritsts]
|
||||||
|
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
|
Loading…
Reference in New Issue
Block a user