add method and route to search across tracks, albums and artists.

+ break models into separate files
+ same for the utils and setup
This commit is contained in:
geoffrey45
2023-03-09 13:08:50 +03:00
parent d39c0ea2f8
commit e3ec9db989
55 changed files with 1113 additions and 1137 deletions
+23
View File
@@ -0,0 +1,23 @@
from collections import defaultdict
from operator import attrgetter
from app.models import Track
def remove_duplicates(tracks: list[Track]) -> list[Track]:
"""
Remove duplicates from a list of Track objects based on the trackhash attribute.
Retains objects with the highest bitrate.
"""
hash_to_tracks = defaultdict(list)
for track in tracks:
hash_to_tracks[track.trackhash].append(track)
tracks = []
for track_group in hash_to_tracks.values():
max_bitrate_track = max(track_group, key=attrgetter("bitrate"))
tracks.append(max_bitrate_track)
return tracks