mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-06 19:25:34 +00:00
use setters to manipulate artist and playlist objects
This commit is contained in:
parent
5487dad27b
commit
fe6c12d856
@ -199,10 +199,9 @@ def get_artist(artisthash: str):
|
||||
if acount == 0 and tcount < 10:
|
||||
limit = tcount
|
||||
|
||||
artist.trackcount = tcount
|
||||
artist.albumcount = acount
|
||||
|
||||
artist.duration = sum(t.duration for t in tracks)
|
||||
artist.set_trackcount(tcount)
|
||||
artist.set_albumcount(acount)
|
||||
artist.set_duration(sum(t.duration for t in tracks))
|
||||
|
||||
artist.is_favorite = favdb.check_is_favorite(artisthash, FavType.artist)
|
||||
|
||||
|
@ -80,8 +80,7 @@ def send_all_playlists():
|
||||
playlist.images = get_first_4_images(playlist.trackhashes)
|
||||
playlist.images = [img['image'] for img in playlist.images]
|
||||
|
||||
playlist.trackhashes = []
|
||||
playlist.artisthashes = []
|
||||
playlist.clear_lists()
|
||||
|
||||
playlists.sort(
|
||||
key=lambda p: datetime.strptime(p.last_updated, "%Y-%m-%d %H:%M:%S"),
|
||||
@ -163,7 +162,7 @@ def get_playlist(playlistid: str):
|
||||
duration = sum(t.duration for t in tracks)
|
||||
playlist.last_updated = date_string_to_time_passed(playlist.last_updated)
|
||||
|
||||
playlist.duration = duration
|
||||
playlist.set_duration(duration)
|
||||
|
||||
if not playlist.has_image:
|
||||
playlist.images = get_first_4_images(playlist.trackhashes)
|
||||
@ -172,8 +171,7 @@ def get_playlist(playlistid: str):
|
||||
# swap 3rd image with first (3rd image is the visible image in UI)
|
||||
playlist.images[2], playlist.images[0] = playlist.images[0], playlist.images[2]
|
||||
|
||||
playlist.trackhashes = []
|
||||
playlist.artisthashes = []
|
||||
playlist.clear_lists()
|
||||
|
||||
return {"info": playlist, "tracks": tracks}
|
||||
|
||||
|
@ -64,16 +64,11 @@ def extract_thumb(filepath: str, webp_path: str) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def extract_date(date_str: str | None) -> int:
|
||||
current_year = datetime.date.today().today().year
|
||||
|
||||
if date_str is None:
|
||||
return current_year
|
||||
|
||||
def extract_date(date_str: str | None, filepath: str) -> int:
|
||||
try:
|
||||
return int(date_str.split("-")[0])
|
||||
except: # pylint: disable=bare-except
|
||||
return current_year
|
||||
return datetime.date.today().today().year
|
||||
|
||||
|
||||
def get_tags(filepath: str):
|
||||
@ -145,7 +140,7 @@ def get_tags(filepath: str):
|
||||
tags.image = f"{tags.albumhash}.webp"
|
||||
tags.folder = win_replace_slash(os.path.dirname(filepath))
|
||||
|
||||
tags.date = extract_date(tags.year)
|
||||
tags.date = extract_date(tags.year, filepath)
|
||||
tags.filepath = win_replace_slash(filepath)
|
||||
tags.filetype = filetype
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import dataclasses
|
||||
import json
|
||||
import dataclasses
|
||||
from dataclasses import dataclass
|
||||
|
||||
from app.utils.hashing import create_hash
|
||||
@ -33,11 +33,18 @@ class Artist(ArtistMinimal):
|
||||
colors: list[str] = dataclasses.field(default_factory=list)
|
||||
is_favorite: bool = False
|
||||
|
||||
def __post_init__(self):
|
||||
super(Artist, self).__init__(self.name)
|
||||
def __init__(self, name: str):
|
||||
super(Artist, self).__init__(name)
|
||||
self.colors = json.loads(str(self.colors))
|
||||
|
||||
def set_trackcount(self, count: int):
|
||||
self.trackcount = count
|
||||
|
||||
def set_albumcount(self, count: int):
|
||||
self.albumcount = count
|
||||
|
||||
def set_duration(self, duration: int):
|
||||
self.duration = duration
|
||||
|
||||
def set_colors(self, colors: list[str]):
|
||||
self.colors = colors
|
||||
|
||||
# TODO: Use inheritance to create the classes in this file.
|
||||
|
@ -40,3 +40,14 @@ class Playlist:
|
||||
else:
|
||||
self.image = "None"
|
||||
self.thumb = "None"
|
||||
|
||||
def set_duration(self, duration: int):
|
||||
self.duration = duration
|
||||
|
||||
def clear_lists(self):
|
||||
"""
|
||||
Removes data from lists to make it lighter for sending
|
||||
over the API.
|
||||
"""
|
||||
self.trackhashes = []
|
||||
self.artisthashes = []
|
||||
|
@ -36,7 +36,7 @@ class ArtistStore:
|
||||
|
||||
for artist in cls.artists:
|
||||
if artist.artisthash == artisthash:
|
||||
artist.colors = color
|
||||
artist.set_colors(color)
|
||||
break
|
||||
|
||||
@classmethod
|
||||
|
Loading…
x
Reference in New Issue
Block a user