From f440a5b38cf10e2bda3897ce1d887688be01ec3f Mon Sep 17 00:00:00 2001 From: Preston Date: Sat, 12 Sep 2020 16:59:49 -0400 Subject: [PATCH] Fix handling when the channel scraper fails --- .../components/data-settings/data-settings.js | 66 +++++++++++++------ static/locales/en-US.yaml | 1 + 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/renderer/components/data-settings/data-settings.js b/src/renderer/components/data-settings/data-settings.js index d097fda5..fbb6b388 100644 --- a/src/renderer/components/data-settings/data-settings.js +++ b/src/renderer/components/data-settings/data-settings.js @@ -247,6 +247,8 @@ export default Vue.extend({ this.updateShowProgressBar(true) this.setProgressBarPercentage(0) + let count = 0 + feedData.forEach(async (channel, index) => { const channelId = channel.xmlurl.replace('https://www.youtube.com/feeds/videos.xml?channel_id=', '') let channelInfo @@ -256,24 +258,35 @@ export default Vue.extend({ channelInfo = await this.getChannelInfoLocal(channelId) } - const subscription = { - id: channelId, - name: channelInfo.author, - thumbnail: channelInfo.authorThumbnails[1].url + if (typeof channelInfo.author !== 'undefined') { + const subscription = { + id: channelId, + name: channelInfo.author, + thumbnail: channelInfo.authorThumbnails[1].url + } + + subscriptions.push(subscription) } - subscriptions.push(subscription) + count++ - const progressPercentage = ((subscriptions.length + 1) / feedData.length) * 100 + const progressPercentage = (count / feedData.length) * 100 this.setProgressBarPercentage(progressPercentage) - if (subscriptions.length === feedData.length) { + if (count === feedData.length) { primaryProfile.subscriptions = primaryProfile.subscriptions.concat(subscriptions) this.updateProfile(primaryProfile) - this.showToast({ - message: this.$t('Settings.Data Settings.All subscriptions have been successfully imported') - }) + if (subscriptions.length < count) { + this.showToast({ + message: this.$t('Settings.Data Settings.One or more subscriptions were unable to be imported') + }) + } else { + this.showToast({ + message: this.$t('Settings.Data Settings.All subscriptions have been successfully imported') + }) + } + this.updateShowProgressBar(false) } }) @@ -331,6 +344,8 @@ export default Vue.extend({ this.updateShowProgressBar(true) this.setProgressBarPercentage(0) + let count = 0 + newPipeSubscriptions.forEach(async (channel, index) => { const channelId = channel.url.replace(/https:\/\/(www\.)?youtube\.com\/channel\//, '') let channelInfo @@ -340,24 +355,35 @@ export default Vue.extend({ channelInfo = await this.getChannelInfoLocal(channelId) } - const subscription = { - id: channelId, - name: channelInfo.author, - thumbnail: channelInfo.authorThumbnails[1].url + if (typeof channelInfo.author !== 'undefined') { + const subscription = { + id: channelId, + name: channelInfo.author, + thumbnail: channelInfo.authorThumbnails[1].url + } + + subscriptions.push(subscription) } - subscriptions.push(subscription) + count++ - const progressPercentage = ((subscriptions.length + 1) / newPipeSubscriptions.length) * 100 + const progressPercentage = (count / newPipeSubscriptions.length) * 100 this.setProgressBarPercentage(progressPercentage) - if (subscriptions.length === newPipeSubscriptions.length) { + if (count === newPipeSubscriptions.length) { primaryProfile.subscriptions = primaryProfile.subscriptions.concat(subscriptions) this.updateProfile(primaryProfile) - this.showToast({ - message: this.$t('Settings.Data Settings.All subscriptions have been successfully imported') - }) + if (subscriptions.length < count) { + this.showToast({ + message: this.$t('Settings.Data Settings.One or more subscriptions were unable to be imported') + }) + } else { + this.showToast({ + message: this.$t('Settings.Data Settings.All subscriptions have been successfully imported') + }) + } + this.updateShowProgressBar(false) } }) diff --git a/static/locales/en-US.yaml b/static/locales/en-US.yaml index 4fcd12db..03336545 100644 --- a/static/locales/en-US.yaml +++ b/static/locales/en-US.yaml @@ -202,6 +202,7 @@ Settings: Profile object has insufficient data, skipping item: Profile object has insufficient data, skipping item All subscriptions and profiles have been successfully imported: All subscriptions and profiles have been successfully imported All subscriptions have been successfully imported: All subscriptions have been successfully imported + One or more subscriptions were unable to be imported: One or more subscriptions were unable to be imported Invalid subscriptions file: Invalid subscriptions file This might take a while, please wait: This might take a while, please wait Invalid history file: Invalid history file