From 9612924cb8a6810ae06e50daa130a001f12e877b Mon Sep 17 00:00:00 2001
From: absidue <48293849+absidue@users.noreply.github.com>
Date: Fri, 28 Jun 2024 18:27:09 +0200
Subject: [PATCH] feat(toDash): Add the "dub" role to translated captions

---
 src/utils/DashManifest.tsx | 12 ++++++++----
 src/utils/StreamingInfo.ts |  8 ++++++++
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/utils/DashManifest.tsx b/src/utils/DashManifest.tsx
index 5c0620450..155c58c99 100644
--- a/src/utils/DashManifest.tsx
+++ b/src/utils/DashManifest.tsx
@@ -241,10 +241,14 @@ async function DashManifest({
             lang={set.language}
             contentType="text"
           >
-            <role
-              schemeIdUri="urn:mpeg:dash:role:2011"
-              value="caption"
-            />
+            {
+              set.track_roles.map((role) => (
+                <role
+                  schemeIdUri="urn:mpeg:dash:role:2011"
+                  value={role}
+                />
+              ))
+            }
             <label id={index + audio_sets.length}>
               {set.track_name}
             </label>
diff --git a/src/utils/StreamingInfo.ts b/src/utils/StreamingInfo.ts
index a56785c61..5f09cdd1b 100644
--- a/src/utils/StreamingInfo.ts
+++ b/src/utils/StreamingInfo.ts
@@ -128,6 +128,7 @@ export interface TextSet {
   mime_type: string;
   language: string;
   track_name: string;
+  track_roles: ('caption' | 'dub')[];
   representation: TextRepresentation;
 }
 
@@ -760,10 +761,17 @@ function getTextSets(
     const url = new URL(caption_track.base_url);
     url.searchParams.set('fmt', format);
 
+    const track_roles: ('caption' | 'dub')[] = [ 'caption' ];
+
+    if (url.searchParams.has('tlang')) {
+      track_roles.push('dub');
+    }
+
     return {
       mime_type,
       language: caption_track.language_code,
       track_name: caption_track.name.toString(),
+      track_roles,
       representation: {
         uid: `text-${caption_track.vss_id}`,
         base_url: transform_url(url).toString()