67 Commits

Author SHA1 Message Date
2a85a2bc18 Fix permission error when copying files to network directory
- Replace shutil.copy2() with shutil.copyfile() in enhanced_provider.py
- Replace shutil.copy() with shutil.copyfile() in aniworld_provider.py
- copyfile() only copies content, avoiding metadata permission issues
2026-01-09 19:18:57 +01:00
bd655cb0f0 Fix event initialization issues
- Remove None assignment for download_progress event in AniworldLoader
- Remove None assignments for download_status and scan_status events in SeriesApp
- Events library requires events to not be initialized to None
- Verified logging configuration is properly set to INFO level
2026-01-07 19:39:42 +01:00
f39a08d985 Fix event handler TypeError and increase log level to INFO 2026-01-07 19:18:01 +01:00
055bbf4de6 Fix event subscription bug in SerieScanner and mark checklist complete 2026-01-07 19:01:42 +01:00
ab7d78261e Replace asyncio.to_thread with ThreadPoolExecutor.run_in_executor
- Add ThreadPoolExecutor with 3 max workers to SeriesApp
- Replace all asyncio.to_thread calls with loop.run_in_executor
- Add shutdown() method to properly cleanup executor
- Integrate SeriesApp.shutdown() into FastAPI shutdown sequence
- Ensures proper resource cleanup on Ctrl+C (SIGINT/SIGTERM)
2026-01-03 21:04:52 +01:00
b1726968e5 Refactor: Replace CallbackManager with Events pattern
- Replace callback system with events library in SerieScanner
- Update SeriesApp to subscribe to loader and scanner events
- Refactor ScanService to use Events instead of CallbackManager
- Remove CallbackManager imports and callback classes
- Add safe event calling with error handling in SerieScanner
- Update AniworldLoader to use Events for download progress
- Remove progress_callback parameter from download methods
- Update all affected tests for Events pattern
- Fix test_series_app.py for new event subscription model
- Comment out obsolete callback tests in test_scan_service.py

All core tests passing. Events provide cleaner event-driven architecture.
2025-12-30 21:04:45 +01:00
ff9dea0488 removed cancel request 2025-12-30 20:36:02 +01:00
4780f68a23 Fix: Use yt_dlp.utils.DownloadCancelled for proper download cancellation
- Import and use DownloadCancelled exception which YT-DLP properly handles
- Add InterruptedError handling throughout the call chain
- Fire 'cancelled' status event when download is cancelled
- Handle InterruptedError in DownloadService to set CANCELLED status
2025-12-27 19:38:12 +01:00
08f816a954 Fix: Add graceful download cancellation on Ctrl+C
- Add cancellation flag to AniworldLoader with request_cancel/reset_cancel/is_cancelled methods
- Update base_provider.Loader interface with cancellation abstract methods
- Integrate cancellation check in YT-DLP progress hooks
- Add request_download_cancel method to SeriesApp and AnimeService
- Update DownloadService.stop() to request cancellation before shutdown
- Clean up temp files on cancellation
2025-12-27 19:31:57 +01:00
1b7ca7b4da feat: Enhanced anime add flow with sanitized folders and targeted scan
- Add sanitize_folder_name utility for filesystem-safe folder names
- Add sanitized_folder property to Serie entity
- Update SerieList.add() to use sanitized display names for folders
- Add scan_single_series() method for targeted episode scanning
- Enhance add_series endpoint: DB save -> folder create -> targeted scan
- Update response to include missing_episodes and total_missing
- Add comprehensive unit tests for new functionality
- Update API tests with proper mock support
2025-12-26 12:49:23 +01:00
72ac201153 Show total items to scan in progress overlay
- Add total_items parameter to broadcast_scan_started and broadcast_scan_progress
- Pass total from SeriesApp to WebSocket broadcasts in AnimeService
- Update JS overlay to show progress bar and current/total count
- Add CSS for progress bar styling
- Add unit tests for new total_items parameter
- All 1024 tests passing
2025-12-24 20:54:27 +01:00
32dc893434 cleanup 2025-12-16 19:22:16 +01:00
596476f9ac refactor: remove database access from core layer
- Remove db_session parameter from SeriesApp, SerieList, SerieScanner
- Move all database operations to AnimeService (service layer)
- Add add_series_to_db, contains_in_db methods to AnimeService
- Update sync_series_from_data_files to use inline DB operations
- Remove obsolete test classes for removed DB methods
- Fix pylint issues: add broad-except comments, fix line lengths
- Core layer (src/core/) now has zero database imports

