client: try new icon set

- server: fix search endpoint
This commit is contained in:
geoffrey45
2021-12-30 00:13:53 +03:00
parent c8d1f5f012
commit 477072daf0
10 changed files with 66 additions and 75 deletions
+43 -45
View File
@@ -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/<file_id>')
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/<query>')
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}
return {'songs': songs_array, 'info': album_obj}
+1 -1
View File
@@ -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,
+15 -9
View File
@@ -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)