refactor: Restructure downloaders with clear separation

This commit implements a complete reorganization of the downloader system
with a clear distinction between anime streaming sites and video hosting services.

## Structure Changes

**New Organization:**
- `app/downloaders/anime_sites/` - Anime streaming sites (catalogs + metadata)
- `app/downloaders/video_players/` - Video hosting services (file downloads)

**Base Classes:**
- `BaseAnimeSite` - For anime providers (search, episodes, metadata)
- `BaseVideoPlayer` - For video players (download link extraction)

**Migrated Downloaders:**
Anime Sites (4):
- AnimeSama, NekoSama, AnimeUltime, Vostfree

Video Players (8):
- Doodstream, Sibnet, VidMoly, SendVid, Lpayer, 1fichier, Uptobox, Rapidfile

## Key Improvements

1. **Clear Separation**: Distinct base classes for different use cases
2. **Preserved Functionality**: All existing features maintained
   - VidMoly: M3U8 support, Playwright, multi-domains, target_filename param
   - SendVid: target_filename parameter support
   - All others: No behavioral changes

3. **Better Organization**:
   - Anime sites: search_anime(), get_episodes(), get_anime_metadata()
   - Video players: get_download_link(url, target_filename=None)

4. **Fixed Imports**: Updated cross-imports in AnimeSama
   - from ..video_players.vidmoly import
   - from ..video_players.sendvid import
   - from ..video_players.sibnet import
   - from ..video_players.lpayer import

5. **Updated Tests**: All test imports use new structure
6. **Updated Providers**: Added 4 missing file hosts to providers.py

## Backward Compatibility

 Main API unchanged: get_downloader() works identically
 All 23 tests passing
 Frontend fully functional
 No breaking changes for users

## Documentation

