Skip to content

Commit 052252b

Browse files
authored
Key media item translation names by media type (#4216)
1 parent 0604c40 commit 052252b

16 files changed

Lines changed: 585 additions & 401 deletions

File tree

music_assistant/controllers/translations/__init__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ async def reverse_lookup_media_names(self, query: str) -> set[str]:
139139
140140
Lets localized item names be found by the name the user sees: a text search that returns
141141
nothing literally can be retried against these canonical names (which equal the items'
142-
stored ``search_name``). Only ``common.media.*.name`` entries are considered.
142+
stored ``search_name``). Only genre and playlist names (``common.media.genre.*`` /
143+
``common.media.playlist.*``) are considered — the searchable library media types; browse
144+
and recommendation folder titles are display-only and never library items.
143145
144146
The reverse-translation always uses the metadata controller's configured language
145147
(``CONF_LANGUAGE``), which doubles as the fallback search locale; an English, unknown or
@@ -157,7 +159,9 @@ async def reverse_lookup_media_names(self, query: str) -> set[str]:
157159
return set()
158160
matches: set[str] = set()
159161
for key, value in bundle.items():
160-
if not (key.startswith("common.media.") and key.endswith(".name")):
162+
if not key.endswith(".name"):
163+
continue
164+
if not key.startswith(("common.media.genre.", "common.media.playlist.")):
161165
continue
162166
if normalized in create_safe_string(value, True, True):
163167
if english := self._source.get(key):
@@ -219,8 +223,9 @@ def _candidate_keys(key: str, owner_prefix: str | None = None) -> list[str]:
219223
220224
A fully-qualified key (starting with ``provider.``/``core.``/``common.``) is tried
221225
as-is plus a ``common.`` rewrite that drops the owner segment. A relative key is tried
222-
under the owner prefix (if any), then ``common.``, then bare. Any candidate ending in
223-
``.name`` also gets a bare fallback (dropping ``.name``).
226+
under the owner prefix (if any), then ``common.``, then bare. Multi-instance providers carry
227+
an ``<domain>--<id>`` instance id, so the domain-only prefix is also tried before ``common.``.
228+
Any candidate ending in ``.name`` also gets a bare fallback (dropping ``.name``).
224229
"""
225230
roots = ("provider.", "core.", "common.")
226231
base_candidates: list[str] = []
@@ -235,6 +240,10 @@ def _candidate_keys(key: str, owner_prefix: str | None = None) -> list[str]:
235240
else:
236241
if owner_prefix:
237242
base_candidates.append(f"{owner_prefix}.{key}")
243+
# a multi-instance owner is "provider.<domain>--<id>"; also try the bare domain
244+
domain_prefix = owner_prefix.split("--", 1)[0]
245+
if domain_prefix != owner_prefix:
246+
base_candidates.append(f"{domain_prefix}.{key}")
238247
base_candidates.append(f"common.{key}")
239248
base_candidates.append(key)
240249
candidates: list[str] = []

music_assistant/providers/builtin/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ async def get_playlist(self, prov_playlist_id: str) -> Playlist:
256256
item_id=prov_playlist_id,
257257
provider=self.instance_id,
258258
name=BUILTIN_PLAYLISTS[prov_playlist_id],
259-
translation_key=f"builtin_playlist.{prov_playlist_id}",
259+
translation_key=prov_playlist_id,
260260
provider_mappings={
261261
ProviderMapping(
262262
item_id=prov_playlist_id,

music_assistant/providers/deezer/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ async def recommendations(self) -> list[RecommendationFolder]:
616616
item_id="made_for_you",
617617
provider=self.instance_id,
618618
name="Made for you",
619-
translation_key="recommendations.made_for_you",
619+
translation_key="made_for_you",
620620
items=UniqueList(made_for_you_items),
621621
)
622622
)
@@ -630,7 +630,7 @@ async def recommendations(self) -> list[RecommendationFolder]:
630630
item_id="recommended_albums",
631631
provider=self.instance_id,
632632
name="Recommended albums",
633-
translation_key="recommendations.recommended_albums",
633+
translation_key="recommended_albums",
634634
items=UniqueList(
635635
[self.parse_album(album=album) for album in recommended_albums]
636636
),
@@ -648,7 +648,7 @@ async def recommendations(self) -> list[RecommendationFolder]:
648648
item_id="recommended_artists",
649649
provider=self.instance_id,
650650
name="Recommended artists",
651-
translation_key="recommendations.recommended_artists",
651+
translation_key="recommended_artists",
652652
items=UniqueList(
653653
[self.parse_artist(artist=artist) for artist in recommended_artists]
654654
),

music_assistant/providers/lastfm_recommendations/recommendations.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ async def _get_personalized_recommendations(self) -> AsyncIterator[Recommendatio
414414
yield RecommendationFolder(
415415
item_id=f"{self.provider.instance_id}_similar_artists",
416416
name="Discover Similar Artists",
417-
translation_key="recommendations.discover_similar_artists",
417+
translation_key="discover_similar_artists",
418418
provider=self.provider.instance_id,
419419
items=UniqueList(similar_artists[:TARGET_ITEM_COUNT]),
420420
subtitle=f"Based on your top {len(top_artists)} artists",
@@ -435,7 +435,7 @@ async def _get_personalized_recommendations(self) -> AsyncIterator[Recommendatio
435435
yield RecommendationFolder(
436436
item_id=f"{self.provider.instance_id}_similar_tracks",
437437
name="Discover Similar Tracks",
438-
translation_key="recommendations.discover_similar_tracks",
438+
translation_key="discover_similar_tracks",
439439
provider=self.provider.instance_id,
440440
items=UniqueList(similar_tracks[:TARGET_ITEM_COUNT]),
441441
subtitle=f"Based on your top {len(top_tracks)} tracks",
@@ -460,7 +460,7 @@ async def _get_global_recommendations(self) -> AsyncIterator[RecommendationFolde
460460
yield RecommendationFolder(
461461
item_id=f"{self.provider.instance_id}_chart_top_artists",
462462
name="Global Top Artists",
463-
translation_key="recommendations.global_top_artists",
463+
translation_key="global_top_artists",
464464
provider=self.provider.instance_id,
465465
items=UniqueList(top_artists),
466466
subtitle="Most popular artists worldwide",
@@ -479,7 +479,7 @@ async def _get_global_recommendations(self) -> AsyncIterator[RecommendationFolde
479479
yield RecommendationFolder(
480480
item_id=f"{self.provider.instance_id}_chart_top_tracks",
481481
name="Global Top Tracks",
482-
translation_key="recommendations.global_top_tracks",
482+
translation_key="global_top_tracks",
483483
provider=self.provider.instance_id,
484484
items=UniqueList(top_tracks),
485485
subtitle="Most popular tracks worldwide",

music_assistant/providers/opensubsonic/sonic_provider.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ async def _podcast_recommendations(self) -> RecommendationFolder:
831831
item_id="subsonic_newest_podcasts",
832832
provider=self.domain,
833833
name="Newest Podcast Episodes",
834-
translation_key="recommendations.episodes_recently_added",
834+
translation_key="episodes_recently_added",
835835
)
836836
sonic_episodes = await self.conn.get_newest_podcasts(count=self._reco_limit)
837837
for ep in sonic_episodes:
@@ -868,7 +868,7 @@ async def _new_recommendations(self) -> RecommendationFolder:
868868
item_id="subsonic_new_albums",
869869
provider=self.domain,
870870
name="New Albums",
871-
translation_key="recommendations.recently_added_albums",
871+
translation_key="recently_added_albums",
872872
)
873873
new_albums = await self.conn.get_album_list2(ltype="newest", size=self._reco_limit)
874874
for sonic_album in new_albums:
@@ -880,7 +880,7 @@ async def _played_recommendations(self) -> RecommendationFolder:
880880
item_id="subsonic_most_played",
881881
provider=self.domain,
882882
name="Most Played Albums",
883-
translation_key="recommendations.most_played_albums",
883+
translation_key="most_played_albums",
884884
)
885885
albums = await self.conn.get_album_list2(ltype="frequent", size=self._reco_limit)
886886
for sonic_album in albums:

0 commit comments

Comments
 (0)