722 unit tests pass
2025-12-15 15:19:03 +01:00
1652f2f6af feat: rescan now saves to database instead of data files
- Update SeriesApp.rescan() to use database storage by default (use_database=True)
- Use SerieScanner.scan_async() for database mode, which saves directly to DB
- Fall back to legacy file-based scan() when use_database=False (for CLI compatibility)
- Reinitialize SerieList from database after scan when in database mode
- Update unit tests to use use_database=False for mocked tests
- Add parameter to control storage mode for backward compatibility
2025-12-13 20:37:03 +01:00
684337fd0c Add data file to database sync functionality
- Add get_all_series_from_data_files() to SeriesApp
- Sync series from data files to DB on startup
- Add unit tests for new SeriesApp method
- Add integration tests for sync functionality
- Update documentation
2025-12-13 09:32:57 +01:00
798461a1ea better db model 2025-12-04 19:22:42 +01:00
e0a7c6baa9 some fixes 2025-12-02 13:24:22 +01:00
396b243d59 chore: Add deprecation warnings and update documentation (Task 9)
Task 9: Clean up legacy code
- Added deprecation warnings to Serie.save_to_file() and load_from_file()
- Updated infrastructure.md with Data Storage section documenting:
  - SQLite database as primary storage
  - Legacy file storage as deprecated
  - Data migration process
- Added deprecation warning tests for Serie class
- Updated existing tests to handle new warnings
- All 1012 tests pass (872 unit + 55 API + 85 integration)
2025-12-01 19:55:15 +01:00
cb014cf547 feat(core): Add database support to SeriesApp (Task 7)
- Added db_session parameter to SeriesApp.__init__()
- Added db_session property and set_db_session() method
- Added init_from_db_async() for async database initialization
- Pass db_session to SerieList and SerieScanner during construction
- Added get_series_app_with_db() dependency for FastAPI endpoints
- All 815 unit tests and 55 API tests pass
2025-12-01 19:42:04 +01:00
46ca4c9aac Task 5: Update SerieScanner to use database storage
- Add db_session parameter to SerieScanner.__init__
- Add async scan_async() method for database-backed scanning
- Add _save_serie_to_db() helper for creating/updating series
- Add _update_serie_in_db() helper for updating existing series
- Add deprecation warning to file-based scan() method
- Maintain backward compatibility for CLI usage
- Add comprehensive unit tests (15 tests, all passing)
- Update instructions.md to mark Task 5 complete
2025-12-01 19:25:28 +01:00
795f83ada5 Task 4: Update SerieList to use database storage
- Add db_session and skip_load parameters to SerieList.__init__
- Add async load_series_from_db() method for database loading
- Add async add_to_db() method for database storage
- Add async contains_in_db() method for database checks
- Add _convert_from_db() and _convert_to_db_dict() helper methods
- Add deprecation warnings to file-based add() method
- Maintain backward compatibility for file-based operations
- Add comprehensive unit tests (29 tests, all passing)
- Update instructions.md to mark Task 4 complete
2025-12-01 19:18:50 +01:00
85a6b053eb Phase 8: Documentation and deprecation warnings for identifier standardization
- Enhanced infrastructure.md with identifier convention table, format requirements, migration notes
- Updated docs/README.md with series identifier convention section
- Updated docs/api_reference.md with key-based API examples and notes
- Added deprecation warnings to SerieList.get_by_folder()
- Added deprecation warnings to anime.py folder fallback lookup
- Added deprecation warnings to validate_series_key_or_folder()
- All warnings include v3.0.0 removal timeline
- All 1006 tests pass
2025-11-28 18:06:04 +01:00
883f89b113 Add series key metadata to callback contexts 2025-11-23 20:02:11 +01:00
5c08bac248 style: reorder imports in SeriesApp.py
Minor formatting change - imports reordered alphabetically
2025-11-23 19:54:19 +01:00
8443de4e0f feat(core): standardize SeriesApp to use key as primary identifier
Task 2.1 - Update SeriesApp to Use Key for All Operations

