mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-10 13:07:35 +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:
|
if acount == 0 and tcount < 10:
|
||||||
limit = tcount
|
limit = tcount
|
||||||
|
|
||||||
artist.trackcount = tcount
|
artist.set_trackcount(tcount)
|
||||||
artist.albumcount = acount
|
artist.set_albumcount(acount)
|
||||||
|
artist.set_duration(sum(t.duration for t in tracks))
|
||||||
artist.duration = sum(t.duration for t in tracks)
|
|
||||||
|
|
||||||
artist.is_favorite = favdb.check_is_favorite(artisthash, FavType.artist)
|
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 = get_first_4_images(playlist.trackhashes)
|
||||||
playlist.images = [img['image'] for img in playlist.images]
|
playlist.images = [img['image'] for img in playlist.images]
|
||||||
|
|
||||||
playlist.trackhashes = []
|
playlist.clear_lists()
|
||||||
playlist.artisthashes = []
|
|
||||||
|
|
||||||
playlists.sort(
|
playlists.sort(
|
||||||
key=lambda p: datetime.strptime(p.last_updated, "%Y-%m-%d %H:%M:%S"),
|
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)
|
duration = sum(t.duration for t in tracks)
|
||||||
playlist.last_updated = date_string_to_time_passed(playlist.last_updated)
|
playlist.last_updated = date_string_to_time_passed(playlist.last_updated)
|
||||||
|
|
||||||
playlist.duration = duration
|
playlist.set_duration(duration)
|
||||||
|
|
||||||
if not playlist.has_image:
|
if not playlist.has_image:
|
||||||
playlist.images = get_first_4_images(playlist.trackhashes)
|
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)
|
# 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.images[2], playlist.images[0] = playlist.images[0], playlist.images[2]
|
||||||
|
|
||||||
playlist.trackhashes = []
|
playlist.clear_lists()
|
||||||
playlist.artisthashes = []
|
|
||||||
|
|
||||||
return {"info": playlist, "tracks": tracks}
|
return {"info": playlist, "tracks": tracks}
|
||||||
|
|
||||||
|
@ -64,16 +64,11 @@ def extract_thumb(filepath: str, webp_path: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def extract_date(date_str: str | None) -> int:
|
def extract_date(date_str: str | None, filepath: str) -> int:
|
||||||
current_year = datetime.date.today().today().year
|
|
||||||
|
|
||||||
if date_str is None:
|
|
||||||
return current_year
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return int(date_str.split("-")[0])
|
return int(date_str.split("-")[0])
|
||||||
except: # pylint: disable=bare-except
|
except: # pylint: disable=bare-except
|
||||||
return current_year
|
return datetime.date.today().today().year
|
||||||
|
|
||||||
|
|
||||||
def get_tags(filepath: str):
|
def get_tags(filepath: str):
|
||||||
@ -145,7 +140,7 @@ def get_tags(filepath: str):
|
|||||||
tags.image = f"{tags.albumhash}.webp"
|
tags.image = f"{tags.albumhash}.webp"
|
||||||
tags.folder = win_replace_slash(os.path.dirname(filepath))
|
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.filepath = win_replace_slash(filepath)
|
||||||
tags.filetype = filetype
|
tags.filetype = filetype
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import dataclasses
|
|
||||||
import json
|
import json
|
||||||
|
import dataclasses
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from app.utils.hashing import create_hash
|
from app.utils.hashing import create_hash
|
||||||
@ -33,11 +33,18 @@ class Artist(ArtistMinimal):
|
|||||||
colors: list[str] = dataclasses.field(default_factory=list)
|
colors: list[str] = dataclasses.field(default_factory=list)
|
||||||
is_favorite: bool = False
|
is_favorite: bool = False
|
||||||
|
|
||||||
def __post_init__(self):
|
def __init__(self, name: str):
|
||||||
super(Artist, self).__init__(self.name)
|
super(Artist, self).__init__(name)
|
||||||
self.colors = json.loads(str(self.colors))
|
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]):
|
def set_colors(self, colors: list[str]):
|
||||||
self.colors = colors
|
self.colors = colors
|
||||||
|
|
||||||
# TODO: Use inheritance to create the classes in this file.
|
|
||||||
|
@ -40,3 +40,14 @@ class Playlist:
|
|||||||
else:
|
else:
|
||||||
self.image = "None"
|
self.image = "None"
|
||||||
self.thumb = "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:
|
for artist in cls.artists:
|
||||||
if artist.artisthash == artisthash:
|
if artist.artisthash == artisthash:
|
||||||
artist.colors = color
|
artist.set_colors(color)
|
||||||
break
|
break
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
Loading…
x
Reference in New Issue
Block a user