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:
@@ -0,0 +1,85 @@
|
||||
"""Base class for video hosting services (players)"""
|
||||
from abc import abstractmethod
|
||||
from typing import Optional, Tuple
|
||||
import logging
|
||||
import httpx
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class BaseVideoPlayer:
|
||||
"""
|
||||
Base class for video hosting services.
|
||||
|
||||
Video players host actual video files and provide direct download links.
|
||||
They extract URLs from embedded players and handle file downloads.
|
||||
|
||||
Examples: Doodstream, Sibnet, VidMoly, SendVid, Lpayer, 1fichier, etc.
|
||||
|
||||
KEY FEATURE: Flexible get_download_link() signature to support:
|
||||
- Standard: get_download_link(url)
|
||||
- With target_filename: get_download_link(url, target_filename="...") (VidMoly, SendVid)
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
# Initialize HTTP client directly
|
||||
self.client = httpx.AsyncClient(timeout=10.0, follow_redirects=True)
|
||||
|
||||
@abstractmethod
|
||||
def can_handle(self, url: str) -> bool:
|
||||
"""Check if this player can handle the given URL"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def get_download_link(
|
||||
self,
|
||||
url: str,
|
||||
target_filename: Optional[str] = None
|
||||
) -> Tuple[str, str]:
|
||||
"""
|
||||
Extract direct download link and filename from video player URL.
|
||||
|
||||
Args:
|
||||
url: The video player URL
|
||||
target_filename: Optional filename override (used by VidMoly, SendVid)
|
||||
|
||||
Returns:
|
||||
Tuple of (download_url, filename)
|
||||
|
||||
Note:
|
||||
- Always use sanitize_filename() on extracted filenames!
|
||||
- target_filename parameter is optional but MUST be supported
|
||||
for compatibility with VidMoly and SendVid
|
||||
"""
|
||||
pass
|
||||
|
||||
# Common methods for all video players
|
||||
async def close(self):
|
||||
"""Close HTTP client"""
|
||||
await self.client.aclose()
|
||||
|
||||
async def _fetch_page(self, url: str) -> str:
|
||||
"""Fetch HTML page content"""
|
||||
response = await self.client.get(url)
|
||||
response.raise_for_status()
|
||||
return response.text
|
||||
|
||||
def _parse_html(self, html: str) -> BeautifulSoup:
|
||||
"""Parse HTML with BeautifulSoup"""
|
||||
return BeautifulSoup(html, 'lxml')
|
||||
|
||||
def _extract_filename_from_headers(self, headers: dict) -> Optional[str]:
|
||||
"""Extract filename from Content-Disposition header"""
|
||||
from app.utils import sanitize_filename
|
||||
|
||||
content_disposition = headers.get("content-disposition", "")
|
||||
if "filename=" in content_disposition:
|
||||
filename = content_disposition.split("filename=")[-1].strip('"')
|
||||
return sanitize_filename(filename) # Security!
|
||||
return None
|
||||
|
||||
def _sanitize(self, filename: str) -> str:
|
||||
"""Convenience method for filename sanitization"""
|
||||
from app.utils import sanitize_filename
|
||||
return sanitize_filename(filename)
|
||||
Reference in New Issue
Block a user