Changes:
- Added 'key' field to DownloadStatusEventArgs and ScanStatusEventArgs
- Updated download() method docstrings to clarify key vs folder usage
- Implemented _get_serie_by_key() helper method for series lookups
- Updated all event emissions to include both key (identifier) and folder (metadata)
- Enhanced logging to show both key and folder for better debugging
- Fixed test mocks to include new key and item_id fields

Benefits:
- Consistent series identification throughout core application layer
- Clear separation between identifier (key) and metadata (folder)
- Better debugging with comprehensive log messages
- Type-safe lookups with Optional[Serie] return types
- Single source of truth for series lookups

Test Results:
- All 16 SeriesApp tests pass
- All 562 unit tests pass with no regressions
- No breaking changes to existing functionality

Follows:
- PEP 8 style guidelines (max 79 chars per line)
- PEP 257 docstring standards
- Project coding standards (type hints, error handling, logging)
2025-11-23 19:51:26 +01:00
51cd319a24 Task 1.5: Update Provider Factory documentation for key usage
- Added comprehensive module-level docstring explaining provider vs series keys
- Enhanced Loaders class docstring with purpose and attributes documentation
- Added detailed docstring to GetLoader() method with Args/Returns/Raises sections
- Added type hints: Dict[str, Loader] for self.dict and -> None for __init__
- Clarified distinction between provider keys (e.g., 'aniworld.to') and series keys
- No functional changes - existing implementation already correct
- All 34 provider tests pass
- All 16 SeriesApp tests pass
- Updated instructions.md to mark Task 1.5 as completed
- Follows PEP 8 and PEP 257 standards
2025-11-23 19:45:22 +01:00
c4ec6c9f0e Task 1.1: Fix PEP 8 compliance in Serie class
- Fixed line length issues (max 79 chars)
- Added UTF-8 encoding to file operations
- Fixed blank line formatting
- Improved code formatting in __str__, to_dict, from_dict methods
- All docstrings now comply with PEP 8
- All 16 Serie class tests pass
- All 5 anime model tests pass
- No functional changes, only style improvements
2025-11-23 19:38:26 +01:00
aeb1ebe7a2 Task 1.4: Update provider classes to use key as primary identifier
- Enhanced download() method docstring in aniworld_provider.py
- Enhanced Download() method docstring in enhanced_provider.py
- Clarified that 'key' is the series unique identifier from provider
- Clarified that 'serie_folder'/'serieFolder' is filesystem folder name (metadata only)
- Added comprehensive Args, Returns, and Raises sections to docstrings
- Fixed PEP 8 line length issue in logging statement
- Verified existing code already uses 'key' for identification and logging
- All 34 provider-related tests pass successfully
- No functional changes required, documentation improvements only
2025-11-23 17:51:32 +01:00
920a5b0eaf feat(core): Standardize SerieScanner to use 'key' as primary identifier
Task 1.3: Update SerieScanner to Use Key Consistently

Changes:
- Renamed self.folderDict to self.keyDict for clarity and consistency
- Updated internal storage to use serie.key as dictionary key
- Modified scan() method to store series by key
- Enhanced logging to show both key (identifier) and folder (metadata)
- Added debug logging when storing series
- Updated error contexts to include both key and folder in metadata
- Updated completion statistics to use keyDict
- Enhanced docstrings to clarify identifier vs metadata usage
- Fixed import formatting to comply with PEP 8 line length

Success criteria met:
 Scanner stores series by 'key'
 Progress callbacks use 'key' for identification
 Error messages reference both 'key' and 'folder' appropriately
 All 554 unit tests pass

Related to: Series Identifier Standardization (Phase 1, Task 1.3)
2025-11-23 13:06:33 +01:00
8b5b06ca9a feat: Standardize SerieList to use key as primary identifier (Task 1.2)
- Renamed folderDict to keyDict for clarity
- Updated internal storage to use serie.key instead of serie.folder
- Optimized contains() from O(n) to O(1) with direct key lookup
- Added get_by_key() as primary lookup method
- Added get_by_folder() for backward compatibility
- Enhanced docstrings to clarify key vs folder usage
- Created comprehensive test suite (12 tests, all passing)
- Verified no breaking changes (16 SeriesApp tests pass)

