mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-06 03:05:35 +00:00
sort albums in get_artist_albums route
This commit is contained in:
parent
45bf7570a3
commit
b9f0204225
@ -108,14 +108,14 @@ def get_artist_albums():
|
||||
|
||||
albumartists: str = data["albumartists"]
|
||||
limit: int = data.get("limit")
|
||||
exclude: str = data.get("exclude")
|
||||
base_title: str = data.get("base_title")
|
||||
|
||||
albumartists: list[str] = albumartists.split(",")
|
||||
|
||||
albums = [
|
||||
{
|
||||
"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
|
||||
]
|
||||
@ -141,7 +141,6 @@ def get_album_versions():
|
||||
artisthash: str = data['artisthash']
|
||||
|
||||
albums = AlbumStore.get_albums_by_artisthash(artisthash)
|
||||
print(base_title, artisthash)
|
||||
|
||||
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)
|
||||
]
|
||||
|
||||
print(albums)
|
||||
|
||||
return {
|
||||
"data": albums
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
Contains all the artist(s) routes.
|
||||
"""
|
||||
from collections import deque
|
||||
from pprint import pprint
|
||||
|
||||
from flask import Blueprint, request
|
||||
|
||||
@ -45,7 +46,7 @@ class ArtistsCache:
|
||||
artists: deque[CacheEntry] = deque(maxlen=1)
|
||||
|
||||
@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.
|
||||
"""
|
||||
@ -138,6 +139,7 @@ class ArtistsCache:
|
||||
album.check_is_single(album_tracks)
|
||||
|
||||
entry.type_checked = True
|
||||
entry.albums.sort(key=lambda a: a.date, reverse=True)
|
||||
|
||||
|
||||
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]
|
||||
eps = [a for a in all_albums if a.is_EP]
|
||||
|
||||
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_single]
|
||||
return albums
|
||||
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_single]
|
||||
return albums_
|
||||
|
||||
albums = filter(lambda a: artisthash in a.albumartists_hashes, all_albums)
|
||||
albums = list(albums)
|
||||
|
@ -6,6 +6,7 @@ from tqdm import tqdm
|
||||
from app.models import Album, Track
|
||||
from app.db.sqlite.albums import SQLiteAlbumMethods as aldb
|
||||
from .tracks import TrackStore
|
||||
from ..utils.hashing import create_hash
|
||||
|
||||
|
||||
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 albums if album.albumhash != exclude]
|
||||
albums = [album for album in albums if create_hash(album.base_title) != create_hash(exclude)]
|
||||
|
||||
if len(albums) > limit:
|
||||
random.shuffle(albums)
|
||||
|
Loading…
x
Reference in New Issue
Block a user