|
14 | 14 | router = APIRouter() |
15 | 15 |
|
16 | 16 |
|
| 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 | + |
17 | 34 | def get_base_manifest(user_settings: UserSettings | None = None): |
18 | 35 | catalogs = [] |
19 | 36 |
|
20 | 37 | if user_settings: |
21 | | - # Handle watchly.rec |
22 | | - rec_config = next((c for c in user_settings.catalogs if c.id == "watchly.rec"), None) |
23 | | - if not rec_config or rec_config.enabled: |
24 | | - name = rec_config.name if rec_config and rec_config.name else "Top Picks for You" |
25 | | - enabled_movie = getattr(rec_config, "enabled_movie", True) if rec_config else True |
26 | | - enabled_series = getattr(rec_config, "enabled_series", True) if rec_config else True |
27 | | - |
28 | | - if enabled_movie: |
29 | | - catalogs.append({"type": "movie", "id": "watchly.rec", "name": name, "extra": []}) |
30 | | - if enabled_series: |
31 | | - catalogs.append({"type": "series", "id": "watchly.rec", "name": name, "extra": []}) |
32 | | - |
33 | | - # Handle watchly.creators |
34 | | - creators_config = next((c for c in user_settings.catalogs if c.id == "watchly.creators"), None) |
35 | | - if not creators_config or creators_config.enabled: |
36 | | - name = creators_config.name if creators_config and creators_config.name else "From your favourite Creators" |
37 | | - enabled_movie = getattr(creators_config, "enabled_movie", True) if creators_config else True |
38 | | - enabled_series = getattr(creators_config, "enabled_series", True) if creators_config else True |
39 | | - |
40 | | - if enabled_movie: |
41 | | - catalogs.append({"type": "movie", "id": "watchly.creators", "name": name, "extra": []}) |
42 | | - if enabled_series: |
43 | | - catalogs.append({"type": "series", "id": "watchly.creators", "name": name, "extra": []}) |
| 38 | + catalogs.extend(get_catalogs_from_config(user_settings, "watchly.rec", "Top Picks for You", True, True)) |
| 39 | + catalogs.extend( |
| 40 | + get_catalogs_from_config(user_settings, "watchly.creators", "From your favourite Creators", False, False) |
| 41 | + ) |
44 | 42 | else: |
45 | 43 | # Default: include watchly.rec |
46 | 44 | catalogs.append({"type": "movie", "id": "watchly.rec", "name": "Top Picks for You", "extra": []}) |
|
0 commit comments