feat(wave): implement Phase 1 Smart Wave recommendations and buffer rotation
This commit is contained in:
1 parent
aa6c605d14
commit
9fbe372fab
10 files changed
+879
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import os
|
||||
import json
|
||||
from app.config import settings
|
||||
|
||||
def ensure_smart_playlist(playlist_name: str = "Моя Волна") -> str:
|
||||
"""Ensure Navidrome .nsp Smart Playlist exists in library."""
|
||||
playlists_dir = os.path.join(settings.MUSIC_DIR, "playlists")
|
||||
os.makedirs(playlists_dir, exist_ok=True)
|
||||
|
||||
nsp_path = os.path.join(playlists_dir, f"{playlist_name}.nsp")
|
||||
|
||||
# Path inside Navidrome is relative to /music
|
||||
nsp_content = {
|
||||
"all": [
|
||||
{
|
||||
"path": {
|
||||
"contains": "AI Recommendations/Моя Волна"
|
||||
}
|
||||
}
|
||||
],
|
||||
"sort": "random",
|
||||
"limit": 100
|
||||
}
|
||||
|
||||
with open(nsp_path, "w", encoding="utf-8") as f:
|
||||
json.dump(nsp_content, f, ensure_ascii=False, indent=2)
|
||||
|
||||
# Also generate M3U8 playlist at music root for universal Subsonic auto-import
|
||||
wave_dir = os.path.join(settings.MUSIC_DIR, "AI Recommendations", "Моя Волна")
|
||||
m3u_path = os.path.join(settings.MUSIC_DIR, f"{playlist_name}.m3u8")
|
||||
|
||||
lines = ["#EXTM3U\n"]
|
||||
if os.path.exists(wave_dir):
|
||||
for f in sorted(os.listdir(wave_dir)):
|
||||
if f.lower().endswith(".mp3"):
|
||||
lines.append(f"#EXTINF:-1,{os.path.splitext(f)[0]}\n")
|
||||
lines.append(f"AI Recommendations/Моя Волна/{f}\n")
|
||||
|
||||
with open(m3u_path, "w", encoding="utf-8") as f:
|
||||
f.writelines(lines)
|
||||
|
||||
return nsp_path
|
||||
Reference in new issue
Block a user