diff --git a/server/app/api.py b/server/app/api.py index 1a1ece7e..aab17bb7 100644 --- a/server/app/api.py +++ b/server/app/api.py @@ -51,7 +51,7 @@ def search_by_title(): songs = all_songs_instance.find_song_by_title(query) all_songs.append(convert_to_json(songs)) - songs_by_albums = all_songs_instance.find_songs_by_album(query) + songs_by_albums = all_songs_instance.get_songs_by_album(query) all_songs.append(convert_to_json(songs_by_albums)) songs_by_artists = all_songs_instance.find_songs_by_artist(query) @@ -277,7 +277,9 @@ def getFolderTree(folder: str = None): songs_array = all_songs_instance.find_songs_by_folder( req_dir) + songs = convert_to_json(songs_array) + for song in songs: song['artists'] = song['artists'].split(', ') song['filepath'] = song['filepath'].replace(home_dir, '') @@ -286,7 +288,7 @@ def getFolderTree(folder: str = None): song['type']['name'] = "folder" song['type']['id'] = req_dir - return {"files": songs, "folders": sorted(folders, key= lambda i: i['name'])} + return {"files": remove_duplicates(songs), "folders": sorted(folders, key= lambda i: i['name'])} @bp.route('/get/queue', methods=['POST']) diff --git a/server/app/helpers.py b/server/app/helpers.py index fe8586c8..1d70cd1a 100644 --- a/server/app/helpers.py +++ b/server/app/helpers.py @@ -94,13 +94,13 @@ def getTags(full_path): try: audio = FLAC(full_path) except: - return + return elif full_path.endswith('.mp3'): try: audio = MP3(full_path) except: return - + try: artists = audio['artist'][0] except KeyError: @@ -202,6 +202,15 @@ def get_folders(): def remove_duplicates(array): + song_num = 0 + + while song_num < len(array): + for index, song in enumerate(array): + if array[song_num]["title"] == song["title"] and array[song_num]["album"] == song["album"] and array[song_num]["artists"] == song["artists"] and index != song_num: + array.remove(song) + + song_num += 1 + return array diff --git a/server/app/models.py b/server/app/models.py index 36e4c520..b4785616 100644 --- a/server/app/models.py +++ b/server/app/models.py @@ -48,6 +48,9 @@ class AllSongs(Mongo): def find_songs_by_album(self, name, artist): return self.collection.find({'album': name, 'album_artist': artist}) + + def get_songs_by_album(self, query): + return self.collection.find({'album': query}) def get_all_songs(self): return self.collection.find().limit(25)