-
-
Notifications
You must be signed in to change notification settings - Fork 10
feat: add option to configure top_posters for poster rating #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
67ca101
feat: add option to configure top_posters for poster rating
TimilsinaBimal bbf7348
feat: implement poster rating API key validation and frontend integra…
TimilsinaBimal 72a24e6
feat: add display_at_home and shuffle options to Stremio identity fetch
TimilsinaBimal 5417ea9
minor improvments
TimilsinaBimal 7ff6f0a
Update app/services/token_store.py
TimilsinaBimal 6750f72
refactor: rename get_poster methods to get_poster_url for clarity and…
TimilsinaBimal ebae436
Merge branch 'feat/rating-posters' of github.com:TimilsinaBimal/Watch…
TimilsinaBimal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| from fastapi import APIRouter, HTTPException | ||
| from loguru import logger | ||
| from pydantic import BaseModel, Field | ||
|
|
||
| from app.services.poster_ratings.factory import PosterProvider, poster_ratings_factory | ||
|
|
||
| router = APIRouter(prefix="/poster-rating", tags=["poster-rating"]) | ||
|
|
||
|
|
||
| class ValidateApiKeyRequest(BaseModel): | ||
| provider: str = Field(description="Provider name: 'rpdb' or 'top_posters'") | ||
| api_key: str = Field(description="API key to validate") | ||
|
|
||
|
|
||
| class ValidateApiKeyResponse(BaseModel): | ||
| valid: bool | ||
| message: str | None = None | ||
|
|
||
|
|
||
| @router.post("/validate", response_model=ValidateApiKeyResponse) | ||
| async def validate_api_key(payload: ValidateApiKeyRequest) -> ValidateApiKeyResponse: | ||
| """Validate a poster rating provider API key.""" | ||
| if not payload.api_key or not payload.api_key.strip(): | ||
| return ValidateApiKeyResponse(valid=False, message="API key cannot be empty") | ||
|
|
||
| try: | ||
| provider_enum = PosterProvider(payload.provider) | ||
| except ValueError: | ||
| raise HTTPException(status_code=400, detail=f"Invalid provider: {payload.provider}") | ||
|
|
||
| try: | ||
| if provider_enum == PosterProvider.RPDB: | ||
| is_valid = await poster_ratings_factory.rpdb_service.validate_api_key(payload.api_key.strip()) | ||
| elif provider_enum == PosterProvider.TOP_POSTERS: | ||
| is_valid = await poster_ratings_factory.top_posters_service.validate_api_key(payload.api_key.strip()) | ||
| else: | ||
| raise HTTPException(status_code=400, detail=f"Unsupported provider: {payload.provider}") | ||
|
|
||
| if is_valid: | ||
| return ValidateApiKeyResponse(valid=True, message="API key is valid") | ||
| else: | ||
| return ValidateApiKeyResponse(valid=False, message="Invalid API key") | ||
| except Exception as e: | ||
| logger.error(f"Validation failed: {str(e)}") | ||
| return ValidateApiKeyResponse(valid=False, message="Validation failed due to an internal error.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| from enum import Enum | ||
| from typing import Literal | ||
|
|
||
| from app.services.poster_ratings.rpdb import RPDBService | ||
| from app.services.poster_ratings.top_posters import TopPostersService | ||
|
|
||
|
|
||
| class PosterProvider(Enum): | ||
| RPDB = "rpdb" | ||
| TOP_POSTERS = "top_posters" | ||
|
|
||
|
|
||
| class PosterRatingsFactory: | ||
| def __init__(self): | ||
| self.rpdb_service: RPDBService = RPDBService() | ||
| self.top_posters_service: TopPostersService = TopPostersService() | ||
|
|
||
| def get_poster_url( | ||
| self, | ||
| poster_provider: PosterProvider, | ||
| api_key: str, | ||
| provider: Literal["imdb", "tmdb", "tvdb"], | ||
| item_id: str, | ||
| **kwargs, | ||
| ) -> str: | ||
|
|
||
| poster_provider_map = { | ||
| PosterProvider.RPDB: self.rpdb_service, | ||
| PosterProvider.TOP_POSTERS: self.top_posters_service, | ||
| } | ||
| return poster_provider_map[poster_provider].get_poster(api_key, provider, item_id, **kwargs) | ||
|
|
||
|
|
||
| poster_ratings_factory = PosterRatingsFactory() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| from typing import Literal | ||
| from urllib.parse import urlencode | ||
|
|
||
| import httpx | ||
|
|
||
|
|
||
| class RPDBService: | ||
| def __init__(self): | ||
| self.base_url = "https://api.ratingposterdb.com" | ||
|
|
||
| async def validate_api_key(self, api_key: str) -> bool: | ||
| url = f"{self.base_url}/{api_key}/isValid" | ||
| async with httpx.AsyncClient(timeout=10.0) as client: | ||
| response = await client.get(url) | ||
| return response.status_code == 200 | ||
|
|
||
| def get_poster_url( | ||
| self, | ||
| api_key: str, | ||
| provider: Literal["imdb", "tmdb", "tvdb"], | ||
| item_id: str, | ||
| fallback: str, | ||
| ) -> str: | ||
| url = f"{self.base_url}/{api_key}/{provider}/poster-default/{item_id}.jpg" | ||
| params = {"fallback": "true"} | ||
|
|
||
| poster_url = f"{url}?{urlencode(params)}" | ||
| return poster_url | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| from typing import Literal | ||
| from urllib.parse import urlencode | ||
|
|
||
| import httpx | ||
|
|
||
|
|
||
| class TopPostersService: | ||
| def __init__(self): | ||
| self.base_url = "https://api.top-streaming.stream" | ||
|
|
||
| async def validate_api_key(self, api_key: str) -> bool: | ||
| url = f"{self.base_url}/auth/verify/{api_key}" | ||
| async with httpx.AsyncClient(timeout=10.0) as client: | ||
| response = await client.get(url) | ||
| response.raise_for_status() | ||
| json_data = response.json() | ||
| return json_data.get("valid", False) | ||
|
|
||
| def get_poster_url(self, api_key: str, provider: Literal["imdb", "tmdb", "tvdb"], item_id: str, **kwargs) -> str: | ||
| url = f"{self.base_url}/{api_key}/{provider}/poster-default/{item_id}.jpg" | ||
|
|
||
| poster_url = f"{url}?{urlencode(kwargs)}" | ||
| return poster_url |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.