Skip to content

Commit

Permalink
Use Intl.DisplayNames to get the language names
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue committed Sep 9, 2023
1 parent 03b6183 commit 5fd1059
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/renderer/views/Watch/Watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -1459,8 +1459,10 @@ export default defineComponent({
}

if (hasMultipleAudioTracks) {
// match YouTube's local API response with English
const languageNames = new Intl.DisplayNames('en-US', { type: 'language' })
for (const format of audioFormats) {
this.generateAudioTrackFieldInvidious(format)
this.generateAudioTrackFieldInvidious(format, languageNames)
}

this.audioTracks = this.createAudioTracksFromLocalFormats(audioFormats)
Expand Down Expand Up @@ -1488,31 +1490,34 @@ export default defineComponent({

/**
* @param {import('youtubei.js').Misc.Format} format
* @param {Intl.DisplayNames} languageNames
*/
generateAudioTrackFieldInvidious: function (format) {
generateAudioTrackFieldInvidious: function (format, languageNames) {
let type = ''

// use the same id numbers as YouTube (except -1, when we aren't sure what it is)
let idNumber = ''

if (format.is_descriptive) {
type = 'descriptive'
type = ' descriptive'
idNumber = 2
} else if (format.is_dubbed) {
type = 'dubbed'
type = ''
idNumber = 3
} else if (format.is_original) {
type = 'original'
type = ' original'
idNumber = 4
} else {
type = 'alternative'
type = ' alternative'
idNumber = -1
}

const languageName = languageNames.of(format.language)

format.audio_track = {
audio_is_default: !!format.is_original,
id: `${format.language}.${idNumber}`,
display_name: `${format.language} ${type}`
display_name: `${languageName}${type}`
}
},

Expand Down

0 comments on commit 5fd1059

Please sign in to comment.