Files
ohm_streaming/app/downloaders/video_players/base.py
T
root 3cf2f8eca5 feat: add multiple video player support for Frieren S2 downloads
- Add Lpayer API decryption using AES (key: kiemtienmua911ca)
- Add yt-dlp extraction for bypassing player blocking
- Add HTTP 206 support for video validation (Range header)
- Add VidMoly .biz domain support (alternative to .to)
- Add SendVid extraction (working - downloaded S1 and S2 E1)
- Add player fallback system with caching per anime URL
- Add video URL validation before returning to downloader
- Update HTTP clients with realistic browser headers
- Add pycryptodome to requirements.txt
- Add test file for fallback system

Downloads working: SendVid (primary), Lpayer (403 issue), VidMoly (testing)
2026-02-25 16:29:53 +00:00

93 lines
3.3 KiB
Python

"""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):
# Realistic browser headers to avoid blocking by video hosts
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.9,fr;q=0.8",
"Referer": "https://anime-sama.tv/",
}
# Initialize HTTP client with browser headers
self.client = httpx.AsyncClient(timeout=10.0, follow_redirects=True, headers=headers)
@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)