Skip to content

Commit 6c2e7ab

Browse files
feat: add last updated time on addon description after update
1 parent c5697e6 commit 6c2e7ab

File tree

5 files changed

+35
-36
lines changed

5 files changed

+35
-36
lines changed

app/api/endpoints/manifest.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from datetime import datetime, timezone
2+
13
from fastapi import HTTPException, Response
24
from fastapi.routing import APIRouter
35
from loguru import logger
@@ -10,27 +12,11 @@
1012
from app.services.stremio.service import StremioBundle
1113
from app.services.token_store import token_store
1214
from app.services.translation import translation_service
15+
from app.utils.catalog import get_catalogs_from_config
1316

1417
router = APIRouter()
1518

1619

17-
def get_catalogs_from_config(
18-
user_settings: UserSettings, cat_id: str, default_name: str, default_movie: bool, default_series: bool
19-
):
20-
catalogs = []
21-
config = next((c for c in user_settings.catalogs if c.id == cat_id), None)
22-
if not config or config.enabled:
23-
name = config.name if config and config.name else default_name
24-
enabled_movie = getattr(config, "enabled_movie", default_movie) if config else default_movie
25-
enabled_series = getattr(config, "enabled_series", default_series) if config else default_series
26-
27-
if enabled_movie:
28-
catalogs.append({"type": "movie", "id": cat_id, "name": name, "extra": []})
29-
if enabled_series:
30-
catalogs.append({"type": "series", "id": cat_id, "name": name, "extra": []})
31-
return catalogs
32-
33-
3420
def get_base_manifest(user_settings: UserSettings | None = None):
3521
catalogs = []
3622

@@ -47,7 +33,10 @@ def get_base_manifest(user_settings: UserSettings | None = None):
4733
"id": settings.ADDON_ID,
4834
"version": __version__,
4935
"name": settings.ADDON_NAME,
50-
"description": "Movie and series recommendations based on your Stremio library",
36+
"description": (
37+
"Movie and series recommendations based on your Stremio library. \nLast updated on:"
38+
f" {datetime.now(timezone.utc).strftime('%d %B %Y, %H:%M:%S')} UTC"
39+
),
5140
"logo": "https://raw.githubusercontent.com/TimilsinaBimal/Watchly/refs/heads/main/app/static/logo.png",
5241
"background": ("https://raw.githubusercontent.com/TimilsinaBimal/Watchly/refs/heads/main/app/static/cover.png"),
5342
"resources": ["catalog"],

app/core/app.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ async def lifespan(app: FastAPI):
2929
logger.warning(f"Failed to close TokenStore Redis client: {exc}")
3030

3131

32-
if settings.APP_ENV != "development":
33-
lifespan = lifespan
34-
else:
35-
lifespan = None
36-
3732
app = FastAPI(
3833
title="Watchly",
3934
description="Stremio catalog addon for movie and series recommendations",
@@ -80,7 +75,6 @@ async def block_missing_token_middleware(request: Request, call_next):
8075

8176

8277
# Serve static files
83-
# Static directory is at project root (3 levels up from app/core/app.py)
8478
# app/core/app.py -> app/core -> app -> root
8579
project_root = Path(__file__).resolve().parent.parent.parent
8680
static_dir = project_root / "app/static"

app/services/stremio/addons.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
from datetime import datetime, timezone
12
from typing import Any
23
from urllib.parse import urlparse
34

45
from loguru import logger
56

7+
from app.core.config import settings
68
from app.services.stremio.client import StremioClient
79

810

@@ -63,23 +65,22 @@ async def update_catalogs(self, auth_key: str, catalogs: list[dict[str, Any]]) -
6365
"""
6466
Inject dynamic catalogs into the installed Watchly addon.
6567
"""
66-
from app.core.config import settings
67-
68-
# Base catalogs that are always present
69-
BASE_CATALOGS = [
70-
{"type": "movie", "id": "watchly.rec", "name": "Top Picks for You", "extra": []},
71-
{"type": "series", "id": "watchly.rec", "name": "Top Picks for You", "extra": []},
72-
]
7368

7469
addons = await self.get_addons(auth_key)
75-
full_catalogs = BASE_CATALOGS + catalogs
7670

7771
found = False
7872
for addon in addons:
7973
if addon.get("manifest", {}).get("id") == settings.ADDON_ID and match_hostname(
8074
addon.get("transportUrl"), settings.HOST_NAME
8175
):
82-
addon["manifest"]["catalogs"] = full_catalogs
76+
addon["manifest"]["catalogs"] = catalogs
77+
# also update description with updated time
78+
# get description from existing addon manifest
79+
description = addon.get("manifest", {}).get("description", "")
80+
addon["manifest"]["description"] = (
81+
f"{description}\nLast updated on:"
82+
f" {datetime.now(timezone.utc).strftime('%d %B %Y, %H:%M:%S')} UTC"
83+
)
8384
found = True
8485
break
8586

@@ -91,7 +92,6 @@ async def update_catalogs(self, auth_key: str, catalogs: list[dict[str, Any]]) -
9192

9293
async def is_addon_installed(self, auth_key: str) -> bool:
9394
"""Check if the Watchly addon is present in the user's collection."""
94-
from app.core.config import settings
9595

9696
addons = await self.get_addons(auth_key)
9797
for addon in addons:

app/services/tmdb/service.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,11 @@ async def get_tv_details(self, tv_id: int) -> dict[str, Any]:
6363

6464
async def get_recommendations(self, tmdb_id: int, media_type: str, page: int = 1) -> dict[str, Any]:
6565
"""Get recommendations based on TMDB ID and media type."""
66-
logger.info(f"Fetching recommendations for: {tmdb_id}")
6766
params = {"page": page}
6867
return await self.client.get(f"/{media_type}/{tmdb_id}/recommendations", params=params)
6968

7069
async def get_similar(self, tmdb_id: int, media_type: str, page: int = 1) -> dict[str, Any]:
7170
"""Get similar content based on TMDB ID and media type."""
72-
logger.info(f"Fetching similar for {tmdb_id}")
7371
params = {"page": page}
7472
return await self.client.get(f"/{media_type}/{tmdb_id}/similar", params=params)
7573

app/utils/catalog.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from app.core.settings import UserSettings
2+
3+
4+
def get_catalogs_from_config(
5+
user_settings: UserSettings, cat_id: str, default_name: str, default_movie: bool, default_series: bool
6+
):
7+
catalogs = []
8+
config = next((c for c in user_settings.catalogs if c.id == cat_id), None)
9+
if not config or config.enabled:
10+
name = config.name if config and config.name else default_name
11+
enabled_movie = getattr(config, "enabled_movie", default_movie) if config else default_movie
12+
enabled_series = getattr(config, "enabled_series", default_series) if config else default_series
13+
14+
if enabled_movie:
15+
catalogs.append({"type": "movie", "id": cat_id, "name": name, "extra": []})
16+
if enabled_series:
17+
catalogs.append({"type": "series", "id": cat_id, "name": name, "extra": []})
18+
return catalogs

0 commit comments

Comments
 (0)