diff --git a/server/app/api.py b/server/app/api.py index aab17bb..23d3a22 100644 --- a/server/app/api.py +++ b/server/app/api.py @@ -46,18 +46,50 @@ def search_by_title(): else: query = request.args.get('q') - all_songs = [] + albums = [] + artists = [] - songs = all_songs_instance.find_song_by_title(query) - all_songs.append(convert_to_json(songs)) + s = all_songs_instance.find_song_by_title(query) + songs = convert_to_json(s) - songs_by_albums = all_songs_instance.get_songs_by_album(query) - all_songs.append(convert_to_json(songs_by_albums)) + al = all_songs_instance.search_songs_by_album(query) + songs_by_album = convert_to_json(al) - songs_by_artists = all_songs_instance.find_songs_by_artist(query) - all_songs.append(convert_to_json(songs_by_artists)) + ar = all_songs_instance.search_songs_by_artist(query) + songs_by_artists = convert_to_json(ar) - return {'songs': all_songs} + + for song in songs_by_album: + album_obj = { + "name": song["album"], + "artists": song["artists"], + } + + if album_obj not in albums: + albums.append(album_obj) + + for album in albums: + try: + image = convert_one_to_json(all_songs_instance.get_song_by_album(album['name'], album['artists']))['image'] + except: + image: None + + album['image'] = image + + for song in songs_by_artists: + a = song["artists"].split(', ') + + for artist in a: + if query.lower() in artist.lower(): + + artist_obj = { + "name": artist, + } + + if artist_obj not in artists: + artists.append(artist_obj) + + return {'songs': remove_duplicates(songs), 'albums': albums, 'artists': artists} @bp.route('/populate') @@ -96,18 +128,6 @@ def populate(): bar.finish() return {'msg': 'updated everything'} - -@bp.route('/file/') -def send_audio(file_id): - song_obj = all_songs_instance.get_song_by_id(file_id) - loaded_song = convert_one_to_json(song_obj) - - filepath = loaded_song['filepath'].split('/')[-1] - print(loaded_song['folder'] + filepath) - - return send_from_directory(home_dir + loaded_song['folder'], filepath) - - @bp.route("/folder/artists") def get_folder_artists(): dir = request.args.get('dir') @@ -282,34 +302,12 @@ def getFolderTree(folder: str = None): for song in songs: song['artists'] = song['artists'].split(', ') - song['filepath'] = song['filepath'].replace(home_dir, '') song['image'] = img_path + song['image'] song['type']['name'] = "folder" song['type']['id'] = req_dir - return {"files": remove_duplicates(songs), "folders": sorted(folders, key= lambda i: i['name'])} - - -@bp.route('/get/queue', methods=['POST']) -def post(): - args = request.get_json() - - type = args['type'] - id = args['id'] - - if type == "folder": - songs = all_songs_instance.find_songs_by_folder_og(id) - songs_array = convert_to_json(songs) - - for song in songs_array: - song['artists'] = song['artists'].split(', ') - song['filepath'] = song['filepath'].replace(home_dir, '') - song['image'] = img_path + song['image'] - - return {'songs': songs_array} - - return {'msg': 'ok'} + return {"files": remove_duplicates(songs), "folders": sorted(folders, key=lambda i: i['name'])} @bp.route('/qwerty') @@ -353,6 +351,7 @@ def getAlbums(): return {'albums': albums} + @bp.route('/albums/') def getAlbumSongs(query: str): album = query.split('::')[0].replace('|', '/') @@ -365,7 +364,6 @@ def getAlbumSongs(query: str): for song in songs_array: song['artists'] = song['artists'].split(', ') - song['filepath'] = song['filepath'].replace(home_dir, '') song['image'] = img_path + song['image'] album_obj = { @@ -376,4 +374,4 @@ def getAlbumSongs(query: str): "artist": songs_array[0]['album_artist'] # "date": songs_array[0]['date'] } - return {'songs': songs_array, 'info': album_obj} \ No newline at end of file + return {'songs': songs_array, 'info': album_obj} diff --git a/server/app/helpers.py b/server/app/helpers.py index 1d70cd1..47011ec 100644 --- a/server/app/helpers.py +++ b/server/app/helpers.py @@ -154,7 +154,7 @@ def getTags(full_path): img_path = extract_thumb(full_path) tags = { - "filepath": full_path, + "filepath": full_path.replace(home_dir, ''), "folder": os.path.dirname(full_path).replace(home_dir, ""), "title": title, "artists": artists, diff --git a/server/app/models.py b/server/app/models.py index b478561..d154f07 100644 --- a/server/app/models.py +++ b/server/app/models.py @@ -35,25 +35,31 @@ class AllSongs(Mongo): # def drop_db(self): # self.collection.drop() - def get_song_by_id(self, file_id): - return self.collection.find_one({'_id': ObjectId(file_id)}) - def insert_song(self, song_obj): self.collection.update_one( {'filepath': song_obj['filepath']}, {"$set": song_obj}, upsert=True) + def get_all_songs(self): + return self.collection.find().limit(25) + + def get_song_by_id(self, file_id): + return self.collection.find_one({'_id': ObjectId(file_id)}) + + def get_song_by_album(self, name, artist): + return self.collection.find_one({'album': name, 'album_artist': artist}) + + def search_songs_by_album(self, query): + return self.collection.find({'album': {'$regex': query, '$options': 'i'}}) + + def search_songs_by_artist(self, query): + return self.collection.find({'artists': {'$regex': query, '$options': 'i'}}) + def find_song_by_title(self, query): self.collection.create_index([('title', pymongo.TEXT)]) return self.collection.find({'title': {'$regex': query, '$options': 'i'}}) 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) def find_songs_by_folder(self, query): return self.collection.find({'folder': query}).sort('title', pymongo.ASCENDING) diff --git a/src/assets/icons/album.svg b/src/assets/icons/album.svg index 95a9ab8..a3c051a 100644 --- a/src/assets/icons/album.svg +++ b/src/assets/icons/album.svg @@ -1,5 +1 @@ - - - - - + diff --git a/src/assets/icons/artist.svg b/src/assets/icons/artist.svg index e1080a6..2b4b86f 100644 --- a/src/assets/icons/artist.svg +++ b/src/assets/icons/artist.svg @@ -1,3 +1 @@ - - - + diff --git a/src/assets/icons/folder.svg b/src/assets/icons/folder.svg index 5d3e766..556d118 100644 --- a/src/assets/icons/folder.svg +++ b/src/assets/icons/folder.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/assets/icons/home.svg b/src/assets/icons/home.svg index 4de4753..eb92d76 100644 --- a/src/assets/icons/home.svg +++ b/src/assets/icons/home.svg @@ -1 +1 @@ - + \ No newline at end of file diff --git a/src/assets/icons/mix.svg b/src/assets/icons/mix.svg index e37728e..8a16260 100644 --- a/src/assets/icons/mix.svg +++ b/src/assets/icons/mix.svg @@ -1,6 +1 @@ - - - - - - + diff --git a/src/assets/icons/playlist.svg b/src/assets/icons/playlist.svg index f2af27b..b7bc255 100644 --- a/src/assets/icons/playlist.svg +++ b/src/assets/icons/playlist.svg @@ -1,3 +1 @@ - - - + diff --git a/src/assets/icons/settings.svg b/src/assets/icons/settings.svg index 39e2112..91ffeed 100644 --- a/src/assets/icons/settings.svg +++ b/src/assets/icons/settings.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file