Overview
MUDE consists of several key components:- Extension activation - Initializes the extension and sets up MPV
- MPV player wrapper - Controls audio playback
- YouTube Music integration - Searches and downloads music
- Recommendation system - Manages playlists and auto-play
- UI controls - Status bar buttons and commands
- State management - Persists playback state across sessions
Extension activation flow
The extension activates when VS Code starts up (onStartupFinished). Hereβs what happens:
Activation sequence
- Storage setup - Creates global storage directory for downloaded files
- MPV initialization - Starts the MPV player process
- Component registration - Registers commands, controls, and status bar
- State restoration - Restores the last played track if available
MPV integration
MUDE uses thenode-mpv library to control the MPV media player:
Key MPV features used
- Audio-only mode - No video rendering for better performance
- Auto-restart - Automatically restarts MPV if it crashes
- Property access - Get media title, duration, pause state
- Event listeners - React to playback events (started, stopped, timeposition)
MPV events
The player emits events that drive the UI:YouTube Music API usage
MUDE uses theytmusic-api library to search and fetch recommendations:
Search functionality
Download process
MUDE usesyoutube-dl-exec (yt-dlp) to download audio:
{globalStorage}/youtube_download.webm, which gets overwritten for each new track.
Recommendation system
The recommendation system provides automatic playlist continuation:How it works
- Fetch recommendations - When a track is selected, fetch related tracks:
- Store globally - Recommendations are stored in memory and persisted:
- Auto-play next - When a track stops, automatically play the next:
Navigation
Users can navigate recommendations manually:- Play next -
MudePlayer.playNextcommand - Play previous -
MudePlayer.playPreviouscommand
State management
MUDE persists state across VS Code restarts usingcontext.globalState:
Persisted state
lastPlayedFilePath- Path to the last downloaded trackyoutubeLabelButton- Current track titlerecommendations- Array of recommended trackscurrentRecommendationIndex- Current position in playlistisPlaying- Whether player is active
Multi-window synchronization
When multiple VS Code windows are open, state is synchronized:UI integration
The status bar provides all playback controls:Status bar items (left to right)
- Logo button (π§) - Opens search
- Previous button - Play previous track
- Seek backward - -10 seconds
- Play/pause button - Toggle playback
- Seek forward - +10 seconds
- Next button - Play next track
- Track label - Current track name
- Timestamp - Current playback position
Command palette
All controls are also available via command palette:MUDE: Search MusicMUDE: Toggle PauseMUDE: +10 secMUDE: -10 secMUDE: Play Next TrackMUDE: Play Previous Track
Data flow
Hereβs how data flows through the system:File structure
extension.ts- Entry point, activation/deactivationplayer.ts- MPV player instancesearchYoutube.ts- Search UI and download logicyoutube.ts- YouTube Music API and yt-dlp integrationgetRecommendations.ts- Fetches related tracksrecommendations.ts- Manages recommendation statenextsongs.ts- Next/previous navigationcontrols.ts- Command handlers for playback controlsstatusBar.ts- Status bar UI and state managementsearchHistory.ts- Recent plays history
Dependencies
Key external dependencies:node-mpv- MPV player wrapper for Node.jsytmusic-api- YouTube Music API clientyoutube-dl-exec- yt-dlp wrapper for downloading audiovscode- VS Code extension API