server: 😜 fix remove dups

This commit is contained in:
geoffrey45
2021-12-29 22:49:58 +03:00
parent 6dbf8efb90
commit c8d1f5f012
3 changed files with 18 additions and 4 deletions
+4 -2
View File
@@ -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'])
+11 -2
View File
@@ -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
+3
View File
@@ -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)