A LOTTTT ...

+ fix help text
+ run populate once when -nps flag is used
+ update app version
+ sort tracks by track and disc no. when saving to playlist
+ serialize search results
+ update tags.artist -> tags.artists
+ update tags.albumartist -> tags.albumartists
+ remove artist images from serialized albums
+ add function to serialize artists for cards
+ misc
This commit is contained in:
mungai-njoroge
2023-08-10 10:30:42 +03:00
parent 5cf188dd38
commit 0a703dcc0f
20 changed files with 149 additions and 103 deletions
+17 -1
View File
@@ -2,11 +2,15 @@
Contains methods relating to albums.
"""
from dataclasses import asdict
from typing import Any
from alive_progress import alive_bar
from app.logger import log
from app.models.track import Track
from app.store.albums import AlbumStore
from app.store.tracks import TrackStore
from app.logger import log
def validate_albums():
@@ -25,3 +29,15 @@ def validate_albums():
if album.albumhash not in album_hashes:
AlbumStore.remove_album(album)
bar()
def sort_by_track_no(tracks: list[Track]) -> list[dict[str, Any]]:
tracks = [asdict(t) for t in tracks]
for t in tracks:
track = str(t["track"]).zfill(3)
t["_pos"] = int(f"{t['disc']}{track}")
tracks = sorted(tracks, key=lambda t: t["_pos"])
return tracks
+1 -1
View File
@@ -144,7 +144,7 @@ def get_artists_from_tracks(tracks: list[Track]) -> set[str]:
"""
artists = set()
master_artist_list = [[x.name for x in t.artist] for t in tracks]
master_artist_list = [[x.name for x in t.artists] for t in tracks]
artists = artists.union(*master_artist_list)
return artists
+2 -2
View File
@@ -164,11 +164,11 @@ class Populate:
if not AlbumStore.album_exists(track.albumhash):
AlbumStore.add_album(AlbumStore.create_album(track))
for artist in track.artist:
for artist in track.artists:
if not ArtistStore.artist_exists(artist.artisthash):
ArtistStore.add_artist(Artist(artist.name))
for artist in track.albumartist:
for artist in track.albumartists:
if not ArtistStore.artist_exists(artist.artisthash):
ArtistStore.add_artist(Artist(artist.name))
+16 -2
View File
@@ -7,14 +7,17 @@ from rapidfuzz import process, utils
from unidecode import unidecode
from app import models
from app.db.sqlite.favorite import SQLiteFavoriteMethods as favdb
from app.models.enums import FavType
from app.models.track import Track
from app.serializers.album import serialize_for_card as serialize_album
from app.serializers.album import serialize_for_card_many as serialize_albums
from app.serializers.artist import serialize_for_cards
from app.serializers.track import serialize_track, serialize_tracks
from app.store.albums import AlbumStore
from app.store.artists import ArtistStore
from app.store.tracks import TrackStore
from app.utils.remove_duplicates import remove_duplicates
from app.db.sqlite.favorite import SQLiteFavoriteMethods as favdb
# ratio = fuzz.ratio
# wratio = fuzz.WRatio
@@ -303,6 +306,8 @@ class TopResults:
else:
top_tracks = TopResults.get_track_items(result, query, limit=tracks_limit)
top_tracks = serialize_tracks(top_tracks)
if tracks_only:
return top_tracks
@@ -311,10 +316,19 @@ class TopResults:
else:
albums = TopResults.get_album_items(result, query, limit=albums_limit)
albums = serialize_albums(albums)
if albums_only:
return albums
artists = SearchArtists(query)()[:artists_limit]
artists = serialize_for_cards(artists)
if result["type"] == "track":
result["item"] = serialize_track(result["item"])
if result["type"] == "album":
result["item"] = serialize_album(result["item"])
return {
"top_result": result,
+6 -3
View File
@@ -7,12 +7,10 @@ from tinytag import TinyTag
from app.settings import Defaults, Paths
from app.utils.hashing import create_hash
from app.utils.parsers import (parse_artist_from_filename,
parse_title_from_filename)
from app.utils.parsers import parse_artist_from_filename, parse_title_from_filename
from app.utils.wintools import win_replace_slash
def parse_album_art(filepath: str):
"""
Returns the album art for a given audio file.
@@ -163,6 +161,9 @@ def get_tags(filepath: str):
tags.filetype = filetype
tags.last_mod = last_mod
tags.artists = tags.artist
tags.albumartists = tags.albumartist
tags = tags.__dict__
# delete all tag properties that start with _ (tinytag internals)
@@ -182,6 +183,8 @@ def get_tags(filepath: str):
"track_total",
"year",
"bitdepth",
"artist",
"albumartist",
]
for tag in to_delete:
+2 -2
View File
@@ -176,7 +176,7 @@ def add_track(filepath: str) -> None:
album.set_colors(colors)
AlbumStore.add_album(album)
artists: list[Artist] = track.artist + track.albumartist # type: ignore
artists: list[Artist] = track.artists + track.albumartists # type: ignore
for artist in artists:
if not ArtistStore.artist_exists(artist.artisthash):
@@ -202,7 +202,7 @@ def remove_track(filepath: str) -> None:
if empty_album:
AlbumStore.remove_album_by_hash(track.albumhash)
artists: list[Artist] = track.artist + track.albumartist # type: ignore
artists: list[Artist] = track.artists + track.albumartists # type: ignore
for artist in artists:
empty_artist = not ArtistStore.artist_has_tracks(artist.artisthash)