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,79 @@
|
||||
from .base import BaseVideoPlayer
|
||||
from bs4 import BeautifulSoup
|
||||
import re
|
||||
import httpx
|
||||
|
||||
|
||||
class DoodStreamDownloader(BaseVideoPlayer):
|
||||
"""Downloader for doodstream.com"""
|
||||
|
||||
def can_handle(self, url: str) -> bool:
|
||||
return any(domain in url.lower() for domain in ["doodstream.com", "dood.stream", "dood.to", "dood.lol", "dood.cx", "dood.so", "dood.watch", "dood.sh"])
|
||||
|
||||
async def get_download_link(self, url: str, target_filename: str = None) -> tuple[str, str]:
|
||||
try:
|
||||
# Get the page
|
||||
response = await self.client.get(url)
|
||||
response.raise_for_status()
|
||||
soup = BeautifulSoup(response.text, 'lxml')
|
||||
|
||||
# Doodstream usually has the video URL in a script with '$(function)'
|
||||
# or in a token-based system
|
||||
download_url = None
|
||||
filename = "doodstream_video.mp4"
|
||||
|
||||
# Method 1: Look for /pass_md5 or similar patterns
|
||||
scripts = soup.find_all('script')
|
||||
for script in scripts:
|
||||
if script.string:
|
||||
# Look for token patterns
|
||||
match = re.search(r'https?://[^\"\']+\.(?:mp4|mkv|avi)', script.string)
|
||||
if match:
|
||||
download_url = match.group(0)
|
||||
break
|
||||
|
||||
# Look for doodstream CDN patterns
|
||||
match = re.search(r'(https?://[^\s\"\'<>]+/download/[^\s\"\'<>]+)', script.string)
|
||||
if match:
|
||||
download_url = match.group(0)
|
||||
break
|
||||
|
||||
# Method 2: Try to construct download URL from page
|
||||
if not download_url:
|
||||
# Extract video ID from URL
|
||||
# Format: https://doodstream.com/e/VIDEO_ID or /d/VIDEO_ID
|
||||
video_id_match = re.search(r'/[ed]/([a-zA-Z0-9]+)', url)
|
||||
if video_id_match:
|
||||
video_id = video_id_match.group(1)
|
||||
# Try direct download pattern
|
||||
download_url = f"https://dood.stream/e/{video_id}"
|
||||
|
||||
# Method 3: Look for any MP4 source in iframes or video tags
|
||||
if not download_url:
|
||||
video = soup.find('video')
|
||||
if video and video.get('src'):
|
||||
download_url = video['src']
|
||||
else:
|
||||
sources = soup.find_all('source')
|
||||
for source in sources:
|
||||
if source.get('src'):
|
||||
download_url = source['src']
|
||||
filename = source.get('src', '').split('/')[-1]
|
||||
break
|
||||
|
||||
if download_url:
|
||||
# Try to get real filename from HEAD request
|
||||
try:
|
||||
head_resp = await self.client.head(download_url, timeout=5.0)
|
||||
fname = self._extract_filename_from_headers(head_resp.headers)
|
||||
if fname:
|
||||
filename = fname
|
||||
except:
|
||||
pass
|
||||
|
||||
return download_url, filename
|
||||
|
||||
raise Exception("Could not extract download link from Doodstream page")
|
||||
|
||||
except Exception as e:
|
||||
raise Exception(f"Error extracting Doodstream link: {str(e)}")
|
||||
Reference in New Issue
Block a user