Files
ohm_streaming/app/downloaders/video_players/rapidfile.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

76 lines
3.1 KiB
Python

from .base import BaseVideoPlayer
from bs4 import BeautifulSoup
import re
import httpx
class RapidFileDownloader(BaseVideoPlayer):
"""Downloader for rapidfile.net and similar hosts"""
def can_handle(self, url: str) -> bool:
return any(domain in url.lower() for domain in ["rapidfile.net", "rapidfile.com", "rapid-file"])
async def get_download_link(self, url: str) -> tuple[str, str]:
try:
# Get the initial page
response = await self.client.get(url)
response.raise_for_status()
soup = BeautifulSoup(response.text, 'lxml')
download_url = None
filename = "rapidfile_download"
# Method 1: Look for download button/link
download_btn = soup.find('a', {'id': 'downloadbtn'}) or soup.find('a', class_='download-btn')
if download_btn and download_btn.get('href'):
download_url = download_btn['href']
# Method 2: Look for form with POST action
if not download_url:
forms = soup.find_all('form')
for form in forms:
action = form.get('action', '')
if action and ('download' in action.lower() or 'file' in action.lower()):
download_url = action if action.startswith('http') else url + action
break
# Method 3: Look for any link with download/file in URL
if not download_url:
for link in soup.find_all('a', href=True):
href = link['href']
if any(keyword in href.lower() for keyword in ['download', 'get_file', 'file.php']):
if href.startswith('http'):
download_url = href
break
# Method 4: Check for direct file links in scripts
if not download_url:
scripts = soup.find_all('script')
for script in scripts:
if script.string:
match = re.search(r'(https?://[^\s\"\'<>]+/(?:download|file)[^\s\"\'<>]+)', script.string)
if match:
download_url = match.group(0)
break
if download_url:
# Get filename from headers or URL
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
else:
filename = download_url.split('/')[-1] or "rapidfile_download"
except:
filename = download_url.split('/')[-1] or "rapidfile_download"
return download_url, filename
# If all else fails, return the original URL
filename = url.split('/')[-1] or "rapidfile_download"
return url, filename
except Exception as e:
raise Exception(f"Error extracting Rapidfile link: {str(e)}")