sort albums in get_artist_albums route

This commit is contained in:
geoffrey45 2023-05-08 16:19:38 +03:00
parent 45bf7570a3
commit b9f0204225
3 changed files with 11 additions and 11 deletions

View File

@ -108,14 +108,14 @@ def get_artist_albums():
albumartists: str = data["albumartists"] albumartists: str = data["albumartists"]
limit: int = data.get("limit") limit: int = data.get("limit")
exclude: str = data.get("exclude") base_title: str = data.get("base_title")
albumartists: list[str] = albumartists.split(",") albumartists: list[str] = albumartists.split(",")
albums = [ albums = [
{ {
"artisthash": a, "artisthash": a,
"albums": AlbumStore.get_albums_by_albumartist(a, limit, exclude=exclude), "albums": AlbumStore.get_albums_by_albumartist(a, limit, exclude=base_title),
} }
for a in albumartists for a in albumartists
] ]
@ -141,7 +141,6 @@ def get_album_versions():
artisthash: str = data['artisthash'] artisthash: str = data['artisthash']
albums = AlbumStore.get_albums_by_artisthash(artisthash) albums = AlbumStore.get_albums_by_artisthash(artisthash)
print(base_title, artisthash)
albums = [ albums = [
a for a in albums a for a in albums
@ -149,8 +148,6 @@ def get_album_versions():
create_hash(a.base_title) == create_hash(base_title) and create_hash(og_album_title) != create_hash(a.og_title) create_hash(a.base_title) == create_hash(base_title) and create_hash(og_album_title) != create_hash(a.og_title)
] ]
print(albums)
return { return {
"data": albums "data": albums
} }

View File

@ -2,6 +2,7 @@
Contains all the artist(s) routes. Contains all the artist(s) routes.
""" """
from collections import deque from collections import deque
from pprint import pprint
from flask import Blueprint, request from flask import Blueprint, request
@ -45,7 +46,7 @@ class ArtistsCache:
artists: deque[CacheEntry] = deque(maxlen=1) artists: deque[CacheEntry] = deque(maxlen=1)
@classmethod @classmethod
def get_albums_by_artisthash(cls, artisthash: str): def get_albums_by_artisthash(cls, artisthash: str) -> tuple[list[Album], int]:
""" """
Returns the cached albums for the given artisthash. Returns the cached albums for the given artisthash.
""" """
@ -138,6 +139,7 @@ class ArtistsCache:
album.check_is_single(album_tracks) album.check_is_single(album_tracks)
entry.type_checked = True entry.type_checked = True
entry.albums.sort(key=lambda a: a.date, reverse=True)
def add_albums_to_cache(artisthash: str): def add_albums_to_cache(artisthash: str):
@ -235,10 +237,10 @@ def get_artist_albums(artisthash: str):
singles = [a for a in all_albums if a.is_single] singles = [a for a in all_albums if a.is_single]
eps = [a for a in all_albums if a.is_EP] eps = [a for a in all_albums if a.is_EP]
def remove_EPs_and_singles(albums: list[Album]): def remove_EPs_and_singles(albums_: list[Album]):
albums = [a for a in albums if not a.is_EP] albums_ = [a for a in albums_ if not a.is_EP]
albums = [a for a in albums if not a.is_single] albums_ = [a for a in albums_ if not a.is_single]
return albums return albums_
albums = filter(lambda a: artisthash in a.albumartists_hashes, all_albums) albums = filter(lambda a: artisthash in a.albumartists_hashes, all_albums)
albums = list(albums) albums = list(albums)

View File

@ -6,6 +6,7 @@ from tqdm import tqdm
from app.models import Album, Track from app.models import Album, Track
from app.db.sqlite.albums import SQLiteAlbumMethods as aldb from app.db.sqlite.albums import SQLiteAlbumMethods as aldb
from .tracks import TrackStore from .tracks import TrackStore
from ..utils.hashing import create_hash
class AlbumStore: class AlbumStore:
@ -73,7 +74,7 @@ class AlbumStore:
albums = [album for album in cls.albums if artisthash in album.albumartists_hashes] albums = [album for album in cls.albums if artisthash in album.albumartists_hashes]
albums = [album for album in albums if album.albumhash != exclude] albums = [album for album in albums if create_hash(album.base_title) != create_hash(exclude)]
if len(albums) > limit: if len(albums) > limit:
random.shuffle(albums) random.shuffle(albums)