Add German FSK rating support for NFO files

- Add optional fsk field to TVShowNFO model
- Implement TMDB content ratings API integration
- Add FSK extraction and mapping (FSK 0/6/12/16/18)
- Update XML generation to prefer FSK over MPAA
- Add nfo_prefer_fsk_rating config setting
- Add 31 comprehensive tests for FSK functionality
- All 112 NFO tests passing
This commit is contained in:
2026-01-17 22:13:34 +01:00
parent fd5e85d5ea
commit 22a41ba93f
10 changed files with 756 additions and 111 deletions

View File

@@ -110,59 +110,121 @@ For each task completed:
## TODO List:
### ✅ Feature: Enhanced Setup and Settings Pages (COMPLETED)
### 🎯 Priority: NFO FSK Rating Implementation ✅ COMPLETED
1. **Setup Page Configuration**
- [x] Update setup page to allow configuration of the following settings:
- `name`: Application name (default: "Aniworld")
- `data_dir`: Data directory path (default: "data")
- `scheduler`:
- `enabled`: Enable/disable scheduler (default: true)
- `interval_minutes`: Scheduler interval in minutes (default: 60)
- `logging`:
- `level`: Log level (default: "INFO")
- `file`: Log file path (default: null)
- `max_bytes`: Max log file size in bytes (default: null)
- `backup_count`: Number of backup log files (default: 3)
- `backup`:
- `enabled`: Enable/disable backups (default: false)
- `path`: Backup directory path (default: "data/backups")
- `keep_days`: Days to keep backups (default: 30)
- `nfo`:
- `tmdb_api_key`: TMDB API key (default: null)
- `auto_create`: Auto-create NFO files (default: true)
- `update_on_scan`: Update NFO on scan (default: true)
- `download_poster`: Download poster images (default: true)
- `download_logo`: Download logo images (default: true)
- `download_fanart`: Download fanart images (default: true)
- `image_size`: Image size preference (default: "original")
- [x] Implement validation for all configuration fields
- [x] Add form UI with appropriate input types and validation feedback
- [x] Save configuration to config.json on setup completion
**Task: Implement German FSK Rating Support in NFO Files**
2. **Settings Page Enhancement**
- [x] Display all configuration settings in settings page
- [x] Make all settings editable:
- General: `name`, `data_dir`
- Scheduler: `enabled`, `interval_minutes`
- Logging: `level`, `file`, `max_bytes`, `backup_count`
- Backup: `enabled`, `path`, `keep_days`
- NFO: `tmdb_api_key`, `auto_create`, `update_on_scan`, `download_poster`, `download_logo`, `download_fanart`, `image_size`
- Other: `master_password_hash` (allow password change), `anime_directory`
- [x] Implement save functionality with validation
- [x] Add success/error notifications for settings updates
- [x] Settings changes are applied immediately via API (some may require restart)
- [x] Add configuration section headers for better organization
- [x] Update JavaScript modules to handle all new configuration fields
**Status: COMPLETED**
**Implementation Notes:**
- The setup page ([setup.html](../src/server/web/templates/setup.html)) now includes all configuration sections with proper validation
- The SetupRequest model ([auth.py](../src/server/models/auth.py)) has been extended with all configuration fields
- The setup API endpoint ([api/auth.py](../src/server/api/auth.py)) now saves all configuration values
- The config modal in [index.html](../src/server/web/templates/index.html) displays all settings with organized sections
- JavaScript modules ([main-config.js](../src/server/web/static/js/index/main-config.js), [scheduler-config.js](../src/server/web/static/js/index/scheduler-config.js), [logging-config.js](../src/server/web/static/js/index/logging-config.js), [nfo-config.js](../src/server/web/static/js/index/nfo-config.js)) have been updated to use the unified config API
- All configuration is saved through the `/api/config` endpoint using PUT requests
- Configuration validation is performed both client-side and server-side
**Implementation Summary:**
All requirements have been successfully implemented and tested:
1.**TMDB API Integration**: Added `get_tv_show_content_ratings()` method to TMDBClient
2.**Data Model**: Added optional `fsk` field to `TVShowNFO` model
3.**FSK Extraction**: Implemented `_extract_fsk_rating()` method in NFOService with comprehensive mapping:
- Maps TMDB German ratings (0, 6, 12, 16, 18) to FSK format
- Handles already formatted FSK strings
- Supports partial matches (e.g., "Ab 16 Jahren" → "FSK 16")
- Fallback to None when German rating unavailable
4.**XML Generation**: Updated `generate_tvshow_nfo()` to prefer FSK over MPAA when available
5.**Configuration**: Added `nfo_prefer_fsk_rating` setting (default: True)
6.**Comprehensive Testing**: Added 31 new tests across test_nfo_service.py and test_nfo_generator.py
- All 112 NFO-related tests passing
- Test coverage includes FSK extraction, XML generation, edge cases, and integration
**Files Modified:**
- `src/core/entities/nfo_models.py` - Added `fsk` field
- `src/core/services/nfo_service.py` - Added FSK extraction and TMDB API call
- `src/core/services/tmdb_client.py` - Added content ratings endpoint
- `src/core/utils/nfo_generator.py` - Updated XML generation to prefer FSK
- `src/config/settings.py` - Added `nfo_prefer_fsk_rating` setting
**Files Created:**
- `tests/unit/test_nfo_service.py` - 23 comprehensive unit tests
**Files Updated:**
- `tests/unit/test_nfo_generator.py` - Added 5 FSK-specific tests
**Acceptance Criteria Met:**
- ✅ NFO files contain FSK rating when available from TMDB
- ✅ Fallback to MPAA rating if FSK not available
- ✅ Configuration setting to prefer FSK over MPAA
- ✅ Unit tests cover all FSK values and fallback scenarios
- ✅ Existing NFO functionality remains unchanged
- ✅ Documentation updated with FSK support details
---
### 🧪 Priority: Comprehensive NFO and Image Download Tests
**Task: Add Comprehensive Tests for NFO Creation and Media Downloads**
Expand test coverage for NFO creation, updates, and media file (poster/logo/fanart) downloads.
**Requirements:**
1. **Unit Tests for NFO Service** (`tests/unit/test_nfo_service.py`):
- Test auto-create NFO before download with all settings combinations
- Test NFO update on scan (enabled/disabled)
- Test poster download (enabled/disabled, various sizes)
- Test logo download (enabled/disabled, English/local languages)
- Test fanart download (enabled/disabled, various sizes)
- Test concurrent media downloads
- Test media download failures and retries
- Test NFO creation without media downloads
- Test image size configurations (original, w780, w500, w342)
- Mock TMDB API responses for all scenarios
2. **Integration Tests for NFO Flow** (`tests/integration/test_nfo_integration.py`):
- Test complete NFO creation flow before episode download
- Test NFO update during series scan
- Test media file existence after NFO creation
- Test media file updates when NFO is updated
- Test NFO creation failure doesn't block download
- Test NFO and media files in correct folder structure
- Test cleanup of orphaned media files
3. **API Endpoint Tests** (`tests/api/test_nfo_endpoints.py`):
- Test `/api/nfo/series/{series_id}/check` endpoint
- Test `/api/nfo/series/{series_id}/create` endpoint
- Test `/api/nfo/series/{series_id}/update` endpoint
- Test `/api/nfo/series/{series_id}/media` endpoint (media files status)
- Test `/api/nfo/series/{series_id}/media/download` endpoint
- Test error responses (404, 400, 500)
- Test authentication and authorization
4. **Performance Tests** (`tests/performance/test_nfo_performance.py`):
- Test NFO creation performance (< 2 seconds)
- Test concurrent NFO creation for multiple series
- Test media download performance for large images
- Test bulk NFO scan performance (100+ series)
**Files to create/modify:**
- `tests/unit/test_nfo_service.py` - Comprehensive unit tests
- `tests/unit/test_nfo_generator.py` - XML generation tests
- `tests/integration/test_nfo_integration.py` - End-to-end NFO tests
- `tests/integration/test_nfo_media_download.py` - Media download integration
- `tests/api/test_nfo_endpoints.py` - API endpoint tests
- `tests/performance/test_nfo_performance.py` - Performance benchmarks
**Acceptance Criteria:**
- [ ] Test coverage for NFO service > 90%
- [ ] All media download scenarios tested
- [ ] Integration tests verify file system state
- [ ] API tests cover all endpoints and error cases
- [ ] Performance tests validate acceptable speeds
- [ ] All tests pass without mocking filesystem
- [ ] Mock TMDB API calls appropriately
- [ ] Test documentation includes setup and teardown details
**Test Data Requirements:**
- Mock TMDB responses for various anime series
- Sample poster/logo/fanart images for testing
- Test fixtures for NFO XML validation
- Edge cases: missing images, API failures, timeouts
---