mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +00:00
client: implement queuing
This commit is contained in:
+50
-23
@@ -1,4 +1,6 @@
|
||||
import typing
|
||||
from app.models import Folders, Artists
|
||||
|
||||
from app.helpers import (
|
||||
all_songs_instance,
|
||||
convert_one_to_json,
|
||||
@@ -29,6 +31,7 @@ bp = Blueprint('api', __name__, url_prefix='')
|
||||
|
||||
artist_instance = Artists()
|
||||
folder_instance = Folders()
|
||||
img_path = "http://127.0.0.1:8900/images/thumbnails/"
|
||||
|
||||
|
||||
def main_whatever():
|
||||
@@ -242,26 +245,26 @@ def getArtistData():
|
||||
@bp.route("/f/<folder>")
|
||||
@cache.cached()
|
||||
def getFolderTree(folder: str = None):
|
||||
if folder == "home":
|
||||
requested_dir = home_dir
|
||||
|
||||
else:
|
||||
try:
|
||||
req_dir, last_id = folder.split('::')
|
||||
except (ValueError):
|
||||
req_dir = folder
|
||||
last_id = None
|
||||
try:
|
||||
req_dir, last_id = folder.split('::')
|
||||
|
||||
req_dir = req_dir.replace('|', '/')
|
||||
dir_list = req_dir.split('/')
|
||||
requested_dir = os.path.join(home_dir, *dir_list)
|
||||
|
||||
if req_dir:
|
||||
dir_list = req_dir.split('/')
|
||||
requested_dir = os.path.join(home_dir, *dir_list)
|
||||
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)
|
||||
|
||||
folders = []
|
||||
files = []
|
||||
|
||||
for entry in dir_content:
|
||||
if entry.is_dir() and not entry.name.startswith('.'):
|
||||
@@ -278,20 +281,23 @@ def getFolderTree(folder: str = None):
|
||||
|
||||
if entry.is_file():
|
||||
if isValidFile(entry.name) == True:
|
||||
songs_array = all_songs_instance.find_songs_by_folder(
|
||||
req_dir, last_id)
|
||||
songs = convert_to_json(songs_array)
|
||||
for song in songs:
|
||||
song['artists'] = song['artists'].split(', ')
|
||||
file = all_songs_instance.find_song_by_path(entry.path)
|
||||
|
||||
files = songs
|
||||
if not file:
|
||||
getTags(entry.path)
|
||||
|
||||
for file in files:
|
||||
file['filepath'] = file['filepath'].replace(home_dir, '')
|
||||
|
||||
songs_array = all_songs_instance.find_songs_by_folder(
|
||||
req_dir, last_id)
|
||||
songs = convert_to_json(songs_array)
|
||||
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": files, "folders": folders}
|
||||
return {"files": songs, "folders": folders}
|
||||
|
||||
|
||||
@bp.route('/image/<img_type>/<image_id>')
|
||||
@@ -313,3 +319,24 @@ def send_image(img_type, image_id):
|
||||
print(img_dir + image)
|
||||
|
||||
return send_from_directory(img_dir, image)
|
||||
|
||||
|
||||
@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'}
|
||||
|
||||
+15
-9
@@ -54,16 +54,16 @@ def extract_thumb(path):
|
||||
return webp_path
|
||||
|
||||
if path.endswith('.flac'):
|
||||
audio = FLAC(path)
|
||||
try:
|
||||
audio = FLAC(path)
|
||||
album_art = audio.pictures[0].data
|
||||
except IndexError:
|
||||
except:
|
||||
album_art = None
|
||||
elif path.endswith('.mp3'):
|
||||
audio = ID3(path)
|
||||
try:
|
||||
audio = ID3(path)
|
||||
album_art = audio.getall('APIC')[0].data
|
||||
except IndexError:
|
||||
except:
|
||||
album_art = None
|
||||
|
||||
if album_art is None:
|
||||
@@ -91,10 +91,16 @@ def extract_thumb(path):
|
||||
|
||||
def getTags(full_path):
|
||||
if full_path.endswith('.flac'):
|
||||
audio = FLAC(full_path)
|
||||
try:
|
||||
audio = FLAC(full_path)
|
||||
except:
|
||||
return
|
||||
elif full_path.endswith('.mp3'):
|
||||
audio = MP3(full_path)
|
||||
|
||||
try:
|
||||
audio = MP3(full_path)
|
||||
except:
|
||||
return
|
||||
|
||||
try:
|
||||
artists = audio['artist'][0]
|
||||
except KeyError:
|
||||
@@ -122,8 +128,8 @@ def getTags(full_path):
|
||||
title = audio['TIT2'][0]
|
||||
except:
|
||||
title = 'Unknown'
|
||||
except IndexError:
|
||||
title = 'Unknown'
|
||||
except:
|
||||
title = full_path.split('/')[-1]
|
||||
|
||||
try:
|
||||
album = audio['album'][0]
|
||||
|
||||
@@ -51,8 +51,7 @@ class AllSongs(Mongo):
|
||||
|
||||
def insert_song(self, song_obj):
|
||||
self.collection.update_one(
|
||||
{'filepath': song_obj['filepath']}, { "$set": song_obj}, upsert=True)
|
||||
# self.collection.insert_one(song_obj)
|
||||
{'filepath': song_obj['filepath']}, {"$set": song_obj}, upsert=True)
|
||||
|
||||
def find_song_by_title(self, query):
|
||||
self.collection.create_index([('title', pymongo.TEXT)])
|
||||
@@ -71,6 +70,9 @@ class AllSongs(Mongo):
|
||||
else:
|
||||
return self.collection.find({'folder': query, '_id': {'$gt': ObjectId(last_id)}}).limit(limit)
|
||||
|
||||
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'}})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user