swingmusic/app/models/playlist.py
mungai-njoroge 93de3d2f0c rewrite migrations
+ delete older migrations ... oops
+ change migratrions from "migrations" to "dbmigrations"
+ restructure migrations, order them based on release version
+ add a utils/decorators.py file with a coroutine decorator
2023-07-29 06:46:28 +03:00

54 lines
1.2 KiB
Python

import dataclasses
import json
from dataclasses import dataclass
from pathlib import Path
from app import settings
@dataclass(slots=True)
class Playlist:
"""Creates playlist objects"""
id: int
image: str
last_updated: str
name: str
settings: str | dict
trackhashes: str | list[str]
thumb: str = ""
count: int = 0
duration: int = 0
has_image: bool = False
images: list[str] = dataclasses.field(default_factory=list)
def __post_init__(self):
self.trackhashes = json.loads(str(self.trackhashes))
# commentted until we need it 👆
self.count = len(self.trackhashes)
if isinstance(self.settings, str):
self.settings = json.loads(self.settings)
self.has_image = (
Path(settings.Paths.get_playlist_img_path()) / str(self.image)
).exists()
if self.image is not None:
self.thumb = "thumb_" + self.image
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 = []