add methods to get recently played items

This commit is contained in:
mungai-njoroge
2023-12-03 20:35:13 +03:00
parent 5a420214f2
commit ddfa7f1b03
10 changed files with 277 additions and 101 deletions
+28 -3
View File
@@ -1,11 +1,36 @@
from attr import dataclass
from dataclasses import dataclass
from typing import Literal
@dataclass
@dataclass
class Track:
"""
Track play logger model
"""
id: int
trackhash: str
duration: int
timestamp: int
timestamp: int
source: str
userid: int
type = "track"
type_src = None
def __post_init__(self):
prefix_map = {
"al:": "album",
"ar:": "artist",
"pl:": "playlist",
"fo:": "folder",
}
for prefix, srctype in prefix_map.items():
if self.source.startswith(prefix):
try:
self.type_src = self.source.split(":", 1)[1]
except IndexError:
pass
self.type = srctype
break