Allows selecting the audio language in the MPD manifest proxy. - #283
Allows selecting the audio language in the MPD manifest proxy.#283andrestardito wants to merge 1 commit into
Conversation
WalkthroughAdds an Changesaudio_lang selection for DASH/MPD proxying
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@mediaflow_proxy/mpd_processor.py`:
- Around line 492-493: The language matching logic at line 492 uses a simple
startswith comparison that fails to handle case-insensitive matching and
hierarchical BCP-47 language tag matching. To fix this, normalize both the
audio_lang parameter and the profile language code to lowercase for comparison,
then implement a three-tier matching strategy: first filter default_audio to
include profiles that exactly match the normalized audio_lang, then also include
profiles whose primary language component (before the hyphen) matches the
audio_lang primary component, and finally fall back to bandwidth selection from
the combined list. This ensures that a request for audio_lang like "es-AR"
properly matches both exact "es-ar" tracks and generic "es" tracks before using
bandwidth as a tiebreaker.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d6374e9d-8b34-4449-9313-a105d5c73ca3
📒 Files selected for processing (6)
docs/usage/examples.mddocs/usage/url-params-and-encoding.mdmediaflow_proxy/handlers.pymediaflow_proxy/mpd_processor.pymediaflow_proxy/schemas.pymediaflow_proxy/static/url_generator.html
| default_audio = [(p, u) for p, u in all_audio if (p.get("lang") or "").startswith(audio_lang)] | ||
| default_profile, _ = max(default_audio or all_audio, key=lambda pu: pu[0].get("bandwidth", 0)) |
There was a problem hiding this comment.
Regional language requests can select the wrong default audio.
Line 492 only checks profile_lang.startswith(audio_lang), so audio_lang=es-AR will not match a generic es track and may fall back to a different language by bandwidth. Normalize case and implement hierarchical BCP-47 matching (exact → primary-language compatible → bandwidth fallback).
💡 Suggested fix
- default_audio = [(p, u) for p, u in all_audio if (p.get("lang") or "").startswith(audio_lang)]
+ req_lang = (audio_lang or "en").strip().lower()
+ req_primary = req_lang.split("-")[0]
+
+ def _lang_match(profile_lang: str) -> tuple[int, int]:
+ # score: 2 exact, 1 primary-language compatible, 0 no match
+ pl = (profile_lang or "").strip().lower()
+ if pl == req_lang:
+ return (2, 0)
+ pl_primary = pl.split("-")[0] if pl else ""
+ if pl and (pl.startswith(req_lang + "-") or req_lang.startswith(pl + "-") or pl_primary == req_primary):
+ return (1, 0)
+ return (0, 0)
+
+ scored = [
+ (p, u, _lang_match(p.get("lang")))
+ for p, u in all_audio
+ ]
+ matched = [(p, u) for p, u, score in scored if score[0] > 0]
+ default_audio = matched🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@mediaflow_proxy/mpd_processor.py` around lines 492 - 493, The language
matching logic at line 492 uses a simple startswith comparison that fails to
handle case-insensitive matching and hierarchical BCP-47 language tag matching.
To fix this, normalize both the audio_lang parameter and the profile language
code to lowercase for comparison, then implement a three-tier matching strategy:
first filter default_audio to include profiles that exactly match the normalized
audio_lang, then also include profiles whose primary language component (before
the hyphen) matches the audio_lang primary component, and finally fall back to
bandwidth selection from the combined list. This ensures that a request for
audio_lang like "es-AR" properly matches both exact "es-ar" tracks and generic
"es" tracks before using bandwidth as a tiebreaker.
This change was introduced to avoid the need for users to repeatedly select their preferred audio track in the player. This is especially useful when English is not the users' primary language.
Summary by CodeRabbit
New Features
Documentation