mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
remove pagination
This commit is contained in:
+29
-39
@@ -188,6 +188,7 @@ def populate_images():
|
||||
|
||||
return {'sample': artists_in_db_array[:25]}
|
||||
|
||||
|
||||
@bp.route("/artist/<artist>")
|
||||
@cache.cached()
|
||||
def getArtistData(artist: str):
|
||||
@@ -244,24 +245,13 @@ def getArtistData(artist: str):
|
||||
@bp.route("/f/<folder>")
|
||||
@cache.cached()
|
||||
def getFolderTree(folder: str = None):
|
||||
try:
|
||||
req_dir, last_id = folder.split('::')
|
||||
req_dir = folder.replace('|', '/')
|
||||
print(folder)
|
||||
|
||||
req_dir = req_dir.replace('|', '/')
|
||||
dir_list = req_dir.split('/')
|
||||
requested_dir = os.path.join(home_dir, *dir_list)
|
||||
if folder == "home":
|
||||
req_dir = home_dir
|
||||
|
||||
if req_dir == "home":
|
||||
requested_dir = home_dir
|
||||
|
||||
if last_id == "None":
|
||||
last_id = None
|
||||
|
||||
except:
|
||||
requested_dir = home_dir
|
||||
last_id = None
|
||||
|
||||
dir_content = os.scandir(requested_dir)
|
||||
dir_content = os.scandir(os.path.join(home_dir, req_dir))
|
||||
|
||||
folders = []
|
||||
|
||||
@@ -286,7 +276,7 @@ def getFolderTree(folder: str = None):
|
||||
getTags(entry.path)
|
||||
|
||||
songs_array = all_songs_instance.find_songs_by_folder(
|
||||
req_dir, last_id)
|
||||
req_dir)
|
||||
songs = convert_to_json(songs_array)
|
||||
for song in songs:
|
||||
song['artists'] = song['artists'].split(', ')
|
||||
@@ -299,27 +289,6 @@ def getFolderTree(folder: str = None):
|
||||
return {"files": songs, "folders": folders}
|
||||
|
||||
|
||||
@bp.route('/image/<img_type>/<image_id>')
|
||||
def send_image(img_type, image_id):
|
||||
if img_type == "thumbnail":
|
||||
song_obj = all_songs_instance.get_song_by_id(image_id)
|
||||
loaded_song = convert_one_to_json(song_obj)
|
||||
|
||||
img_dir = app_dir + "/images/thumbnails"
|
||||
image = loaded_song['image']
|
||||
|
||||
if img_type == "artist":
|
||||
artist_obj = artist_instance.get_artist_by_id(image_id)
|
||||
artist = convert_one_to_json(artist_obj)
|
||||
|
||||
img_dir = app_dir + "/images/artists"
|
||||
|
||||
image = artist['name'] + ".jpg"
|
||||
print(img_dir + image)
|
||||
|
||||
return send_from_directory(img_dir, image)
|
||||
|
||||
|
||||
@bp.route('/get/queue', methods=['POST'])
|
||||
def post():
|
||||
args = request.get_json()
|
||||
@@ -340,6 +309,7 @@ def post():
|
||||
|
||||
return {'msg': 'ok'}
|
||||
|
||||
|
||||
@bp.route('/qwerty')
|
||||
def populateArtists():
|
||||
all_songs = all_songs_instance.get_all_songs()
|
||||
@@ -358,5 +328,25 @@ def populateArtists():
|
||||
if a_obj not in artists:
|
||||
artists.append(a_obj)
|
||||
|
||||
artist_instance.insert_artist(a_obj)
|
||||
|
||||
return {'songs': artists}
|
||||
return {'songs': artists}
|
||||
|
||||
|
||||
@bp.route('/albums')
|
||||
def getAlbums():
|
||||
s = all_songs_instance.get_all_songs()
|
||||
ss = convert_to_json(s)
|
||||
|
||||
albums = []
|
||||
|
||||
for song in ss:
|
||||
al_obj = {
|
||||
"name": song['album'],
|
||||
"artist": song['artists']
|
||||
}
|
||||
|
||||
if al_obj not in albums:
|
||||
albums.append(al_obj)
|
||||
|
||||
return {'albums': albums}
|
||||
|
||||
@@ -7,13 +7,14 @@ class Mongo:
|
||||
mongo_uri = pymongo.MongoClient()
|
||||
self.db = mongo_uri[database]
|
||||
|
||||
|
||||
class Artists(Mongo):
|
||||
def __init__(self):
|
||||
super(Artists, self).__init__('ALL_ARTISTS')
|
||||
self.collection = self.db['THEM_ARTISTS']
|
||||
|
||||
def insert_artist(self, artist_obj):
|
||||
self.collection.update(artist_obj, artist_obj, upsert=True)
|
||||
self.collection.update_one(artist_obj, {'$set': artist_obj}, upsert=True)
|
||||
|
||||
def get_all_artists(self):
|
||||
return self.collection.find()
|
||||
@@ -48,20 +49,16 @@ class AllSongs(Mongo):
|
||||
return self.collection.find({'album': {'$regex': query, '$options': 'i'}})
|
||||
|
||||
def get_all_songs(self):
|
||||
return self.collection.find()
|
||||
return self.collection.find().limit(25)
|
||||
|
||||
def find_songs_by_folder(self, query, last_id=None):
|
||||
limit = 18
|
||||
if last_id is None:
|
||||
return self.collection.find({'folder': query}).limit(limit)
|
||||
else:
|
||||
return self.collection.find({'folder': query, '_id': {'$gt': ObjectId(last_id)}}).limit(limit)
|
||||
def find_songs_by_folder(self, query):
|
||||
return self.collection.find({'folder': query})
|
||||
|
||||
def find_songs_by_folder_og(self, query):
|
||||
return self.collection.find({'folder': query})
|
||||
|
||||
def find_songs_by_artist(self, query):
|
||||
return self.collection.find({'artists': {'$regex': query, '$options': 'i'}})
|
||||
return self.collection.find({'artists': query})
|
||||
|
||||
def find_songs_by_album_artist(self, query):
|
||||
return self.collection.find({'album_artist': {'$regex': query, '$options': 'i'}})
|
||||
|
||||
Reference in New Issue
Block a user