Files
ohm_streaming/app/downloaders/video_players/sendvid.py
T
root 3afad41d46 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>
2026-01-24 22:13:20 +00:00

84 lines
3.2 KiB
Python

from typing import Optional
from bs4 import BeautifulSoup
from .base import BaseVideoPlayer
import re
class SendVidDownloader(BaseVideoPlayer):
"""Downloader for SendVid videos"""
def can_handle(self, url: str) -> bool:
return "sendvid.com" in url.lower()
async def _fetch_page(self, url: str) -> str:
"""Fetch page with proper headers to avoid 403 errors"""
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
'Referer': 'https://sendvid.com/',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
}
response = await self.client.get(url, headers=headers)
response.raise_for_status()
return response.text
async def get_download_link(self, url: str, target_filename: str = None) -> tuple[str, str]:
"""
Extract direct download link from SendVid embed page
SendVid embed pages contain the direct MP4 URL in a <source> tag
"""
print(f"[SENDVID] Fetching page: {url}")
html = await self._fetch_page(url)
soup = BeautifulSoup(html, 'lxml')
# Try to find the video source in the <source> tag
source_tag = soup.find('source', {'id': 'video_source'})
if source_tag and source_tag.get('src'):
video_url = source_tag['src']
print(f"[SENDVID] Found video URL in <source> tag")
# Generate filename
if target_filename:
filename = target_filename
else:
# Extract filename from video URL or generate one
filename = self._extract_filename_from_url(url, video_url)
print(f"[SENDVID] Download URL: {video_url}")
print(f"[SENDVID] Filename: {filename}")
return video_url, filename
# Fallback: try to find in og:video meta property
og_video = soup.find('meta', {'property': 'og:video'})
if og_video and og_video.get('content'):
video_url = og_video['content']
print(f"[SENDVID] Found video URL in og:video meta")
if target_filename:
filename = target_filename
else:
filename = self._extract_filename_from_url(url, video_url)
print(f"[SENDVID] Download URL: {video_url}")
print(f"[SENDVID] Filename: {filename}")
return video_url, filename
raise Exception("Could not extract video URL from SendVid page")
def _extract_filename_from_url(self, page_url: str, video_url: str) -> str:
"""Generate filename from SendVod URLs"""
# Try to extract video ID from page URL
video_id_match = re.search(r'/embed/([a-z0-9]+)', page_url)
if video_id_match:
video_id = video_id_match.group(1)
# Try to get title from page (might need to fetch, but for now use ID)
return f"sendvid_{video_id}.mp4"
# Fallback: extract from video URL
filename_match = re.search(r'/([^/]+\.mp4)', video_url)
if filename_match:
return filename_match.group(1)
return "sendvid_video.mp4"