Skip to content

feat/apple music and optimizations#2

Open
daimoxd wants to merge 3 commits into
R0MADEV:mainfrom
daimoxd:feat/apple-music-and-optimizations
Open

feat/apple music and optimizations#2
daimoxd wants to merge 3 commits into
R0MADEV:mainfrom
daimoxd:feat/apple-music-and-optimizations

Conversation

@daimoxd

@daimoxd daimoxd commented Jun 5, 2026

Copy link
Copy Markdown

Description

This PR introduces a major overhaul of the audio, UI, and backend architecture to achieve extreme memory optimizations (zero-allocation hot paths). Additionally, it integrates a powerful new Apple Music module with a provider selector and a revamped TUI slash-command system.

Apple Music & New TUI Features

  • Provider Selector (/provider): Dynamically switch the active catalog between youtube and apple.
  • Apple Music Integration (apple.ts, gamdl.ts): Resolves, fetches libraries, and plays Apple Music tracks using gamdl under the hood. Requires authentication cookies to be set via /auth <cookies>.
  • Custom applemusic-api: Integrated a custom fork to enable direct fetching from the Apple Music catalog.
  • Slash Commands (commands.ts): Added a robust command bar at the bottom (/search, /library, /auth, /pause, /help, etc.).
  • Doctor (cli.ts): catunes doctor now checks and reports the status of gamdl.

Improved Performance & Zero-Allocation Hot Paths

  • Audio Engine (audio.ts):
    • Eliminated .map() and new Float64Array() instances on every frame. Pre-allocated _re, _im, _bands, and _wave static buffers.
    • Implemented PcmBuffer: a custom 64KB circular ring-buffer, entirely avoiding costly Buffer.concat() garbage collection cycles during playback.
  • Ink / React UI (app.tsx):
    • Adjusted the render tick from 90ms to 120ms (smoother performance, 25% less CPU overhead).
    • Double-buffering: Added index-swapped buffers (specBufRef, peakBufRef) for the React state to stop spreading arrays every tick.
    • Aggressive Memoization: Wrapped Visualizer, PixelCat, NowPlaying, PickList, and Panel in React.memo to drop redundant UI re-renders.
    • Eliminated the spread of player.state object; React now only re-renders when data actually changes.
  • Backend Relay (server/index.ts):
    • Implemented cached rosters.
    • Pre-serialized JSON broadcast payloads (_rosterPayload) to avoid recreating objects on every single WebSocket broadcast.
  • Caching & I/O (config.ts, playlist.ts, status.ts):
    • In-memory lazy cache for loadSettings() and loadPlaylist(). Writes to disk are now batched to prevent unnecessary I/O.
    • Shared utility fmtTime in fmt.ts to reduce code duplication.

Documentation

  • Updated README.md and README.es.md to properly document the new /auth requirement for Apple Music.
  • Rewrote the "Controls" section to highlight the new TUI slash-commands vs CLI mode.
  • Updated the Legal Disclaimer to properly address the use of third-party tools like gamdl and local file handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant