From e8d6fadd9c4847345f996cb35b3fa65ae39516cd Mon Sep 17 00:00:00 2001 From: IanDesuyo <59338745+IanDesuyo@users.noreply.github.com> Date: Sat, 4 Jan 2025 18:23:20 +0000 Subject: [PATCH] Update language code and name formatting --- extension/src/pages/youtube-page.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/extension/src/pages/youtube-page.ts b/extension/src/pages/youtube-page.ts index 0920ebf5..447680d6 100644 --- a/extension/src/pages/youtube-page.ts +++ b/extension/src/pages/youtube-page.ts @@ -45,19 +45,22 @@ const appendTranslatedTracks = (tracks: any, tlang: string) => { for (const track of tracks) { // Ignore subtitles that are already in the target language if (track.languageCode !== tlang) { - const translatedTrack = { + const translatedTrack = { ...track, - languageCode:`${track.languageCode} >> ${tlang}`, - baseUrl: `${track.baseUrl}&tlang=${tlang}` // YouTube API param for translation + name: { + simpleText: `${track.name?.simpleText} >> ${tlang}`, + runs: track.name?.runs?.map((run: any) => ({ ...run, text: `${run.text} >> ${tlang}` })), + }, + languageCode: tlang, + baseUrl: `${track.baseUrl}&tlang=${tlang}`, // YouTube API param for translation }; translatedTracks.push(translatedTrack); } } - return translatedTracks; -} +}; document.addEventListener( 'asbplayer-get-synced-data', @@ -111,9 +114,10 @@ document.addEventListener( } response.basename = playerContext.videoDetails?.title || document.title; - response.subtitles = appendTranslatedTracks(playerContext?.captions?.playerCaptionsTracklistRenderer?.captionTracks || [], TLANG).map( - adaptYtTrack - ); + response.subtitles = appendTranslatedTracks( + playerContext?.captions?.playerCaptionsTracklistRenderer?.captionTracks || [], + TLANG + ).map(adaptYtTrack); } catch (error) { if (error instanceof Error) { response.error = error.message;