first recommendation draft

This commit is contained in:
cwilvx
2024-10-25 23:26:08 +03:00
parent a26373669d
commit c4a73f0d63
15 changed files with 393 additions and 6 deletions
+37
View File
@@ -0,0 +1,37 @@
from dataclasses import asdict, dataclass, field
import time
from app.lib.playlistlib import get_first_4_images
from app.serializers.track import serialize_tracks
from app.store.tracks import TrackStore
from app.utils.dates import seconds_to_time_string
@dataclass
class Mix:
id: str
title: str
description: str
tracks: list[str]
timestamp: int = field(default_factory=lambda: int(time.time()))
extra: dict = field(default_factory=dict)
saved: bool = False
def to_full_dict(self):
tracks = TrackStore.get_tracks_by_trackhashes(self.tracks)
serialized_tracks = serialize_tracks(tracks)
_dict = asdict(self)
_dict["tracks"] = serialized_tracks
_dict["images"] = get_first_4_images(tracks)
_dict["duration"] = seconds_to_time_string(sum(t.duration for t in tracks))
_dict["trackcount"] = len(tracks)
return _dict
def to_dict(self):
item = self.to_full_dict()
del item["tracks"]
return item
+2
View File
@@ -45,6 +45,7 @@ class Track:
og_title: str = ""
artisthashes: list[str] = field(default_factory=list)
genrehashes: list[str] = field(default_factory=list)
weakhash: str = ""
_pos: int = 0
_ati: str = ""
@@ -76,6 +77,7 @@ class Track:
self.og_title = self.title
self.og_album = self.album
self.folder = self.folder + "/"
self.weakhash = create_hash(self.title, self.artists)
self.image = self.albumhash + ".webp"
self.extra = {