From 5d517fb3dd659d51b027134d9f05dd615d4242e5 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Sat, 7 Sep 2024 12:02:19 +0200 Subject: [PATCH] Fix saving Invidious thumbnail URLs for subscriptions --- .../subscriptions-community.js | 8 ++------ src/renderer/store/modules/profiles.js | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/renderer/components/subscriptions-community/subscriptions-community.js b/src/renderer/components/subscriptions-community/subscriptions-community.js index 59df38efcb57..86c81c6ecc1a 100644 --- a/src/renderer/components/subscriptions-community/subscriptions-community.js +++ b/src/renderer/components/subscriptions-community/subscriptions-community.js @@ -164,12 +164,8 @@ export default defineComponent({ let thumbnailUrl = post.authorThumbnails?.[0]?.url if (name || thumbnailUrl) { - if (thumbnailUrl) { - if (thumbnailUrl.startsWith('//')) { - thumbnailUrl = 'https:' + thumbnailUrl - } else if (thumbnailUrl.startsWith(`${this.currentInvidiousInstanceUrl}/ggpht`)) { - thumbnailUrl = thumbnailUrl.replace(`${this.currentInvidiousInstanceUrl}/ggpht`, 'https://yt3.googleusercontent.com') - } + if (thumbnailUrl?.startsWith('//')) { + thumbnailUrl = 'https:' + thumbnailUrl } subscriptionUpdates.push({ diff --git a/src/renderer/store/modules/profiles.js b/src/renderer/store/modules/profiles.js index 70ca26b8aaa1..9e55e61e3f95 100644 --- a/src/renderer/store/modules/profiles.js +++ b/src/renderer/store/modules/profiles.js @@ -113,7 +113,11 @@ const actions = { } if (channelThumbnailUrl) { - const thumbnail = channelThumbnailUrl.replace(/=s\d*/, '=s176') // change thumbnail size if different + const thumbnail = channelThumbnailUrl + // change thumbnail size if different + .replace(/=s\d*/, '=s176') + // If this is an Invidious URL, convert it to a YouTube one + .replace(/^https?:\/\/[^/]+\/ggpht/, 'https://yt3.googleusercontent.com') if (channel.thumbnail !== thumbnail) { channel.thumbnail = thumbnail @@ -129,7 +133,12 @@ const actions = { }, async updateSubscriptionDetails({ dispatch, state }, { channelThumbnailUrl, channelName, channelId }) { - const thumbnail = channelThumbnailUrl?.replace(/=s\d*/, '=s176') ?? null // change thumbnail size if different + const thumbnail = channelThumbnailUrl + // change thumbnail size if different + ?.replace(/=s\d*/, '=s176') + // If this is an Invidious URL, convert it to a YouTube one + .replace(/^https?:\/\/[^/]+\/ggpht/, 'https://yt3.googleusercontent.com') ?? + null const profileList = state.profileList for (const profile of profileList) { const currentProfileCopy = deepCopy(profile) @@ -173,6 +182,11 @@ const actions = { }, async addChannelToProfiles({ commit }, { channel, profileIds }) { + // If this is an Invidious URL, convert it to a YouTube one + if (!channel.thumbnail.startsWith('https://yt3.googleusercontent.com/')) { + channel.thumbnail = channel.thumbnail.replace(/^https?:\/\/[^/]+\/ggpht/, 'https://yt3.googleusercontent.com') + } + try { await DBProfileHandlers.addChannelToProfiles(channel, profileIds) commit('addChannelToProfiles', { channel, profileIds })