From 77470751c3d49b2e2d56808b85d39b487a0d2ca4 Mon Sep 17 00:00:00 2001 From: Emma Date: Fri, 9 Sep 2022 13:39:56 -0400 Subject: [PATCH] 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> --- src/renderer/views/Watch/Watch.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/renderer/views/Watch/Watch.js b/src/renderer/views/Watch/Watch.js index db3435d3..f18e9808 100644 --- a/src/renderer/views/Watch/Watch.js +++ b/src/renderer/views/Watch/Watch.js @@ -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':