Skip to content

Commit adcc6e0

Browse files
opt: optimize translation service
1 parent a01c255 commit adcc6e0

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

app/api/endpoints/manifest.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,38 @@ async def _manifest_handler(response: Response, token: str):
111111

112112
base_manifest = get_base_manifest(user_settings)
113113

114+
fetched_catalogs = await fetch_catalogs(token)
115+
116+
all_catalogs = [c.copy() for c in base_manifest["catalogs"]] + [c.copy() for c in fetched_catalogs]
117+
118+
translated_catalogs = []
119+
114120
# translate to target language
115121
if user_settings and user_settings.language:
116-
for cat in base_manifest.get("catalogs", []):
122+
for cat in all_catalogs:
117123
if cat.get("name"):
118124
cat["name"] = await translation_service.translate(cat["name"], user_settings.language)
119-
120-
fetched_catalogs = await fetch_catalogs(token)
121-
122-
all_catalogs = [c.copy() for c in base_manifest["catalogs"]] + [c.copy() for c in fetched_catalogs]
125+
translated_catalogs.append(cat)
126+
else:
127+
translated_catalogs = all_catalogs
123128

124129
if user_settings:
125130
order_map = {c.id: i for i, c in enumerate(user_settings.catalogs)}
126-
all_catalogs.sort(key=lambda x: order_map.get(get_config_id(x), 999))
131+
translated_catalogs.sort(key=lambda x: order_map.get(get_config_id(x), 999))
127132

128-
base_manifest["catalogs"] = all_catalogs
133+
base_manifest["catalogs"] = translated_catalogs
129134

130135
return base_manifest
131136

132137

138+
@router.get("/manifest.json")
139+
async def manifest():
140+
manifest = await get_base_manifest()
141+
# since user is not logged in, return empty catalogs
142+
manifest["catalogs"] = []
143+
return manifest
144+
145+
133146
@router.get("/{token}/manifest.json")
134147
async def manifest_token(response: Response, token: str):
135148
return await _manifest_handler(response, token)

app/core/settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ def get_default_settings() -> UserSettings:
1919
return UserSettings(
2020
language="en-US",
2121
catalogs=[
22-
CatalogConfig(id="watchly.rec", name="Recommended", enabled=True),
23-
CatalogConfig(id="watchly.loved", name="More like what you loved", enabled=True),
22+
CatalogConfig(id="watchly.rec", name="Top Picks for You", enabled=True),
23+
CatalogConfig(id="watchly.loved", name="More Like", enabled=True),
2424
CatalogConfig(id="watchly.watched", name="Because you watched", enabled=True),
25-
CatalogConfig(id="watchly.theme", name="Because of Genre/Theme", enabled=True),
25+
CatalogConfig(id="watchly.theme", name="Genre & Keyword Catalogs", enabled=True),
2626
],
2727
)
2828

app/services/catalog.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from app.services.scoring import ScoringService
44
from app.services.stremio_service import StremioService
55
from app.services.tmdb_service import TMDBService
6-
from app.services.translation import translation_service
76
from app.services.user_profile import UserProfileService
87

98

@@ -47,7 +46,6 @@ async def get_theme_based_catalogs(
4746
self, library_items: list[dict], user_settings: UserSettings | None = None
4847
) -> list[dict]:
4948
catalogs = []
50-
lang = user_settings.language if user_settings else "en-US"
5149

5250
# 1. Build User Profile
5351
# Combine loved and watched
@@ -82,8 +80,8 @@ async def get_theme_based_catalogs(
8280
movie_rows = await self.row_generator.generate_rows(movie_profile, "movie")
8381

8482
for row in movie_rows:
85-
translated_title = await translation_service.translate(row.title, lang)
86-
catalogs.append({"type": "movie", "id": row.id, "name": translated_title, "extra": []})
83+
# translated_title = await translation_service.translate(row.title, lang)
84+
catalogs.append({"type": "movie", "id": row.id, "name": row.title, "extra": []})
8785

8886
# Generate for Series
8987
series_profile = await self.user_profile_service.build_user_profile(
@@ -92,8 +90,8 @@ async def get_theme_based_catalogs(
9290
series_rows = await self.row_generator.generate_rows(series_profile, "series")
9391

9492
for row in series_rows:
95-
translated_title = await translation_service.translate(row.title, lang)
96-
catalogs.append({"type": "series", "id": row.id, "name": translated_title, "extra": []})
93+
# translated_title = await translation_service.translate(row.title, lang)
94+
catalogs.append({"type": "series", "id": row.id, "name": row.title, "extra": []})
9795

9896
return catalogs
9997

@@ -108,7 +106,8 @@ async def get_dynamic_catalogs(
108106

109107
# Theme Based
110108
theme_config = next((c for c in user_settings.catalogs if c.id == "watchly.theme"), None)
111-
if not theme_config or theme_config.enabled:
109+
110+
if theme_config and theme_config.enabled:
112111
catalogs.extend(await self.get_theme_based_catalogs(library_items, user_settings))
113112

114113
# Item Based (Loved/Watched)
@@ -165,8 +164,6 @@ def get_date(item):
165164
last_loved = loved[0] if loved else None
166165
if last_loved:
167166
label = loved_config.name
168-
if not label or label == "More like what you loved": # Default
169-
label = await translation_service.translate("More like what you loved", language)
170167

171168
catalogs.append(self.build_catalog_entry(last_loved, label, "watchly.loved"))
172169

@@ -185,7 +182,5 @@ def get_date(item):
185182

186183
if last_watched:
187184
label = watched_config.name
188-
if not label or label == "Because you watched":
189-
label = await translation_service.translate("Because you watched", language)
190185

191186
catalogs.append(self.build_catalog_entry(last_watched, label, "watchly.watched"))

app/static/script.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Default catalog configurations
22
const defaultCatalogs = [
33
{ id: 'watchly.rec', name: 'Top Picks for You', enabled: true, description: 'Personalized recommendations based on your library' },
4-
{ id: 'watchly.loved', name: 'More like what you loved', enabled: true, description: 'Recommendations similar to content you explicitly loved' },
5-
{ id: 'watchly.watched', name: 'Because you watched', enabled: true, description: 'Recommendations based on your recent watch history' },
6-
{ id: 'watchly.theme', name: 'Genre & Theme Collections', enabled: true, description: 'Dynamic collections based on your favorite genres' },
4+
{ id: 'watchly.loved', name: 'More Like', enabled: true, description: 'Recommendations similar to content you explicitly loved' },
5+
{ id: 'watchly.watched', name: 'Because You Watched', enabled: true, description: 'Recommendations based on your recent watch history' },
6+
{ id: 'watchly.theme', name: 'Genre & Keyword Catalogs', enabled: true, description: 'Dynamic catalogs based on your favorite genres, keyword, countries and many more. Just like netflix. Example: American Horror, Based on Novel or Book etc.' },
77
];
88

99
let catalogs = JSON.parse(JSON.stringify(defaultCatalogs));
@@ -506,7 +506,7 @@ function createCatalogItem(cat, index) {
506506
item.className = `catalog-item group bg-slate-900 border border-slate-700 rounded-xl p-4 transition-all hover:border-slate-600 ${disabledClass}`;
507507
item.setAttribute('data-index', index);
508508

509-
const isRenamable = true;
509+
const isRenamable = cat.id !== 'watchly.theme';
510510
item.innerHTML = `
511511
<div class="flex items-start gap-3 sm:items-center sm:gap-4">
512512
<div class="sort-buttons flex flex-col gap-1 flex-shrink-0 mt-0.5 sm:mt-0">

0 commit comments

Comments
 (0)