add route to get all tracks in path

+ add routes to save album and artist as a playlist
This commit is contained in:
mungai-njoroge
2023-08-04 13:40:48 +03:00
parent efb6aae927
commit 655fd8bc22
7 changed files with 169 additions and 38 deletions
+22 -4
View File
@@ -2,16 +2,18 @@
Contains all the folder routes.
"""
import os
import psutil
from pathlib import Path
import psutil
from flask import Blueprint, request
from showinfm import show_in_file_manager
from app import settings
from app.lib.folderslib import GetFilesAndDirs, get_folders
from app.db.sqlite.settings import SettingsSQLMethods as db
from app.utils.wintools import win_replace_slash, is_windows
from app.lib.folderslib import GetFilesAndDirs, get_folders
from app.serializers.track import track_serializer
from app.store.tracks import TrackStore as store
from app.utils.wintools import is_windows, win_replace_slash
api = Blueprint("folder", __name__, url_prefix="")
@@ -129,3 +131,19 @@ def open_in_file_manager():
show_in_file_manager(path)
return {"success": True}
@api.route("/folder/tracks/all")
def get_tracks_in_path():
path = request.args.get("path")
if path is None:
return {"error": "No path provided."}, 400
tracks = store.get_tracks_in_path(path)
tracks = sorted(tracks, key=lambda i: i.last_mod)
tracks = (track_serializer(t) for t in tracks if Path(t.filepath).exists())
return {
"tracks": list(tracks)[:300],
}