mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +00:00
show playlists in folder view
This commit is contained in:
@@ -5,7 +5,6 @@ from flask_openapi3 import APIBlueprint
|
|||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
from app.api.apischemas import GenericLimitSchema
|
from app.api.apischemas import GenericLimitSchema
|
||||||
from app.db.libdata import TrackTable
|
|
||||||
from app.db.userdata import FavoritesTable
|
from app.db.userdata import FavoritesTable
|
||||||
from app.lib.extras import get_extra_info
|
from app.lib.extras import get_extra_info
|
||||||
from app.models import FavType
|
from app.models import FavType
|
||||||
|
|||||||
+71
-2
@@ -2,6 +2,7 @@
|
|||||||
Contains all the folder routes.
|
Contains all the folder routes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@@ -14,8 +15,10 @@ from showinfm import show_in_file_manager
|
|||||||
from app import settings
|
from app import settings
|
||||||
from app.config import UserConfig
|
from app.config import UserConfig
|
||||||
from app.db.libdata import TrackTable
|
from app.db.libdata import TrackTable
|
||||||
|
from app.db.userdata import FavoritesTable, PlaylistTable
|
||||||
from app.lib.folderslib import get_files_and_dirs, get_folders
|
from app.lib.folderslib import get_files_and_dirs, get_folders
|
||||||
from app.serializers.track import serialize_track
|
from app.serializers.track import serialize_track, serialize_tracks
|
||||||
|
from app.store.tracks import TrackStore
|
||||||
from app.utils.wintools import is_windows, win_replace_slash
|
from app.utils.wintools import is_windows, win_replace_slash
|
||||||
|
|
||||||
tag = Tag(name="Folders", description="Get folders and tracks in a directory")
|
tag = Tag(name="Folders", description="Get folders and tracks in a directory")
|
||||||
@@ -73,6 +76,7 @@ def get_folder_tree(body: FolderTree):
|
|||||||
|
|
||||||
Returns a list of all the folders and tracks in the given folder.
|
Returns a list of all the folders and tracks in the given folder.
|
||||||
"""
|
"""
|
||||||
|
og_req_dir = body.folder
|
||||||
req_dir = body.folder
|
req_dir = body.folder
|
||||||
tracks_only = body.tracks_only
|
tracks_only = body.tracks_only
|
||||||
|
|
||||||
@@ -96,6 +100,54 @@ def get_folder_tree(body: FolderTree):
|
|||||||
"tracks": [],
|
"tracks": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if req_dir.startswith("$playlist"):
|
||||||
|
splits = req_dir.split("/")
|
||||||
|
|
||||||
|
if len(splits) == 2:
|
||||||
|
pid = splits[1]
|
||||||
|
playlist = PlaylistTable.get_by_id(int(pid))
|
||||||
|
tracks = TrackStore.get_tracks_by_trackhashes(
|
||||||
|
playlist.trackhashes[body.start : body.start + body.limit]
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"path": req_dir,
|
||||||
|
"folders": [],
|
||||||
|
"tracks": serialize_tracks(tracks),
|
||||||
|
}
|
||||||
|
|
||||||
|
playlists = PlaylistTable.get_all()
|
||||||
|
playlists = sorted(
|
||||||
|
playlists,
|
||||||
|
key=lambda p: datetime.strptime(p.last_updated, "%Y-%m-%d %H:%M:%S"),
|
||||||
|
reverse=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
for playlist in playlists:
|
||||||
|
playlist.clear_lists()
|
||||||
|
|
||||||
|
return {
|
||||||
|
"path": req_dir,
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"name": p.name,
|
||||||
|
"path": f"$playlist/{p.id}",
|
||||||
|
}
|
||||||
|
for p in playlists
|
||||||
|
],
|
||||||
|
"tracks": [],
|
||||||
|
}
|
||||||
|
|
||||||
|
if req_dir == "$favorites":
|
||||||
|
tracks, total = FavoritesTable.get_fav_tracks(body.start, body.limit)
|
||||||
|
tracks = TrackStore.get_tracks_by_trackhashes([t.hash for t in tracks])
|
||||||
|
|
||||||
|
return {
|
||||||
|
"tracks": serialize_tracks(tracks),
|
||||||
|
"folders": [],
|
||||||
|
"path": req_dir,
|
||||||
|
}
|
||||||
|
|
||||||
if is_windows():
|
if is_windows():
|
||||||
# Trailing slash needed when drive letters are passed,
|
# Trailing slash needed when drive letters are passed,
|
||||||
# Remember, the trailing slash is removed in the client.
|
# Remember, the trailing slash is removed in the client.
|
||||||
@@ -104,7 +156,7 @@ def get_folder_tree(body: FolderTree):
|
|||||||
else:
|
else:
|
||||||
req_dir = "/" + req_dir if not req_dir.startswith("/") else req_dir
|
req_dir = "/" + req_dir if not req_dir.startswith("/") else req_dir
|
||||||
|
|
||||||
return get_files_and_dirs(
|
results = get_files_and_dirs(
|
||||||
req_dir,
|
req_dir,
|
||||||
start=body.start,
|
start=body.start,
|
||||||
limit=body.limit,
|
limit=body.limit,
|
||||||
@@ -115,6 +167,23 @@ def get_folder_tree(body: FolderTree):
|
|||||||
foldersort_reverse=body.foldersort_reverse,
|
foldersort_reverse=body.foldersort_reverse,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if og_req_dir == "$home" and config.showPlaylistsInFolderView:
|
||||||
|
# Get all playlists and return them as a list of folders
|
||||||
|
playlists_item = {
|
||||||
|
"name": "Playlists",
|
||||||
|
"path": "$playlists",
|
||||||
|
}
|
||||||
|
|
||||||
|
favorites_item = {
|
||||||
|
"name": "Favorites",
|
||||||
|
"path": "$favorites",
|
||||||
|
}
|
||||||
|
|
||||||
|
results["folders"].insert(0, playlists_item)
|
||||||
|
results["folders"].insert(0, favorites_item)
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
def get_all_drives(is_win: bool = False):
|
def get_all_drives(is_win: bool = False):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class UserConfig:
|
|||||||
"Smith & Thell",
|
"Smith & Thell",
|
||||||
"Peter, Paul & Mary",
|
"Peter, Paul & Mary",
|
||||||
"Simon & Garfunkel",
|
"Simon & Garfunkel",
|
||||||
|
"Judy & Mary",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
genreSeparators: set[str] = field(default_factory=lambda: {"/", ";", "&"})
|
genreSeparators: set[str] = field(default_factory=lambda: {"/", ";", "&"})
|
||||||
@@ -48,6 +49,7 @@ class UserConfig:
|
|||||||
enablePeriodicScans: bool = False
|
enablePeriodicScans: bool = False
|
||||||
scanInterval: int = 10
|
scanInterval: int = 10
|
||||||
enableWatchdog: bool = False
|
enableWatchdog: bool = False
|
||||||
|
showPlaylistsInFolderView: bool = False
|
||||||
|
|
||||||
# plugins
|
# plugins
|
||||||
enablePlugins: bool = True
|
enablePlugins: bool = True
|
||||||
|
|||||||
Reference in New Issue
Block a user