combine userdata and swing db into one

+ port populate to new db interface
+ add genrehashes and hash info to tracks
+ properly structure new db table files
+ move helpers to dedicated utils file
+ move settings from db to config file
+ move artists, albums, auth and favorites endpoint to new db interface
+ use folder store to index filepaths
+ paginate favorite pages
+ 56 moretiny changes 😅
This commit is contained in:
cwilvx
2024-06-30 15:06:33 +03:00
parent 1a66194c6c
commit 4a9f804e70
53 changed files with 1719 additions and 1353 deletions
+7 -4
View File
@@ -2,9 +2,6 @@ import dataclasses
import datetime
from dataclasses import dataclass
from app.config import UserConfig
from app.settings import SessionVarKeys, get_flag
from ..utils.hashing import create_hash
from ..utils.parsers import get_base_title_and_versions, parse_feat_from_title
from .artist import Artist
@@ -27,15 +24,21 @@ class Album:
date: int
duration: int
genres: list[dict[str, str]]
genrehashes: list[str]
og_title: str
title: str
trackcount: int
is_favorite: bool
extra: dict
type: str = "album"
image: str = ""
versions: list[str] = dataclasses.field(default_factory=list)
def __post_init__(self):
self.date = datetime.datetime.fromtimestamp(self.date).year
# self.date = datetime.datetime.fromtimestamp(self.date).year
self.image = self.albumhash + ".webp"
self.populate_versions()
# albumhash: str
# title: str
+7
View File
@@ -44,6 +44,13 @@ class Artist:
date: int
duration: int
genres: list[dict[str, str]]
genrehashes: list[str]
name: str
trackcount: int
is_favorite: bool
extra: dict
image: str = ""
def __post_init__(self):
self.image = self.artisthash + ".webp"
+11
View File
@@ -0,0 +1,11 @@
from dataclasses import dataclass
from typing import Any, Literal
@dataclass
class Favorite:
hash: str
type: Literal["album", "track", "artist"]
timestamp: int
userid: int
extra: dict[str, Any]
+17 -2
View File
@@ -1,13 +1,28 @@
from dataclasses import dataclass
from typing import Any
@dataclass
class SimilarArtistEntry:
artisthash: str
name: str
weight: float
scrobbles: int
listeners: int
@dataclass
class SimilarArtist:
artisthash: str
similar_artist_hashes: str
similar_artists: list[SimilarArtistEntry]
def get_artist_hash_set(self) -> set[str]:
"""
Returns a set of similar artists.
"""
return set(self.similar_artist_hashes.split("~"))
if not self.similar_artists:
return set()
# INFO:
return set(a['artisthash'] for a in self.similar_artists)
+1 -1
View File
@@ -4,7 +4,7 @@ from dataclasses import dataclass
@dataclass
class Plugin:
name: str
description: str
active: bool
settings: dict
extra: dict
+12 -19
View File
@@ -1,20 +1,4 @@
from dataclasses import dataclass, field
import os
from pathlib import Path
from flask_jwt_extended import current_user
from app.settings import SessionVarKeys, get_flag
from app.utils.hashing import create_hash
from app.utils.parsers import (
clean_title,
get_base_title_and_versions,
parse_feat_from_title,
remove_prod,
split_artists,
)
from .artist import ArtistMinimal
from dataclasses import dataclass
@dataclass(slots=True)
@@ -28,7 +12,7 @@ class Track:
albumartists: list[dict[str, str]]
albumhash: str
artisthashes: list[str]
artists: str
artists: list[dict[str, str]]
bitrate: int
copyright: str
date: int
@@ -36,7 +20,8 @@ class Track:
duration: int
filepath: str
folder: str
genre: list[dict[str, str]]
genres: list[dict[str, str]]
genrehashes: list[str]
last_mod: int
og_album: str
og_title: str
@@ -48,7 +33,15 @@ class Track:
is_favorite: bool = False
_pos: int = 0
_ati: str = ""
image: str = ""
def __post_init__(self):
self.image = self.albumhash + ".webp"
self.extra = {
"disc_total": self.extra.get("disc_total", 0),
"track_total": self.extra.get("track_total", 0),
"samplerate": self.extra.get("samplerate", -1),
}
# album: str
# albumartists: str | list[ArtistMinimal]
+5 -9
View File
@@ -5,19 +5,15 @@ import json
@dataclass(slots=True)
class User:
id: int
username: str
firstname: str
lastname: str
password: str
email: str
image: str
password: str
username: str
roles: list[str]
extra: dict[str, str] = field(default_factory=dict)
# NOTE: roles: ['admin', 'user', 'curator']
roles: list[str] = field(default_factory=lambda: ["user"])
def __post_init__(self):
self.roles = json.loads(self.roles)
def todict(self):
this_dict = asdict(self)
del this_dict["password"]
@@ -28,5 +24,5 @@ class User:
return {
"id": self.id,
"username": self.username,
"firstname": self.firstname,
"firstname": self.extra["firstname"] if self.extra else "",
}