Base Provider¶
base
¶
Base provider interface and data classes for anime sources.
This module defines the abstract base class and data structures that all anime providers must implement. It provides a consistent interface for searching, fetching details, and extracting streams from various sources.
Data Classes
AnimeResult: Search result representation Episode: Episode information StreamLink: Stream URL with metadata AnimeDetails: Complete anime information
Base Class
BaseProvider: Abstract interface for all providers
Example
Implementing a provider::
from weeb_cli.providers.base import BaseProvider, AnimeResult
from weeb_cli.providers.registry import register_provider
@register_provider("myprovider", lang="en", region="US")
class MyProvider(BaseProvider):
def search(self, query: str) -> List[AnimeResult]:
# Implementation
pass
def get_details(self, anime_id: str) -> Optional[AnimeDetails]:
# Implementation
pass
AnimeResult
dataclass
¶
Search result for an anime.
Represents a single anime in search results with basic information.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for the anime (provider-specific). |
title |
str
|
Display title of the anime. |
type |
str
|
Content type (e.g., 'series', 'movie', 'ova'). |
cover |
Optional[str]
|
URL to cover/poster image. |
year |
Optional[int]
|
Release year. |
Source code in weeb_cli/providers/base.py
Episode
dataclass
¶
Episode information.
Represents a single episode with metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for the episode (provider-specific). |
number |
int
|
Episode number within the season. |
title |
Optional[str]
|
Episode title (if available). |
season |
int
|
Season number (default: 1). |
url |
Optional[str]
|
Direct URL to episode page (optional). |
Source code in weeb_cli/providers/base.py
StreamLink
dataclass
¶
Stream URL with metadata.
Represents a playable stream with quality and server information.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
Direct stream URL (HLS, MP4, etc.). |
quality |
str
|
Quality label (e.g., '1080p', '720p', 'auto'). |
server |
str
|
Server/host name (e.g., 'megacloud', 'default'). |
headers |
Dict[str, str]
|
HTTP headers required for playback. |
subtitles |
Optional[str]
|
URL to subtitle file (optional). |
Source code in weeb_cli/providers/base.py
AnimeDetails
dataclass
¶
Complete anime information.
Represents full details of an anime including episodes.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for the anime. |
title |
str
|
Display title. |
description |
Optional[str]
|
Synopsis/description text. |
cover |
Optional[str]
|
URL to cover/poster image. |
genres |
List[str]
|
List of genre tags. |
year |
Optional[int]
|
Release year. |
status |
Optional[str]
|
Airing status (e.g., 'ongoing', 'completed'). |
episodes |
List[Episode]
|
List of available episodes. |
total_episodes |
Optional[int]
|
Total episode count (if known). |
Source code in weeb_cli/providers/base.py
BaseProvider
¶
Bases: ABC
Abstract base class for anime providers.
All anime source providers must inherit from this class and implement the abstract methods. Provides common functionality like HTTP requests with retry logic.
Class Attributes
name: Provider identifier (set by @register_provider). lang: Language code (e.g., 'en', 'tr', 'de', 'pl'). region: Region code (e.g., 'US', 'TR', 'DE', 'PL').
Instance Attributes
headers: Default HTTP headers for requests.
Example
Implementing a provider::
@register_provider("myprovider", lang="en", region="US")
class MyProvider(BaseProvider):
def search(self, query: str) -> List[AnimeResult]:
results = self._request(f"{BASE_URL}/search?q={query}")
return [AnimeResult(id=r['id'], title=r['title'])
for r in results]
Source code in weeb_cli/providers/base.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
__init__
¶
Initialize provider with default headers.
Source code in weeb_cli/providers/base.py
search
abstractmethod
¶
Search for anime by query string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search query (anime title or keywords). |
required |
Returns:
| Type | Description |
|---|---|
List[AnimeResult]
|
List of anime search results. |
Raises:
| Type | Description |
|---|---|
ProviderError
|
If search fails. |
Source code in weeb_cli/providers/base.py
get_details
abstractmethod
¶
Get detailed information for an anime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
anime_id
|
str
|
Unique anime identifier from search results. |
required |
Returns:
| Type | Description |
|---|---|
Optional[AnimeDetails]
|
Complete anime details, or None if not found. |
Raises:
| Type | Description |
|---|---|
ProviderError
|
If fetching details fails. |
Source code in weeb_cli/providers/base.py
get_episodes
abstractmethod
¶
Get list of available episodes for an anime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
anime_id
|
str
|
Unique anime identifier. |
required |
Returns:
| Type | Description |
|---|---|
List[Episode]
|
List of episodes with metadata. |
Raises:
| Type | Description |
|---|---|
ProviderError
|
If fetching episodes fails. |
Source code in weeb_cli/providers/base.py
get_streams
abstractmethod
¶
Get stream URLs for a specific episode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
anime_id
|
str
|
Unique anime identifier. |
required |
episode_id
|
str
|
Unique episode identifier. |
required |
Returns:
| Type | Description |
|---|---|
List[StreamLink]
|
List of available stream links with quality options. |
Raises:
| Type | Description |
|---|---|
ProviderError
|
If extracting streams fails. |
Source code in weeb_cli/providers/base.py
Overview¶
The base provider module defines the abstract interface and data structures that all anime providers must implement.
Data Classes¶
AnimeResult¶
Search result representation.
Episode¶
Episode information with metadata.
StreamLink¶
Stream URL with quality and server information.
AnimeDetails¶
Complete anime information including episodes.
BaseProvider Interface¶
Abstract base class that all providers must inherit from.
Required Methods¶
search(): Search for animeget_details(): Get anime detailsget_episodes(): Get episode listget_streams(): Extract stream URLs
Helper Methods¶
_request(): HTTP request with retry logic
Implementation Example¶
from weeb_cli.providers.base import BaseProvider, AnimeResult
from weeb_cli.providers.registry import register_provider
@register_provider("myprovider", lang="en", region="US")
class MyProvider(BaseProvider):
def search(self, query: str) -> List[AnimeResult]:
# Implementation
pass
API Reference¶
AnimeResult
dataclass
¶
Search result for an anime.
Represents a single anime in search results with basic information.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for the anime (provider-specific). |
title |
str
|
Display title of the anime. |
type |
str
|
Content type (e.g., 'series', 'movie', 'ova'). |
cover |
Optional[str]
|
URL to cover/poster image. |
year |
Optional[int]
|
Release year. |
Source code in weeb_cli/providers/base.py
Episode
dataclass
¶
Episode information.
Represents a single episode with metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for the episode (provider-specific). |
number |
int
|
Episode number within the season. |
title |
Optional[str]
|
Episode title (if available). |
season |
int
|
Season number (default: 1). |
url |
Optional[str]
|
Direct URL to episode page (optional). |
Source code in weeb_cli/providers/base.py
StreamLink
dataclass
¶
Stream URL with metadata.
Represents a playable stream with quality and server information.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
Direct stream URL (HLS, MP4, etc.). |
quality |
str
|
Quality label (e.g., '1080p', '720p', 'auto'). |
server |
str
|
Server/host name (e.g., 'megacloud', 'default'). |
headers |
Dict[str, str]
|
HTTP headers required for playback. |
subtitles |
Optional[str]
|
URL to subtitle file (optional). |
Source code in weeb_cli/providers/base.py
AnimeDetails
dataclass
¶
Complete anime information.
Represents full details of an anime including episodes.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for the anime. |
title |
str
|
Display title. |
description |
Optional[str]
|
Synopsis/description text. |
cover |
Optional[str]
|
URL to cover/poster image. |
genres |
List[str]
|
List of genre tags. |
year |
Optional[int]
|
Release year. |
status |
Optional[str]
|
Airing status (e.g., 'ongoing', 'completed'). |
episodes |
List[Episode]
|
List of available episodes. |
total_episodes |
Optional[int]
|
Total episode count (if known). |
Source code in weeb_cli/providers/base.py
BaseProvider
¶
Bases: ABC
Abstract base class for anime providers.
All anime source providers must inherit from this class and implement the abstract methods. Provides common functionality like HTTP requests with retry logic.
Class Attributes
name: Provider identifier (set by @register_provider). lang: Language code (e.g., 'en', 'tr', 'de', 'pl'). region: Region code (e.g., 'US', 'TR', 'DE', 'PL').
Instance Attributes
headers: Default HTTP headers for requests.
Example
Implementing a provider::
@register_provider("myprovider", lang="en", region="US")
class MyProvider(BaseProvider):
def search(self, query: str) -> List[AnimeResult]:
results = self._request(f"{BASE_URL}/search?q={query}")
return [AnimeResult(id=r['id'], title=r['title'])
for r in results]
Source code in weeb_cli/providers/base.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
__init__
¶
Initialize provider with default headers.
Source code in weeb_cli/providers/base.py
search
abstractmethod
¶
Search for anime by query string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search query (anime title or keywords). |
required |
Returns:
| Type | Description |
|---|---|
List[AnimeResult]
|
List of anime search results. |
Raises:
| Type | Description |
|---|---|
ProviderError
|
If search fails. |
Source code in weeb_cli/providers/base.py
get_details
abstractmethod
¶
Get detailed information for an anime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
anime_id
|
str
|
Unique anime identifier from search results. |
required |
Returns:
| Type | Description |
|---|---|
Optional[AnimeDetails]
|
Complete anime details, or None if not found. |
Raises:
| Type | Description |
|---|---|
ProviderError
|
If fetching details fails. |
Source code in weeb_cli/providers/base.py
get_episodes
abstractmethod
¶
Get list of available episodes for an anime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
anime_id
|
str
|
Unique anime identifier. |
required |
Returns:
| Type | Description |
|---|---|
List[Episode]
|
List of episodes with metadata. |
Raises:
| Type | Description |
|---|---|
ProviderError
|
If fetching episodes fails. |
Source code in weeb_cli/providers/base.py
get_streams
abstractmethod
¶
Get stream URLs for a specific episode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
anime_id
|
str
|
Unique anime identifier. |
required |
episode_id
|
str
|
Unique episode identifier. |
required |
Returns:
| Type | Description |
|---|---|
List[StreamLink]
|
List of available stream links with quality options. |
Raises:
| Type | Description |
|---|---|
ProviderError
|
If extracting streams fails. |