From 3b4ee5990f16519653d7117c0940d26893d5b07d Mon Sep 17 00:00:00 2001 From: chunky programmer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Mon, 8 May 2023 21:09:16 -0400 Subject: [PATCH] fix comment and playlist fallbacks --- .../ft-profile-channel-list.js | 6 +- .../ft-profile-filter-channels-list.js | 6 +- .../player-settings/player-settings.js | 6 +- .../watch-video-comments.js | 113 +++++++++++++----- .../watch-video-playlist.js | 4 +- src/renderer/views/Playlist/Playlist.js | 68 ++++++++--- .../SubscribedChannels/SubscribedChannels.js | 6 +- static/locales/en-US.yaml | 1 + 8 files changed, 157 insertions(+), 53 deletions(-) diff --git a/src/renderer/components/ft-profile-channel-list/ft-profile-channel-list.js b/src/renderer/components/ft-profile-channel-list/ft-profile-channel-list.js index 799251819..b47b74fe3 100644 --- a/src/renderer/components/ft-profile-channel-list/ft-profile-channel-list.js +++ b/src/renderer/components/ft-profile-channel-list/ft-profile-channel-list.js @@ -41,7 +41,11 @@ export default defineComponent({ }, computed: { backendPreference: function () { - return this.$store.getters.getBackendPreference + let preference = this.$store.getters.getBackendPreference + if (preference === 'piped') { + preference = this.$store.getters.getFallbackPreference + } + return preference }, currentInvidiousInstance: function () { return this.$store.getters.getCurrentInvidiousInstance diff --git a/src/renderer/components/ft-profile-filter-channels-list/ft-profile-filter-channels-list.js b/src/renderer/components/ft-profile-filter-channels-list/ft-profile-filter-channels-list.js index ece62f7ac..23ebcd18c 100644 --- a/src/renderer/components/ft-profile-filter-channels-list/ft-profile-filter-channels-list.js +++ b/src/renderer/components/ft-profile-filter-channels-list/ft-profile-filter-channels-list.js @@ -33,7 +33,11 @@ export default defineComponent({ }, computed: { backendPreference: function () { - return this.$store.getters.getBackendPreference + let preference = this.$store.getters.getBackendPreference + if (preference === 'piped') { + preference = this.$store.getters.getFallbackPreference + } + return preference }, currentInvidiousInstance: function () { return this.$store.getters.getCurrentInvidiousInstance diff --git a/src/renderer/components/player-settings/player-settings.js b/src/renderer/components/player-settings/player-settings.js index 54611a59f..f1e5d8cfe 100644 --- a/src/renderer/components/player-settings/player-settings.js +++ b/src/renderer/components/player-settings/player-settings.js @@ -62,7 +62,11 @@ export default defineComponent({ }, computed: { backendPreference: function () { - return this.$store.getters.getBackendPreference + let preference = this.$store.getters.getBackendPreference + if (preference === 'piped') { + preference = this.$store.getters.getFallbackPreference + } + return preference }, autoplayVideos: function () { diff --git a/src/renderer/components/watch-video-comments/watch-video-comments.js b/src/renderer/components/watch-video-comments/watch-video-comments.js index 37b2d5009..38c3db3c0 100644 --- a/src/renderer/components/watch-video-comments/watch-video-comments.js +++ b/src/renderer/components/watch-video-comments/watch-video-comments.js @@ -44,15 +44,15 @@ export default defineComponent({ }, computed: { backendPreference: function () { - let preference = this.$store.getters.getBackendPreference - if (preference === 'piped') { - preference = this.$store.getters.getFallbackPreference - } - return preference + return this.$store.getters.getBackendPreference + }, + + fallbackPreference: function () { + return this.$store.getters.getFallbackPreference }, backendFallback: function () { - return this.$store.getters.getBackendFallback && this.$store.getters.getBackendPreference !== 'piped' + return this.$store.getters.getBackendFallback }, hideCommentLikes: function () { @@ -207,8 +207,13 @@ export default defineComponent({ copyToClipboard(err) }) if (this.backendFallback && this.backendPreference === 'local') { - showToast(this.$t('Falling back to Invidious API')) - this.getCommentDataInvidious() + if (this.fallbackPreference === 'invidious') { + showToast(this.$t('Falling back to Invidious API')) + this.getCommentDataInvidious() + } else if (this.fallbackPreference === 'piped') { + showToast(this.$t('Falling back to Piped API')) + this.getCommentDataPiped() + } } else { this.isLoading = false } @@ -240,8 +245,13 @@ export default defineComponent({ copyToClipboard(err) }) if (this.backendFallback && this.backendPreference === 'local') { - showToast(this.$t('Falling back to Invidious API')) - this.getCommentDataInvidious() + if (this.fallbackPreference === 'invidious') { + showToast(this.$t('Falling back to Invidious API')) + this.getCommentDataInvidious() + } else if (this.fallbackPreference === 'piped') { + showToast(this.$t('Falling back to Piped API')) + this.getCommentDataPiped() + } } else { this.isLoading = false } @@ -249,27 +259,65 @@ export default defineComponent({ }, getCommentDataPiped: async function () { - const { comments, continuation } = await getPipedComments(this.id) - this.commentData = comments - this.nextPageToken = continuation - this.isLoading = false - this.showComments = true + try { + const { comments, continuation } = await getPipedComments(this.id) + this.commentData = comments + this.nextPageToken = continuation + this.isLoading = false + this.showComments = true + } catch (err) { + console.error(err) + const errorMessage = this.$t('Piped API Error (Click to copy)') + showToast(`${errorMessage}: ${err}`, 10000, () => { + copyToClipboard(err) + }) + if (this.backendFallback && this.backendPreference === 'piped') { + if (this.fallbackPreference === 'invidious') { + showToast(this.$t('Falling back to Invidious API')) + this.getCommentDataInvidious() + } else if (process.env.IS_ELECTRON && this.fallbackPreference === 'local') { + showToast(this.$t('Falling back to local API')) + this.getCommentDataLocal() + } + } else { + this.isLoading = false + } + } }, getCommentDataPipedMore: async function(token, index = null) { - const { comments, continuation } = await getPipedCommentsMore({ - videoId: this.id, - continuation: token - }) - if (index !== null) { - this.commentData[index].replies = this.commentData[index].replies.concat(comments) - this.commentData[index].showReplies = true - this.commentData[index].replyToken = continuation - } else { - this.commentData = this.commentData.concat(comments) - this.nextPageToken = continuation + try { + const { comments, continuation } = await getPipedCommentsMore({ + videoId: this.id, + continuation: token + }) + if (index !== null) { + this.commentData[index].replies = this.commentData[index].replies.concat(comments) + this.commentData[index].showReplies = true + this.commentData[index].replyToken = continuation + } else { + this.commentData = this.commentData.concat(comments) + this.nextPageToken = continuation + } + this.isLoading = false + } catch (err) { + console.error(err) + const errorMessage = this.$t('Piped API Error (Click to copy)') + showToast(`${errorMessage}: ${err}`, 10000, () => { + copyToClipboard(err) + }) + if (this.backendFallback && this.backendPreference === 'piped') { + if (this.fallbackPreference === 'invidious') { + showToast(this.$t('Falling back to Invidious API')) + this.getCommentDataInvidious() + } else if (process.env.IS_ELECTRON && this.fallbackPreference === 'local') { + showToast(this.$t('Falling back to local API')) + this.getCommentDataLocal() + } + } else { + this.isLoading = false + } } - this.isLoading = false }, getCommentDataInvidious: function () { @@ -288,9 +336,14 @@ export default defineComponent({ showToast(`${errorMessage}: ${xhr.responseText}`, 10000, () => { copyToClipboard(xhr.responseText) }) - if (process.env.IS_ELECTRON && this.backendFallback && this.backendPreference === 'invidious') { - showToast(this.$t('Falling back to local API')) - this.getCommentDataLocal() + if (this.backendFallback && this.backendPreference === 'invidious') { + if (this.fallbackPreference === 'piped') { + showToast(this.$t('Falling back to Piped API')) + this.getCommentDataPiped() + } else if (process.env.IS_ELECTRON && this.fallbackPreference === 'local') { + showToast(this.$t('Falling back to local API')) + this.getCommentDataLocal() + } } else { this.isLoading = false } diff --git a/src/renderer/components/watch-video-playlist/watch-video-playlist.js b/src/renderer/components/watch-video-playlist/watch-video-playlist.js index 47ab4504c..d1b861945 100644 --- a/src/renderer/components/watch-video-playlist/watch-video-playlist.js +++ b/src/renderer/components/watch-video-playlist/watch-video-playlist.js @@ -398,9 +398,11 @@ export default defineComponent({ if (this.fallbackPreference === 'invidious') { showToast(this.$t('Falling back to Invidious API')) this.getPlaylistInformationInvidious() - } else { + } else if (process.env.IS_ELECTRON && this.fallbackPreference === 'local') { showToast(this.$t('Falling back to Piped API')) this.getPlaylistInformationLocal() + } else { + this.isLoading = false } } else { this.isLoading = false diff --git a/src/renderer/views/Playlist/Playlist.js b/src/renderer/views/Playlist/Playlist.js index 8953b65ef..efac4419f 100644 --- a/src/renderer/views/Playlist/Playlist.js +++ b/src/renderer/views/Playlist/Playlist.js @@ -45,8 +45,10 @@ export default defineComponent({ }, computed: { backendPreference: function () { - return 'piped' - // return this.$store.getters.getBackendPreference + return this.$store.getters.getBackendPreference + }, + fallbackPreference: function () { + return this.$store.getters.getFallbackPreference }, backendFallback: function () { return this.$store.getters.getBackendFallback @@ -117,8 +119,13 @@ export default defineComponent({ }).catch((err) => { console.error(err) if (this.backendPreference === 'local' && this.backendFallback) { - console.warn('Falling back to Invidious API') - this.getPlaylistInvidious() + if (this.fallbackPreference === 'invidious') { + console.warn('Falling back to Invidious API') + this.getPlaylistInvidious() + } else { + console.warn('Falling back to Piped API') + this.getPlaylistPiped() + } } else { this.isLoading = false } @@ -156,9 +163,16 @@ export default defineComponent({ this.isLoading = false }).catch((err) => { console.error(err) - if (process.env.IS_ELECTRON && this.backendPreference === 'invidious' && this.backendFallback) { - console.warn('Error getting data with Invidious, falling back to local backend') - this.getPlaylistLocal() + if (this.backendPreference === 'invidious' && this.backendFallback) { + if (process.env.IS_ELECTRON && this.fallbackPreference === 'local') { + console.warn('Error getting data with Invidious, falling back to local backend') + this.getPlaylistLocal() + } else if (this.fallbackPreference === 'piped') { + console.warn('Error getting data with Invidious, falling back to Piped backend') + this.getPlaylistPiped() + } else { + this.isLoading = false + } } else { this.isLoading = false // TODO: Show toast with error message @@ -167,18 +181,36 @@ export default defineComponent({ }, getPlaylistPiped: async function () { - this.isLoading = true - const { playlist, videos, nextpage } = await getPipedPlaylist(this.playlistId) - this.infoData = playlist - this.continuationData = nextpage - this.playlistItems = this.playlistItems.concat(videos) + try { + this.isLoading = true + const { playlist, videos, nextpage } = await getPipedPlaylist(this.playlistId) + this.infoData = playlist + this.continuationData = nextpage + this.playlistItems = this.playlistItems.concat(videos) - this.updateSubscriptionDetails({ - channelThumbnailUrl: pipedImageToYouTube(playlist.channelThumbnail), - channelName: playlist.channelName, - channelId: playlist.channelId - }) - this.isLoading = false + this.updateSubscriptionDetails({ + channelThumbnailUrl: pipedImageToYouTube(playlist.channelThumbnail), + channelName: playlist.channelName, + channelId: playlist.channelId + }) + this.isLoading = false + } catch (err) { + console.error(err) + if (this.backendPreference === 'invidious' && this.backendFallback) { + if (process.env.IS_ELECTRON && this.fallbackPreference === 'local') { + console.warn('Error getting data with Piped, falling back to local backend') + this.getPlaylistLocal() + } else if (this.fallbackPreference === 'invidious') { + console.warn('Error getting data with Piped, falling back to Invidious backend') + this.getPlaylistPiped() + } else { + this.isLoading = false + } + } else { + this.isLoading = false + // TODO: Show toast with error message + } + } }, getNextPage: function () { diff --git a/src/renderer/views/SubscribedChannels/SubscribedChannels.js b/src/renderer/views/SubscribedChannels/SubscribedChannels.js index 0ca0ebe39..d125a7263 100644 --- a/src/renderer/views/SubscribedChannels/SubscribedChannels.js +++ b/src/renderer/views/SubscribedChannels/SubscribedChannels.js @@ -59,7 +59,11 @@ export default defineComponent({ }, backendPreference: function () { - return this.$store.getters.getBackendPreference + let preference = this.$store.getters.getBackendPreference + if (preference === 'piped') { + preference = this.$store.getters.getFallbackPreference + } + return preference }, currentInvidiousInstance: function () { diff --git a/static/locales/en-US.yaml b/static/locales/en-US.yaml index 01f4cb2b8..9763db2a2 100644 --- a/static/locales/en-US.yaml +++ b/static/locales/en-US.yaml @@ -848,6 +848,7 @@ Tooltips: # Toast Messages Local API Error (Click to copy): Local API Error (Click to copy) Invidious API Error (Click to copy): Invidious API Error (Click to copy) +Piped API Error (Click to copy): Piped API Error (Click to copy) Falling back to Invidious API: Falling back to Invidious API Falling back to Piped API: Falling back to Piped API Falling back to the local API: Falling back to the local API