Skip to content

Commit 4c644ad

Browse files
authored
Trim video titles with the local API to avoid breaking the databases (#8354)
1 parent 21b940b commit 4c644ad

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/renderer/helpers/api/local.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ export function parseShort(short, channelId, channelName) {
11101110
return {
11111111
type: 'video',
11121112
videoId: reelItem.id,
1113-
title: reelItem.title.text,
1113+
title: reelItem.title.text?.trim(),
11141114
author: channelName,
11151115
authorId: channelId,
11161116
viewCount: reelItem.views.isEmpty() ? null : parseLocalSubscriberCount(reelItem.views.text),
@@ -1123,7 +1123,7 @@ export function parseShort(short, channelId, channelName) {
11231123
return {
11241124
type: 'video',
11251125
videoId: shortsLockupView.on_tap_endpoint.payload.videoId,
1126-
title: shortsLockupView.overlay_metadata.primary_text.text,
1126+
title: shortsLockupView.overlay_metadata.primary_text.text?.trim(),
11271127
author: channelName,
11281128
authorId: channelId,
11291129
viewCount: shortsLockupView.overlay_metadata.secondary_text ? parseLocalSubscriberCount(shortsLockupView.overlay_metadata.secondary_text.text) : null,
@@ -1318,7 +1318,7 @@ export function parseLocalPlaylistVideo(video) {
13181318
return {
13191319
type: 'video',
13201320
videoId: short.id,
1321-
title: short.title.text,
1321+
title: short.title.text?.trim(),
13221322
viewCount: parseLocalSubscriberCount(short.views.text),
13231323
lengthSeconds: ''
13241324
}
@@ -1354,7 +1354,7 @@ export function parseLocalPlaylistVideo(video) {
13541354
return {
13551355
type: 'video',
13561356
videoId: shortsLockupView.on_tap_endpoint.payload.videoId,
1357-
title: shortsLockupView.overlay_metadata.primary_text.text,
1357+
title: shortsLockupView.overlay_metadata.primary_text.text?.trim(),
13581358
viewCount,
13591359
lengthSeconds: ''
13601360
}
@@ -1400,7 +1400,7 @@ export function parseLocalPlaylistVideo(video) {
14001400
return {
14011401
type: 'video',
14021402
videoId: video_.id,
1403-
title: video_.title.text,
1403+
title: video_.title.text?.trim(),
14041404
author: video_.author.name,
14051405
authorId: (video_.author?.id != null && video_.author.id !== 'N/A') ? video_.author.id : null,
14061406
viewCount,
@@ -1426,7 +1426,7 @@ export function parseLocalListVideo(item, channelId, channelName) {
14261426
return {
14271427
type: 'video',
14281428
videoId: movie.id,
1429-
title: movie.title.text,
1429+
title: movie.title.text?.trim(),
14301430
author: movie.author.name !== 'N/A' ? movie.author.name : channelName,
14311431
authorId: movie.author.id !== 'N/A' ? movie.author.id : channelId,
14321432
description: movie.description_snippet?.text,
@@ -1456,7 +1456,7 @@ export function parseLocalListVideo(item, channelId, channelName) {
14561456
return {
14571457
type: 'video',
14581458
videoId: video.video_id,
1459-
title: video.title.text,
1459+
title: video.title.text?.trim(),
14601460
author: video.author?.name ?? channelName,
14611461
authorId: (video.author?.id != null && video.author.id !== 'N/A') ? video.author.id : channelId,
14621462
viewCount: video.views.text == null ? null : extractNumberFromString(video.views.text),
@@ -1507,7 +1507,7 @@ export function parseLocalListVideo(item, channelId, channelName) {
15071507
return {
15081508
type: 'video',
15091509
videoId: video.video_id,
1510-
title: video.title.text,
1510+
title: video.title.text?.trim(),
15111511
author: video.author.name !== 'N/A' ? video.author.name : channelName,
15121512
authorId: video.author.id !== 'N/A' ? video.author.id : channelId,
15131513
description: video.description,
@@ -1616,7 +1616,7 @@ function parseLockupView(lockupView, channelId = undefined, channelName = undefi
16161616
return {
16171617
type: 'video',
16181618
videoId: lockupView.content_id,
1619-
title: lockupView.metadata.title.text,
1619+
title: lockupView.metadata.title.text?.trim(),
16201620
author: lockupView.metadata.metadata?.metadata_rows[0].metadata_parts?.[0].text?.text,
16211621
authorId: lockupView.metadata.image?.renderer_context?.command_context?.on_tap?.payload.browseId,
16221622
viewCount,
@@ -1756,7 +1756,7 @@ export function parseLocalWatchNextVideo(video) {
17561756
return {
17571757
type: 'video',
17581758
videoId: video.id,
1759-
title: video.title.text,
1759+
title: video.title.text?.trim(),
17601760
author: video.author.name,
17611761
authorId: video.author.id,
17621762
lengthSeconds: video.duration.seconds
@@ -1775,7 +1775,7 @@ export function parseLocalWatchNextVideo(video) {
17751775
return {
17761776
type: 'video',
17771777
videoId: video.video_id,
1778-
title: video.title.text,
1778+
title: video.title.text?.trim(),
17791779
author: video.author.name,
17801780
authorId: video.author.id,
17811781
viewCount: video.view_count == null ? null : extractNumberFromString(video.view_count.text),

src/renderer/views/Watch/Watch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ export default defineComponent({
457457
}
458458

459459
// extract localised title first and fall back to the not localised one
460-
this.videoTitle = result.primary_info?.title.text ?? result.basic_info.title
460+
this.videoTitle = result.primary_info?.title.text?.trim() ?? result.basic_info.title?.trim()
461461
this.videoViewCount = result.basic_info.view_count ?? (result.primary_info.view_count ? extractNumberFromString(result.primary_info.view_count.text) : null)
462462
this.license = result.secondary_info.metadata.rows.find(element => element.title?.text === 'License')?.contents[0]?.text
463463

0 commit comments

Comments
 (0)