fix: folder endpoint returning same track for different files of the same trackhash

+ fix: chunked streaming. return instead of yield chunks
This commit is contained in:
cwilvx
2024-08-15 17:07:34 +03:00
parent cd992419c5
commit ca31054f48
18 changed files with 508 additions and 138 deletions
+23 -17
View File
@@ -44,19 +44,19 @@ class AlbumMapEntry:
class AlbumStore:
albums: list[Album] = CustomList()
# albums: list[Album] = CustomList()
albummap: dict[str, AlbumMapEntry] = {}
@staticmethod
def create_album(track: Track):
"""
Creates album object from a track
"""
return Album(
albumhash=track.albumhash,
albumartists=track.albumartists, # type: ignore
title=track.og_album,
)
# @staticmethod
# def create_album(track: Track):
# """
# Creates album object from a track
# """
# return Album(
# albumhash=track.albumhash,
# albumartists=track.albumartists, # type: ignore
# title=track.og_album,
# )
@classmethod
def load_albums(cls, instance_key: str):
@@ -74,6 +74,12 @@ class AlbumStore:
}
print("Done!")
@classmethod
def index_new_album(cls, album: Album, trackhashes: set[str]):
cls.albummap[album.albumhash] = AlbumMapEntry(
album=album, trackhashes=trackhashes
)
@classmethod
def get_flat_list(cls):
"""
@@ -141,12 +147,12 @@ class AlbumStore:
master_string = "-".join(a.albumartists_hashes for a in cls.albums)
return master_string.count(artisthash)
@classmethod
def album_exists(cls, albumhash: str) -> bool:
"""
Checks if an album exists.
"""
return albumhash in "-".join([a.albumhash for a in cls.albums])
# @classmethod
# def album_exists(cls, albumhash: str) -> bool:
# """
# Checks if an album exists.
# """
# return albumhash in "-".join([a.albumhash for a in cls.albums])
@classmethod
def remove_album(cls, album: Album):
+51 -52
View File
@@ -34,11 +34,10 @@ class ArtistMapEntry:
class ArtistStore:
artists: list[Artist] = CustomList()
artistmap: dict[str, ArtistMapEntry] = {}
@classmethod
def load_artists(cls, instance_key: str):
def load_artists(cls, instance_key: str, _trackhashes: list[str] = []):
"""
Loads all artists from the database into the store.
"""
@@ -52,7 +51,7 @@ class ArtistStore:
artist.artisthash: ArtistMapEntry(
artist=artist, albumhashes=albumhashes, trackhashes=trackhashes
)
for artist, trackhashes, albumhashes in create_artists()
for artist, trackhashes, albumhashes in create_artists(_trackhashes)
}
# for track in TrackStore.get_flat_list():
@@ -77,35 +76,35 @@ class ArtistStore:
"""
return [a.artist for a in cls.artistmap.values()]
@classmethod
def map_artist_color(cls, artist_tuple: tuple):
"""
Maps a color to the corresponding artist.
"""
# @classmethod
# def map_artist_color(cls, artist_tuple: tuple):
# """
# Maps a color to the corresponding artist.
# """
artisthash = artist_tuple[1]
color = json.loads(artist_tuple[2])
# artisthash = artist_tuple[1]
# color = json.loads(artist_tuple[2])
for artist in cls.artists:
if artist.artisthash == artisthash:
artist.set_colors(color)
break
# for artist in cls.artists:
# if artist.artisthash == artisthash:
# artist.set_colors(color)
# break
@classmethod
def add_artist(cls, artist: Artist):
"""
Adds an artist to the store.
"""
cls.artists.append(artist)
# @classmethod
# def add_artist(cls, artist: Artist):
# """
# Adds an artist to the store.
# """
# cls.artists.append(artist)
@classmethod
def add_artists(cls, artists: list[Artist]):
"""
Adds multiple artists to the store.
"""
for artist in artists:
if artist not in cls.artists:
cls.artists.append(artist)
# @classmethod
# def add_artists(cls, artists: list[Artist]):
# """
# Adds multiple artists to the store.
# """
# for artist in artists:
# if artist not in cls.artists:
# cls.artists.append(artist)
@classmethod
def get_artist_by_hash(cls, artisthash: str):
@@ -124,34 +123,34 @@ class ArtistStore:
artists = [cls.get_artist_by_hash(hash) for hash in artisthashes]
return [a for a in artists if a is not None]
@classmethod
def artist_exists(cls, artisthash: str) -> bool:
"""
Checks if an artist exists.
"""
return artisthash in "-".join([a.artisthash for a in cls.artists])
# @classmethod
# def artist_exists(cls, artisthash: str) -> bool:
# """
# Checks if an artist exists.
# """
# return artisthash in "-".join([a.artisthash for a in cls.artists])
@classmethod
def artist_has_tracks(cls, artisthash: str) -> bool:
"""
Checks if an artist has tracks.
"""
artists: set[str] = set()
# @classmethod
# def artist_has_tracks(cls, artisthash: str) -> bool:
# """
# Checks if an artist has tracks.
# """
# artists: set[str] = set()
for track in TrackStore.tracks:
artists.update(track.artist_hashes)
album_artists: list[str] = [a.artisthash for a in track.albumartists]
artists.update(album_artists)
# for track in TrackStore.tracks:
# artists.update(track.artist_hashes)
# album_artists: list[str] = [a.artisthash for a in track.albumartists]
# artists.update(album_artists)
master_hash = "-".join(artists)
return artisthash in master_hash
# master_hash = "-".join(artists)
# return artisthash in master_hash
@classmethod
def remove_artist_by_hash(cls, artisthash: str):
"""
Removes an artist from the store.
"""
cls.artists = CustomList(a for a in cls.artists if a.artisthash != artisthash)
# @classmethod
# def remove_artist_by_hash(cls, artisthash: str):
# """
# Removes an artist from the store.
# """
# cls.artists = CustomList(a for a in cls.artists if a.artisthash != artisthash)
@classmethod
def get_artist_tracks(cls, artisthash: str):
+7 -3
View File
@@ -39,10 +39,14 @@ class FolderStore:
trackhash = cls.map.get(filepath)
if trackhash:
track = TrackStore.trackhashmap.get(trackhash)
trackgroup = TrackStore.trackhashmap.get(trackhash)
if track:
yield track.tracks[0]
if trackgroup is None:
continue
for track in trackgroup.tracks:
if track.filepath == filepath:
yield track
@classmethod
def count_tracks_containing_paths(cls, paths: list[str]):