This establishes key as the single source of truth for series
identification while maintaining folder as metadata for filesystem
operations only.
2025-11-23 12:25:08 +01:00
048434d49c feat: Task 1.1 - Enforce key as primary identifier in Serie class
- Add validation in Serie.__init__ to prevent empty/whitespace keys
- Add validation in Serie.key setter to prevent empty values
- Automatically strip whitespace from key values
- Add comprehensive docstrings explaining key as unique identifier
- Document folder property as metadata only (not for lookups)
- Create comprehensive test suite with 16 tests in test_serie_class.py
- All 56 Serie-related tests pass successfully
- Update instructions.md to mark Task 1.1 as completed

This is the first task in the Series Identifier Standardization effort
to establish 'key' as the single source of truth for series identification
throughout the codebase.
2025-11-23 12:12:58 +01:00
029abb9be2 fix: progress part 1. percentage is working 2025-11-20 19:21:01 +01:00
57da1f1272 fix: download status 2025-11-20 19:02:04 +01:00
ec987eff80 chore: make sure that there is only one app 2025-11-02 15:14:34 +01:00
e414a1a358 refactored callback 2025-11-02 10:34:49 +01:00
8a49db2a10 rework of SeriesApp.py 2025-11-02 10:20:10 +01:00
2de3317aee refactoring backup 2025-11-02 09:52:43 +01:00
d5f7b1598f use of websockets 2025-11-01 19:23:32 +01:00
57c30a0156 call back logs 2025-11-01 19:03:30 +01:00
9fce617949 fix percentage 2025-11-01 18:46:53 +01:00
b76ffbf656 fixed percentage and mb/s view 2025-11-01 16:49:12 +01:00
f0b9d50f85 fix not downloading 2025-11-01 16:43:05 +01:00
6cdb2eb1e1 added logging 2025-11-01 16:29:07 +01:00
a41c86f1da refactor: remove GlobalLogger and migrate to standard Python logging
- Remove src/infrastructure/logging/GlobalLogger.py
- Update SerieScanner.py to use standard logging.getLogger()
- Update aniworld_provider.py to remove custom noKeyFound_logger setup
- Fix test_dependencies.py to properly mock config_service
- Fix code style issues (line length, formatting)
- All 846 tests passing
2025-10-25 17:27:49 +02:00
fecdb38a90 feat: Add comprehensive provider health monitoring and failover system
- Implemented ProviderHealthMonitor for real-time tracking
  - Monitors availability, response times, success rates
  - Automatic marking unavailable after failures
  - Background health check loop

- Added ProviderFailover for automatic provider switching
  - Configurable retry attempts with exponential backoff
  - Integration with health monitoring
  - Smart provider selection

- Created MonitoredProviderWrapper for performance tracking
  - Transparent monitoring for any provider
  - Automatic metric recording
  - No changes needed to existing providers

- Implemented ProviderConfigManager for dynamic configuration
  - Runtime updates without restart
  - Per-provider settings (timeout, retries, bandwidth)
  - JSON-based persistence

- Added Provider Management API (15+ endpoints)
  - Health monitoring endpoints
  - Configuration management
  - Failover control

- Comprehensive testing (34 tests, 100% pass rate)
  - Health monitoring tests
  - Failover scenario tests
  - Configuration management tests

- Documentation updates
  - Updated infrastructure.md
  - Updated instructions.md
  - Created PROVIDER_ENHANCEMENT_SUMMARY.md

Total: ~2,593 lines of code, 34 passing tests
2025-10-24 11:01:40 +02:00
ffb182e3ba cleanup 2025-10-23 19:41:24 +02:00
c81a493fb1 cleanup 2025-10-23 19:00:49 +02:00
3d5c19939c cleanup 2025-10-23 18:28:17 +02:00
9a64ca5b01 cleanup 2025-10-23 18:10:34 +02:00
5c2691b070 cleanup 2025-10-22 17:39:28 +02:00