9.6 KiB
9.6 KiB
MovieMapper Agent Guidelines
Project Overview
MovieMapper is an Electron-based desktop application for organizing and managing movie and TV show collections. It provides features for browsing media files, searching TV shows using TheTVDB API, and managing file metadata with Jellyfin-compatible folder organization.
Build/Lint/Test Commands
Build Commands
npm install- Install project dependenciesnpm start- Run the application using Electronelectron .- Alternative way to run the application
Test Commands
npm test- Currently outputs "Error: no test specified" (default test script)node test-api.js- Run API connectivity test for TheTVDBnode main.js- Run main process directly for debugging (may require environment setup)
Syntax Checking
node --check renderer.js- Check renderer.js for syntax errorsnode --check main.js- Check main.js for syntax errorsnode --check utils/fileUtils.js- Check fileUtils.js for syntax errors
Linting
- No explicit linting tools configured in package.json
- Code style follows JavaScript/Node.js conventions
- Use JSDoc comments for documentation
Architecture Overview
Main Process (main.js)
- Handles all IPC communication with renderer
- File system operations (moving, renaming files)
- TheTVDB API integration with token authentication
- Audit logging to
.auditfiles in directories - Progress reporting via IPC events
Renderer Process (renderer.js)
- UI state management and DOM manipulation
- Event listeners for user interactions
- Tag management for files (extra, commentary)
- Progress spinner display during scanning
- Folder navigation and file display
File Utilities (utils/fileUtils.js)
- Non-recursive directory scanning (current folder only)
- FFmpeg integration for metadata extraction (duration, quality, fps)
- Progress callback support for UI updates
- Returns both folders and media files sorted (folders first)
Code Style Guidelines
Imports
- Use standard Node.js
require()syntax for modules - Import modules at the top of files
- Group imports by standard library, external modules, then local modules
- Use descriptive names for modules (e.g.,
const fs = require('fs'))
Formatting
- Use 2-space indentation
- Use single quotes for strings
- Place opening braces on the same line as the statement
- Add spaces around operators and after commas
- No semicolons required (follows JavaScript convention)
- Use consistent spacing around code blocks
Naming Conventions
- Use camelCase for variables and functions
- Use PascalCase for constructors
- Use UPPER_CASE for constants
- Use descriptive variable names
- Function names should be verbs (e.g.,
scanDirectory,extractFileMetadata) - File names should be lowercase with hyphens (e.g.,
file-utils.js)
Types
- This is a JavaScript project without TypeScript
- Use JSDoc comments to document function parameters and return values
- Use descriptive parameter names
- Include type information in comments for complex objects
Error Handling
- Use try/catch blocks for async operations
- Handle file system errors gracefully
- Log warnings for problematic files but don't crash the application
- Return consistent error structures:
{ success: true/false, error?: string, ... } - Use specific error messages with context information
- Implement proper error propagation throughout the application
IPC Communication Patterns
- Main process handlers use
ipcMain.handle()for async operations - Renderer invokes with
ipcRenderer.invoke()returning promises - Progress updates use
mainWindow.webContents.send()for push events - Renderer listens with
ipcRenderer.on()for progress events - Always return
{ success: boolean, ... }objects from IPC handlers
File Structure
main.js- Electron main process handling IPC and application lifecyclerenderer.js- Electron renderer process managing UI interactionsindex.html- Main HTML structure and styling (dark theme)utils/fileUtils.js- File scanning and metadata extraction utilities.env- Environment configuration file for API keysapp-debug.log- Application debug log file (created at startup)
API Integration
- TheTVDB v4 API integration using bearer token authentication
- Proper error handling for API calls
- Fallback mechanisms when metadata extraction fails
- Environment variables for API keys (TVDB_API_KEY)
- Implement authentication token caching for performance
Code Patterns
- Use async/await for handling asynchronous operations
- Handle permission errors gracefully when scanning directories
- Provide user feedback through console warnings for problematic files
- Use descriptive variable names that reflect their purpose
- Implement comprehensive logging for debugging
- Use consistent IPC patterns for communication between main and renderer processes
- Use
setImmediateyields when sending IPC messages in loops to allow event loop processing
Debugging
- Built-in debugging utilities for problematic files
- Console logging for development and debugging
- Error messages include context information
- Implement debug logging with timestamps via
writeLog()function - Use structured logging for better debugging experience
- Audit logs written to
.auditfiles in each directory
Environment Configuration
- API keys stored in
.envfile - Environment variables should be validated on application startup
- Provide clear error messages when environment variables are missing
- Use
dotenvpackage for loading environment variables
Key Features Implementation
File Tagging System
- Files can be tagged as "extra" or "commentary"
- Tags stored as data attributes on DOM elements:
data-tagged-extra,data-tagged-commentary - Visual feedback with color changes and glow effects when tagged
- Play button enables only when file is tagged
- Individual play button moves single file
- Floating action button (FAB) moves all tagged files at once
Folder Navigation
- Non-recursive scanning shows only current directory contents
- Folders displayed with 📁 icon at top of list
- Clicking folder navigates into it and rescans
openDirectory(path)function handles navigation
Progress Indication
- Spinner with file count shown during directory scanning
- Progress container hidden when not scanning
- IPC event
scan-progresssends updates from main to renderer setImmediateyields ensure UI updates during processing
File Movement
- Files tagged "extra" move to "extras" folder (Jellyfin compatible)
- Files tagged "commentary" move to "commentary" folder
- Target folders created automatically if they don't exist
- Audit log entry written for each move operation
- Files removed from UI after successful move
Recent Changes (Session 2026-02-22)
Bug Fixes
- Fixed duplicate
moveTaggedFilefunction - Two definitions were overwriting each other - Fixed missing click handler for FAB - Added
moveAllTaggedFiles()on floating circle click - Fixed "extra" vs "extras" folder naming - Now correctly uses "extras" for Jellyfin
- Fixed progressBar reference error - Removed reference after switching to spinner
- Removed non-existent test-api-btn reference - Was causing errors on load
New Features
- Folder navigation - Click folders to navigate into them
- Non-recursive scanning - Only shows current directory contents
- Progress spinner - Shows file being processed with count
- Batch file moving - FAB moves all tagged files at once
- Visual feedback - FAB turns yellow while processing
UI Improvements
- Dark theme - Modern dark color scheme (#1a1a2e, #16213e, #0f3460)
- Clean layout - Search/shows on left sidebar, files on right
- Accent color - Pink/red accent (#e94560)
- Better typography - System font stack
- Smooth animations - Hover effects and transitions
Jellyfin Compatible Folder Names
Extras Folders (place inside movie/show folder)
behind the scenes- Behind-the-scenes contentdeleted scenes- Deleted scenesinterviews- Cast/crew interviewsscenes- Individual scenessamples- Sample clipsshorts- Short filmsfeaturettes- Featurettesclips- Clipsother- Generic catch-all for unknown extrasextras- Generic catch-all for unknown extras (CURRENTLY IMPLEMENTED)trailers- Trailers and previewstheme-music- Theme music audio filesbackdrops- Backdrop videos
Special Single-File Names (in same folder as media)
trailer- Single trailer filesample- Single sample filetheme- Theme song audio file
File Suffix Options (append to filename)
-trailer,.trailer,_trailer,trailer-sample,.sample,_sample,sample-scene,-clip,-interview-behindthescenes,-deleted,-deletedscene-featurette,-short,-other,-extra
Known Issues & Future Work
Known Issues
- Progress spinner updates may be delayed due to IPC buffering
- No "go back" / parent directory navigation yet
- Tag state is lost on directory change (not persisted)
Suggested Improvements
- Add parent directory navigation ("..") or breadcrumb
- Persist tag state to avoid accidental loss
- Add more Jellyfin folder type options (trailers, featurettes, etc.)
- Add file renaming with episode matching from TVDB
- Add batch rename functionality
- Consider adding undo for file moves
- Add confirmation dialog before moving files
Execution Constraints
- All commands that might block indefinitely must be run with a timeout
- Example:
timeout 30 npm startto run the application with 30-second timeout - Always run syntax checks after modifying JS files:
node --check <file>