Localization inconsistency fix for Local API (#2535)

* Applying a workaround for localization issue

This changes where the title comes from on the response object from ytdl.
This is related to FreeTubeApp#2530.

* Applying the same workaround on the description

* Added a fallback to videoDetails

* Adding a console error to the title try block

Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>

* Simplifying a loop to Array.join

Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>

* Adding a console error to the description try block

Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>

* Add a map for the description lines

Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>

* Added a question mark operator for descriptions

This should prevent errors from erroneously being thrown on videos
which have a blank description. If the description is undefined or does
not contain a 'runs' field, the resulting descriptionLines should be
and empty array. Then, videoDescription will be an empty string.

* Each line already contains a `\n`

Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>
This commit is contained in:
Emma 2022-09-09 13:39:56 -04:00 committed by GitHub
parent efc5477563
commit 77470751c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 3 deletions

View File

@ -275,8 +275,14 @@ export default Vue.extend({
throw new Error(`${reason}: ${subReason}`)
}
this.videoTitle = result.videoDetails.title
try {
// workaround for title localization
this.videoTitle = result.response.contents.twoColumnWatchNextResults.results.results.contents[0].videoPrimaryInfoRenderer.title.runs[0].text
} catch (err) {
console.error('Failed to extract localised video title, falling back to the standard one.', err)
// if the workaround for localization fails, this sets the title to the potentially non-localized value
this.videoTitle = result.videoDetails.title
}
this.videoViewCount = parseInt(
result.player_response.videoDetails.viewCount,
10
@ -300,7 +306,15 @@ export default Vue.extend({
})
this.videoPublished = new Date(result.videoDetails.publishDate.replace('-', '/')).getTime()
this.videoDescription = result.player_response.videoDetails.shortDescription
try {
// workaround for description localization
const descriptionLines = result.response.contents.twoColumnWatchNextResults.results.results.contents[1].videoSecondaryInfoRenderer.description?.runs
this.videoDescription = descriptionLines?.map(line => line.text).join('') ?? ''
} catch (err) {
console.error('Failed to extract localised video description, falling back to the standard one.', err)
// if the workaround for localization fails, this sets the description to the potentially non-localized value
this.videoDescription = result.player_response.videoDetails.shortDescription
}
switch (this.thumbnailPreference) {
case 'start':