- RESTRUCTURATION_SUMMARY.md - Technical details
- FIX_IMPORT_ERROR.md - Import error resolution
- IMPORT_VERIFICATION_REPORT.md - Complete import verification
- FRONTEND_VERIFICATION_FINAL.md - Frontend validation

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
root
2026-01-24 22:13:20 +00:00
parent 1fe7392063
commit 3afad41d46
25 changed files with 1001 additions and 83 deletions
+83 -7
View File
@@ -69,13 +69,16 @@ Ohm_streaming/
│ │ ├── vostfree.py # Vostfree (anime provider)
│ │ └── __init__.py # Factory function and registry
│ ├── providers.py # Provider configuration (domains, icons, colors)
│ ├── config.py # Environment-based configuration (Pydantic Settings)
│ ├── utils.py # Security utilities (sanitize_filename, is_safe_filename)
│ ├── download_manager.py # Manages download queue, progress, parallel downloads
│ ├── favorites.py # Favorites management system (JSON-based)
│ ├── recommendation_engine.py # Analyzes download history for recommendations
│ ├── recommendation_engine.py # Analyzes download history for personalized recommendations
│ ├── recommendations.py # Fetches latest releases from anime sources
│ ├── kitsu_api.py # Kitsu API integration for metadata
│ ├── kitsu_api.py # Kitsu API integration for anime metadata
│ ├── sonarr_handler.py # Sonarr webhook integration handler
│ └── models/
│ ├── __init__.py # Core models (DownloadTask, AnimeMetadata, etc.)
│ └── sonarr.py # Sonarr Pydantic models
├── downloads/ # Downloaded files storage
├── templates/
@@ -88,6 +91,11 @@ Ohm_streaming/
**Core Components:**
### 0. Configuration (`app/config.py`)
- `Settings` class using Pydantic Settings for environment-based configuration
- Loads from `.env` file with sensible defaults
- Provides `get_settings()` function for accessing configuration globally
### 1. DownloadManager (`app/download_manager.py`)
- Manages all download tasks with parallel download limit (default: 3 concurrent)
- Handles pause/resume/cancel operations
@@ -171,6 +179,42 @@ Ohm_streaming/
- Video player with seeking support (HTTP Range headers)
- Dark theme with gradients and animations
### 6. Security Utilities (`app/utils.py`)
- `sanitize_filename(filename, max_length=255)` - Sanitize filenames to prevent path traversal
- Removes dangerous characters: `\ / : * ? " < > |`
- Strips path separators and leading dots/dashes
- Limits filename length while preserving extension
- `is_safe_filename(filename)` - Validate filename safety
- Checks for path traversal patterns (`..`, `/`, `\`)
- Detects absolute paths and drive letters
- Used throughout the codebase for file operations
### 7. Recommendation Engine (`app/recommendation_engine.py`)
- Analyzes download history to generate personalized recommendations
- Tracks genre preferences and viewing patterns
- Scores anime based on user's download history
- Used by `/api/recommendations` endpoint
### 8. Kitsu API (`app/kitsu_api.py`)
- Integrates with Kitsu anime database for metadata
- Fetches anime information by title or ID
- Provides enriched metadata (synopsis, genres, ratings, poster images)
- Used as fallback when provider metadata is incomplete
### 9. Pydantic Models (`app/models/`)
- **`__init__.py`** - Core models:
- `DownloadStatus` - Enum for task states (PENDING, DOWNLOADING, PAUSED, COMPLETED, FAILED, CANCELLED)
- `HostType` - Enum for file host types (RAPIDFILE, UNFICHIER, DOODSTREAM, OTHER)
- `DownloadTask` - Main task model with progress tracking
- `DownloadRequest` - Request model for creating downloads
- `AnimeMetadata` - Anime information (synopsis, genres, rating, release_year, studio, etc.)
- `AnimeSearchResult` - Enhanced search result with metadata
- **`sonarr.py`** - Sonarr-specific models:
- `SonarrWebhookPayload` - Complete webhook payload schema
- `SonarrEventType` - Enum for event types (Grab, Download, Rename, Delete, Test)
- `SonarrMapping` - Mapping between Sonarr series and anime providers
- `SonarrConfig` - Webhook configuration (enabled, secret, auto-download, etc.)
## Test Structure
**Test Organization (tests/):**
@@ -180,7 +224,10 @@ Ohm_streaming/
- `test_download_manager.py` - DownloadManager tests
- `test_favorites.py` - Favorites system tests
- `test_api.py` - FastAPI endpoint tests
- `test_sonarr.py` - Sonarr integration tests (23 tests, all passing)
- `test_sonarr.py` - Sonarr integration tests
- `test_anime_sama_seasons.py` - Anime-Sama season handling tests
- `test_translate_api.py` - Translation API tests
- `test_delete_and_restore.py` - Delete and restore functionality tests
**Fixtures in conftest.py:**
- `temp_dir` - Temporary directory
@@ -198,6 +245,14 @@ Ohm_streaming/
- `slow` - Slow tests - manual
- `network` - Requires network - manual
**pytest.ini Configuration:**
- Auto-applies markers for async and integration tests
- Coverage enabled by default (`--cov=app`)
- HTML coverage report generated in `htmlcov/`
- Verbose output with local variables in tracebacks
- 300-second timeout for tests
- `asyncio_mode = auto` for async test support
**Running Single Test:**
```bash
# Run specific test file
@@ -240,7 +295,10 @@ class MyHostDownloader(BaseDownloader):
await self.client.aclose()
```
**Important:** Always close the HTTP client in your downloader to avoid resource leaks.
**Important:**
- Always close the HTTP client in your downloader to avoid resource leaks
- Use `sanitize_filename()` from `app.utils` when extracting filenames from URLs
- Use `is_safe_filename()` to validate filenames before file operations
## Sonarr Integration
@@ -332,11 +390,29 @@ Metadata should include:
## Configuration
Edit `main.py` to configure:
- `max_parallel` - Maximum concurrent downloads (default: 3)
- `download_dir` - Storage location (default: "downloads")
The application uses environment variables for configuration via `app/config.py` (Pydantic Settings).
**Environment Variables (.env):**
```bash
# Copy the example file
cp .env.example .env
# Edit .env to configure:
APP_NAME=Ohm Stream Downloader # Application name
DEBUG=false # Debug mode
HOST=0.0.0.0 # Server host
PORT=3000 # Server port
DOWNLOAD_DIR=downloads # Download storage location
MAX_PARALLEL_DOWNLOADS=3 # Maximum concurrent downloads
CHUNK_SIZE=1048576 # Download chunk size (1MB)
CORS_ORIGINS=... # Comma-separated allowed origins
HTTP_TIMEOUT=10.0 # HTTP request timeout (seconds)
DOWNLOAD_TIMEOUT=300 # Download timeout (seconds)
LOG_LEVEL=INFO # Logging level
```
**Configuration Files:**
- `.env` - Environment configuration (create from .env.example)
- `config/sonarr.json` - Sonarr webhook configuration (created automatically)
- `config/sonarr_mappings.json` - Sonarr to anime provider mappings (created automatically)
- `config/.gitkeep` - Ensures config directory is tracked in git