From 4fb28c22e92611ba357efc0fcfc74dc6a74c3757 Mon Sep 17 00:00:00 2001 From: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Thu, 12 Sep 2024 00:22:36 -0400 Subject: [PATCH 1/2] Use constants for api names --- src/constants.js | 30 +++--- src/main/index.js | 3 +- .../ft-community-post/ft-community-post.js | 7 +- .../ft-list-channel/ft-list-channel.js | 3 +- .../ft-list-playlist/ft-list-playlist.js | 5 +- .../components/ft-list-video/ft-list-video.js | 3 +- .../ft-playlist-selector.js | 3 +- .../ft-profile-channel-list.js | 5 +- .../ft-profile-filter-channels-list.js | 6 +- .../general-settings/general-settings.js | 13 +-- .../components/playlist-info/playlist-info.js | 3 +- src/renderer/components/side-nav/side-nav.js | 3 +- .../subscriptions-community.js | 7 +- .../subscriptions-live/subscriptions-live.js | 3 +- .../subscriptions-shorts.js | 3 +- .../subscriptions-videos.js | 3 +- src/renderer/components/top-nav/top-nav.js | 6 +- .../watch-video-comments.js | 11 ++- .../watch-video-live-chat.js | 5 +- .../watch-video-playlist.js | 3 +- src/renderer/helpers/api/invidious.js | 5 +- src/renderer/helpers/api/local.js | 12 +-- src/renderer/helpers/channels.js | 3 +- src/renderer/store/modules/settings.js | 4 +- src/renderer/views/Channel/Channel.js | 93 ++++++++++--------- src/renderer/views/Hashtag/Hashtag.js | 23 ++--- src/renderer/views/Playlist/Playlist.js | 20 ++-- src/renderer/views/Post/Post.js | 3 +- src/renderer/views/Search/Search.js | 22 ++--- .../SubscribedChannels/SubscribedChannels.js | 7 +- src/renderer/views/Trending/Trending.js | 7 +- src/renderer/views/Watch/Watch.js | 11 ++- 32 files changed, 177 insertions(+), 158 deletions(-) diff --git a/src/constants.js b/src/constants.js index 490c8d67771a..a71d961005dc 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,5 +1,5 @@ // IPC Channels -const IpcChannels = { +export const IpcChannels = { ENABLE_PROXY: 'enable-proxy', DISABLE_PROXY: 'disable-proxy', OPEN_EXTERNAL_LINK: 'open-external-link', @@ -40,7 +40,7 @@ const IpcChannels = { SET_INVIDIOUS_AUTHORIZATION: 'set-invidious-authorization' } -const DBActions = { +export const DBActions = { GENERAL: { CREATE: 'db-action-create', FIND: 'db-action-find', @@ -69,7 +69,7 @@ const DBActions = { } } -const SyncEvents = { +export const SyncEvents = { GENERAL: { CREATE: 'sync-create', UPSERT: 'sync-upsert', @@ -94,27 +94,21 @@ const SyncEvents = { } // Utils -const MAIN_PROFILE_ID = 'allChannels' +export const MAIN_PROFILE_ID = 'allChannels' // Width threshold in px at which we switch to using a more heavily altered view for mobile users -const MOBILE_WIDTH_THRESHOLD = 680 +export const MOBILE_WIDTH_THRESHOLD = 680 // Height threshold in px at which we switch to using a more heavily altered playlist view for mobile users -const PLAYLIST_HEIGHT_FORCE_LIST_THRESHOLD = 500 +export const PLAYLIST_HEIGHT_FORCE_LIST_THRESHOLD = 500 // YouTube search character limit is 100 characters -const SEARCH_CHAR_LIMIT = 100 +export const SEARCH_CHAR_LIMIT = 100 // Displayed on the about page and used in the main.js file to only allow bitcoin URLs with this wallet address to be opened -const ABOUT_BITCOIN_ADDRESS = '1Lih7Ho5gnxb1CwPD4o59ss78pwo2T91eS' - -export { - IpcChannels, - DBActions, - SyncEvents, - MAIN_PROFILE_ID, - MOBILE_WIDTH_THRESHOLD, - PLAYLIST_HEIGHT_FORCE_LIST_THRESHOLD, - SEARCH_CHAR_LIMIT, - ABOUT_BITCOIN_ADDRESS, +export const ABOUT_BITCOIN_ADDRESS = '1Lih7Ho5gnxb1CwPD4o59ss78pwo2T91eS' + +export const API_DATA_SOURCES = { + LOCAL_API: 'local', + INVIDIOUS_API: 'invidious' } diff --git a/src/main/index.js b/src/main/index.js index 4cd8cd680a5c..69496519b63d 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -11,6 +11,7 @@ import { DBActions, SyncEvents, ABOUT_BITCOIN_ADDRESS, + API_DATA_SOURCES, } from '../constants' import * as baseHandlers from '../datastores/handlers/base' import { extractExpiryTimestamp, ImageCache } from './ImageCache' @@ -1595,7 +1596,7 @@ function runApp() { }, type: 'normal' }, - (!hidePopularVideos && (backendFallback || backendPreference === 'invidious')) && { + (!hidePopularVideos && (backendFallback || backendPreference === API_DATA_SOURCES.INVIDIOUS_API)) && { label: 'Most Popular', click: (_menuItem, browserWindow, _event) => { navigateTo('/popular', browserWindow) diff --git a/src/renderer/components/ft-community-post/ft-community-post.js b/src/renderer/components/ft-community-post/ft-community-post.js index cbf30691f14f..14153fb0bb32 100644 --- a/src/renderer/components/ft-community-post/ft-community-post.js +++ b/src/renderer/components/ft-community-post/ft-community-post.js @@ -9,6 +9,7 @@ import { A11y, Navigation, Pagination } from 'swiper/modules' import { createWebURL, deepCopy, formatNumber, toLocalePublicationString } from '../../helpers/utils' import { youtubeImageUrlToInvidious } from '../../helpers/api/invidious' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'FtCommunityPost', @@ -71,7 +72,7 @@ export default defineComponent({ return this.$store.getters.getBackendFallback }, isInvidiousAllowed: function() { - return this.backendPreference === 'invidious' || this.backendFallback + return this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API || this.backendFallback } }, created: function () { @@ -111,7 +112,7 @@ export default defineComponent({ this.postText = 'Shared post' this.type = 'text' let authorThumbnails = ['', 'https://yt3.ggpht.com/ytc/AAUvwnjm-0qglHJkAHqLFsCQQO97G7cCNDuDLldsrn25Lg=s88-c-k-c0x00ffffff-no-rj'] - if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') { + if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { authorThumbnails = authorThumbnails.map(thumbnail => { thumbnail.url = youtubeImageUrlToInvidious(thumbnail.url) return thumbnail @@ -122,7 +123,7 @@ export default defineComponent({ } this.postText = autolinker.link(this.data.postText) const authorThumbnails = deepCopy(this.data.authorThumbnails) - if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') { + if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { authorThumbnails.forEach(thumbnail => { thumbnail.url = youtubeImageUrlToInvidious(thumbnail.url) }) diff --git a/src/renderer/components/ft-list-channel/ft-list-channel.js b/src/renderer/components/ft-list-channel/ft-list-channel.js index 709c34cf149c..8f4fa7f62928 100644 --- a/src/renderer/components/ft-list-channel/ft-list-channel.js +++ b/src/renderer/components/ft-list-channel/ft-list-channel.js @@ -3,6 +3,7 @@ import FtSubscribeButton from '../../components/ft-subscribe-button/ft-subscribe import { youtubeImageUrlToInvidious } from '../../helpers/api/invidious' import { formatNumber } from '../../helpers/utils' import { parseLocalSubscriberCount } from '../../helpers/api/local' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'FtListChannel', @@ -44,7 +45,7 @@ export default defineComponent({ } }, created: function () { - if (this.data.dataSource === 'local') { + if (this.data.dataSource === API_DATA_SOURCES.LOCAL_API) { this.parseLocalData() } else { this.parseInvidiousData() diff --git a/src/renderer/components/ft-list-playlist/ft-list-playlist.js b/src/renderer/components/ft-list-playlist/ft-list-playlist.js index 98747cef34c2..50c34121c8eb 100644 --- a/src/renderer/components/ft-list-playlist/ft-list-playlist.js +++ b/src/renderer/components/ft-list-playlist/ft-list-playlist.js @@ -2,6 +2,7 @@ import { defineComponent } from 'vue' import FtIconButton from '../ft-icon-button/ft-icon-button.vue' import { mapActions } from 'vuex' import { showToast } from '../../helpers/utils' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'FtListPlaylist', @@ -104,7 +105,7 @@ export default defineComponent({ created: function () { if (this.isUserPlaylist) { this.parseUserData() - } else if (this.data.dataSource === 'local') { + } else if (this.data.dataSource === API_DATA_SOURCES.LOCAL_API) { this.parseLocalData() } else { this.parseInvidiousData() @@ -158,7 +159,7 @@ export default defineComponent({ this.title = this.data.playlistName if (this.thumbnailCanBeShown && this.data.videos.length > 0) { const thumbnailURL = `https://i.ytimg.com/vi/${this.data.videos[0].videoId}/mqdefault.jpg` - if (this.backendPreference === 'invidious') { + if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { this.thumbnail = thumbnailURL.replace('https://i.ytimg.com', this.currentInvidiousInstanceUrl) } else { this.thumbnail = thumbnailURL diff --git a/src/renderer/components/ft-list-video/ft-list-video.js b/src/renderer/components/ft-list-video/ft-list-video.js index c90e1fa9c8f7..9d9a867d2956 100644 --- a/src/renderer/components/ft-list-video/ft-list-video.js +++ b/src/renderer/components/ft-list-video/ft-list-video.js @@ -13,6 +13,7 @@ import { } from '../../helpers/utils' import { deArrowData, deArrowThumbnail } from '../../helpers/sponsorblock' import debounce from 'lodash.debounce' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'FtListVideo', @@ -337,7 +338,7 @@ export default defineComponent({ } let baseUrl - if (this.backendPreference === 'invidious') { + if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { baseUrl = this.currentInvidiousInstanceUrl } else { baseUrl = 'https://i.ytimg.com' diff --git a/src/renderer/components/ft-playlist-selector/ft-playlist-selector.js b/src/renderer/components/ft-playlist-selector/ft-playlist-selector.js index 825ddc1119ab..0380a2410362 100644 --- a/src/renderer/components/ft-playlist-selector/ft-playlist-selector.js +++ b/src/renderer/components/ft-playlist-selector/ft-playlist-selector.js @@ -1,6 +1,7 @@ import { defineComponent } from 'vue' import FtIconButton from '../ft-icon-button/ft-icon-button.vue' import { mapActions } from 'vuex' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'FtPlaylistSelector', @@ -128,7 +129,7 @@ export default defineComponent({ this.title = this.playlist.playlistName if (this.playlist.videos.length > 0) { const thumbnailURL = `https://i.ytimg.com/vi/${this.playlist.videos[0].videoId}/mqdefault.jpg` - if (this.backendPreference === 'invidious') { + if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { this.thumbnail = thumbnailURL.replace('https://i.ytimg.com', this.currentInvidiousInstanceUrl) } else { this.thumbnail = thumbnailURL 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 c9b859008920..d26a9d649416 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 @@ -8,6 +8,7 @@ import FtButton from '../../components/ft-button/ft-button.vue' import FtPrompt from '../../components/ft-prompt/ft-prompt.vue' import { deepCopy, showToast } from '../../helpers/utils' import { youtubeImageUrlToInvidious } from '../../helpers/api/invidious' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'FtProfileChannelList', @@ -75,7 +76,7 @@ export default defineComponent({ return a.name?.toLowerCase().localeCompare(b.name?.toLowerCase(), this.locale) }) subscriptions.forEach((channel) => { - if (this.backendPreference === 'invidious') { + if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { channel.thumbnail = youtubeImageUrlToInvidious(channel.thumbnail, this.currentInvidiousInstanceUrl) } channel.selected = false @@ -91,7 +92,7 @@ export default defineComponent({ return a.name?.toLowerCase().localeCompare(b.name?.toLowerCase(), this.locale) }) subscriptions.forEach((channel) => { - if (this.backendPreference === 'invidious') { + if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { channel.thumbnail = youtubeImageUrlToInvidious(channel.thumbnail, this.currentInvidiousInstanceUrl) } channel.selected = false 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 57beae3b2590..93fa615d873a 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 @@ -8,7 +8,7 @@ import FtButton from '../../components/ft-button/ft-button.vue' import FtSelect from '../ft-select/ft-select.vue' import { deepCopy, showToast } from '../../helpers/utils' import { youtubeImageUrlToInvidious } from '../../helpers/api/invidious' -import { MAIN_PROFILE_ID } from '../../../constants' +import { API_DATA_SOURCES, MAIN_PROFILE_ID } from '../../../constants' export default defineComponent({ name: 'FtProfileFilterChannelsList', @@ -70,7 +70,7 @@ export default defineComponent({ return index === -1 }).map((channel) => { - if (this.backendPreference === 'invidious') { + if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { channel.thumbnail = youtubeImageUrlToInvidious(channel.thumbnail, this.currentInvidiousInstanceUrl) } channel.selected = false @@ -91,7 +91,7 @@ export default defineComponent({ return index === -1 }).map((channel) => { - if (this.backendPreference === 'invidious') { + if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { channel.thumbnail = youtubeImageUrlToInvidious(channel.thumbnail, this.currentInvidiousInstanceUrl) } channel.selected = false diff --git a/src/renderer/components/general-settings/general-settings.js b/src/renderer/components/general-settings/general-settings.js index 1ddbf2c1d460..68f49b3aab40 100644 --- a/src/renderer/components/general-settings/general-settings.js +++ b/src/renderer/components/general-settings/general-settings.js @@ -11,6 +11,7 @@ import debounce from 'lodash.debounce' import allLocales from '../../../../static/locales/activeLocales.json' import { randomArrayItem, showToast } from '../../helpers/utils' import { translateWindowTitle } from '../../helpers/strings' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'GeneralSettings', @@ -26,11 +27,11 @@ export default defineComponent({ return { backendValues: process.env.SUPPORTS_LOCAL_API ? [ - 'invidious', - 'local' + API_DATA_SOURCES.INVIDIOUS_API, + API_DATA_SOURCES.LOCAL_API ] : [ - 'invidious' + API_DATA_SOURCES.INVIDIOUS_API ], viewTypeValues: [ 'grid', @@ -92,7 +93,7 @@ export default defineComponent({ let includedPageNames = this.includedDefaultPageNames if (this.hideTrendingVideos) includedPageNames = includedPageNames.filter((pageName) => pageName !== 'trending') if (this.hidePlaylists) includedPageNames = includedPageNames.filter((pageName) => pageName !== 'userPlaylists') - if (!(!this.hidePopularVideos && (this.backendFallback || this.backendPreference === 'invidious'))) includedPageNames = includedPageNames.filter((pageName) => pageName !== 'popular') + if (!(!this.hidePopularVideos && (this.backendFallback || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API))) includedPageNames = includedPageNames.filter((pageName) => pageName !== 'popular') return this.$router.getRoutes().filter((route) => includedPageNames.includes(route.name)) }, defaultPageNames: function () { @@ -103,8 +104,8 @@ export default defineComponent({ return this.defaultPages.map((route) => route.path.substring(1)) }, backendPreference: function () { - if (!process.env.SUPPORTS_LOCAL_API && this.$store.getters.getBackendPreference === 'local') { - this.handlePreferredApiBackend('invidious') + if (!process.env.SUPPORTS_LOCAL_API && this.$store.getters.getBackendPreference === API_DATA_SOURCES.LOCAL_API) { + this.handlePreferredApiBackend(API_DATA_SOURCES.INVIDIOUS_API) } return this.$store.getters.getBackendPreference diff --git a/src/renderer/components/playlist-info/playlist-info.js b/src/renderer/components/playlist-info/playlist-info.js index 6f9ff99bcfd9..bf6a008dfe6a 100644 --- a/src/renderer/components/playlist-info/playlist-info.js +++ b/src/renderer/components/playlist-info/playlist-info.js @@ -12,6 +12,7 @@ import { showToast, } from '../../helpers/utils' import debounce from 'lodash.debounce' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'PlaylistInfo', @@ -203,7 +204,7 @@ export default defineComponent({ } let baseUrl = 'https://i.ytimg.com' - if (this.backendPreference === 'invidious') { + if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { baseUrl = this.currentInvidiousInstanceUrl } else if (typeof this.playlistThumbnail === 'string' && this.playlistThumbnail.length > 0) { // Use playlist thumbnail provided by YT when available diff --git a/src/renderer/components/side-nav/side-nav.js b/src/renderer/components/side-nav/side-nav.js index dd050476b583..c7110e0de82f 100644 --- a/src/renderer/components/side-nav/side-nav.js +++ b/src/renderer/components/side-nav/side-nav.js @@ -3,6 +3,7 @@ import FtFlexBox from '../ft-flex-box/ft-flex-box.vue' import SideNavMoreOptions from '../side-nav-more-options/side-nav-more-options.vue' import { youtubeImageUrlToInvidious } from '../../helpers/api/invidious' import { deepCopy } from '../../helpers/utils' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'SideNav', @@ -45,7 +46,7 @@ export default defineComponent({ return a.name?.toLowerCase().localeCompare(b.name?.toLowerCase(), this.locale) }) - if (this.backendPreference === 'invidious') { + if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { subscriptions.forEach((channel) => { channel.thumbnail = youtubeImageUrlToInvidious(channel.thumbnail, this.currentInvidiousInstanceUrl) }) diff --git a/src/renderer/components/subscriptions-community/subscriptions-community.js b/src/renderer/components/subscriptions-community/subscriptions-community.js index 86c81c6ecc1a..3cd1bf60f09f 100644 --- a/src/renderer/components/subscriptions-community/subscriptions-community.js +++ b/src/renderer/components/subscriptions-community/subscriptions-community.js @@ -5,6 +5,7 @@ import SubscriptionsTabUI from '../subscriptions-tab-ui/subscriptions-tab-ui.vue import { calculatePublishedDate, copyToClipboard, getRelativeTimeFromDate, showToast } from '../../helpers/utils' import { getLocalChannelCommunity } from '../../helpers/api/local' import { invidiousGetCommunityPosts } from '../../helpers/api/invidious' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'SubscriptionsCommunity', @@ -141,7 +142,7 @@ export default defineComponent({ const postListFromRemote = (await Promise.all(channelsToLoadFromRemote.map(async (channel) => { let posts = [] - if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') { + if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { posts = await this.getChannelPostsInvidious(channel) } else { posts = await this.getChannelPostsLocal(channel) @@ -221,7 +222,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (this.backendPreference === 'local' && this.backendFallback) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) { showToast(this.$t('Falling back to Invidious API')) return await this.getChannelPostsInvidious(channel) } @@ -242,7 +243,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) { + if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API && this.backendFallback) { showToast(this.$t('Falling back to Local API')) resolve(this.getChannelPostsLocal(channel)) } else { diff --git a/src/renderer/components/subscriptions-live/subscriptions-live.js b/src/renderer/components/subscriptions-live/subscriptions-live.js index ab3e8d0e7474..2a948b0d9b10 100644 --- a/src/renderer/components/subscriptions-live/subscriptions-live.js +++ b/src/renderer/components/subscriptions-live/subscriptions-live.js @@ -12,6 +12,7 @@ import { import { invidiousAPICall, invidiousFetch } from '../../helpers/api/invidious' import { getLocalChannelLiveStreams } from '../../helpers/api/local' import { parseYouTubeRSSFeed, updateVideoListAfterProcessing } from '../../helpers/subscriptions' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'SubscriptionsLive', @@ -156,7 +157,7 @@ export default defineComponent({ let videos = [] let name, thumbnailUrl - if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') { + if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { if (useRss) { ({ videos, name, thumbnailUrl } = await this.getChannelLiveInvidiousRSS(channel)) } else { diff --git a/src/renderer/components/subscriptions-shorts/subscriptions-shorts.js b/src/renderer/components/subscriptions-shorts/subscriptions-shorts.js index 101687cccd79..5bfb3b168c00 100644 --- a/src/renderer/components/subscriptions-shorts/subscriptions-shorts.js +++ b/src/renderer/components/subscriptions-shorts/subscriptions-shorts.js @@ -10,6 +10,7 @@ import { showToast } from '../../helpers/utils' import { invidiousFetch } from '../../helpers/api/invidious' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'SubscriptionsShorts', @@ -142,7 +143,7 @@ export default defineComponent({ let videos = [] let name - if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') { + if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { ({ videos, name } = await this.getChannelShortsInvidious(channel)) } else { ({ videos, name } = await this.getChannelShortsLocal(channel)) diff --git a/src/renderer/components/subscriptions-videos/subscriptions-videos.js b/src/renderer/components/subscriptions-videos/subscriptions-videos.js index d11120615fc2..82e46a655c21 100644 --- a/src/renderer/components/subscriptions-videos/subscriptions-videos.js +++ b/src/renderer/components/subscriptions-videos/subscriptions-videos.js @@ -12,6 +12,7 @@ import { import { invidiousAPICall, invidiousFetch } from '../../helpers/api/invidious' import { getLocalChannelVideos } from '../../helpers/api/local' import { parseYouTubeRSSFeed, updateVideoListAfterProcessing } from '../../helpers/subscriptions' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'SubscriptionsVideos', @@ -160,7 +161,7 @@ export default defineComponent({ let videos = [] let name, thumbnailUrl - if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') { + if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { if (useRss) { ({ videos, name, thumbnailUrl } = await this.getChannelVideosInvidiousRSS(channel)) } else { diff --git a/src/renderer/components/top-nav/top-nav.js b/src/renderer/components/top-nav/top-nav.js index 1e08e430b0f1..2ce74ed713d6 100644 --- a/src/renderer/components/top-nav/top-nav.js +++ b/src/renderer/components/top-nav/top-nav.js @@ -4,7 +4,7 @@ import FtInput from '../ft-input/ft-input.vue' import FtProfileSelector from '../ft-profile-selector/ft-profile-selector.vue' import debounce from 'lodash.debounce' -import { IpcChannels, MOBILE_WIDTH_THRESHOLD } from '../../../constants' +import { API_DATA_SOURCES, IpcChannels, MOBILE_WIDTH_THRESHOLD } from '../../../constants' import { openInternalPath } from '../../helpers/utils' import { translateWindowTitle } from '../../helpers/strings' import { clearLocalSearchSuggestionsSession, getLocalSearchSuggestions } from '../../helpers/api/local' @@ -276,10 +276,10 @@ export default defineComponent({ getSearchSuggestions: function (query) { switch (this.backendPreference) { - case 'local': + case API_DATA_SOURCES.LOCAL_API: this.getSearchSuggestionsLocal(query) break - case 'invidious': + case API_DATA_SOURCES.INVIDIOUS_API: this.getSearchSuggestionsInvidious(query) break } 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 c7d5a8f6639c..5ce0843a02fb 100644 --- a/src/renderer/components/watch-video-comments/watch-video-comments.js +++ b/src/renderer/components/watch-video-comments/watch-video-comments.js @@ -6,6 +6,7 @@ import FtTimestampCatcher from '../../components/ft-timestamp-catcher/ft-timesta import { copyToClipboard, showToast } from '../../helpers/utils' import { getInvidiousCommunityPostCommentReplies, getInvidiousCommunityPostComments, invidiousGetCommentReplies, invidiousGetComments } from '../../helpers/api/invidious' import { getLocalComments, parseLocalComment } from '../../helpers/api/local' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'WatchVideoComments', @@ -174,7 +175,7 @@ export default defineComponent({ getCommentData: function () { this.isLoading = true - if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious' || this.isPostComments) { + if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API || this.isPostComments) { if (!this.isPostComments) { this.getCommentDataInvidious() } else { @@ -189,7 +190,7 @@ export default defineComponent({ if (this.commentData.length === 0 || this.nextPageToken === null || typeof this.nextPageToken === 'undefined') { showToast(this.$t('Comments.There are no more comments for this video')) } else { - if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious' || this.isPostComments) { + if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API || this.isPostComments) { if (!this.isPostComments) { this.getCommentDataInvidious() } else { @@ -210,7 +211,7 @@ export default defineComponent({ }, getCommentReplies: function (index) { - if (!process.env.SUPPORTS_LOCAL_API || this.commentData[index].dataType === 'invidious' || this.isPostComments) { + if (!process.env.SUPPORTS_LOCAL_API || this.commentData[index].dataType === API_DATA_SOURCES.INVIDIOUS_API || this.isPostComments) { if (!this.isPostComments) { this.getCommentRepliesInvidious(index) } else { @@ -260,7 +261,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (this.backendFallback && this.backendPreference === 'local') { + if (this.backendFallback && this.backendPreference === API_DATA_SOURCES.LOCAL_API) { showToast(this.$t('Falling back to Invidious API')) this.getCommentDataInvidious() } else { @@ -306,7 +307,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (this.backendFallback && this.backendPreference === 'local') { + if (this.backendFallback && this.backendPreference === API_DATA_SOURCES.LOCAL_API) { showToast(this.$t('Falling back to Invidious API')) this.getCommentDataInvidious() } else { diff --git a/src/renderer/components/watch-video-live-chat/watch-video-live-chat.js b/src/renderer/components/watch-video-live-chat/watch-video-live-chat.js index 973eaddc551a..916f366b4662 100644 --- a/src/renderer/components/watch-video-live-chat/watch-video-live-chat.js +++ b/src/renderer/components/watch-video-live-chat/watch-video-live-chat.js @@ -7,6 +7,7 @@ import autolinker from 'autolinker' import { getRandomColorClass } from '../../helpers/colors' import { getLocalVideoInfo, parseLocalTextRuns } from '../../helpers/api/local' import { formatNumber } from '../../helpers/utils' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'WatchVideoLiveChat', @@ -100,7 +101,7 @@ export default defineComponent({ this.isLoading = false } else { switch (this.backendPreference) { - case 'local': + case API_DATA_SOURCES.LOCAL_API: if (this.liveChat) { this.liveChatInstance = this.liveChat this.startLiveChatLocal() @@ -108,7 +109,7 @@ export default defineComponent({ this.showLiveChatUnavailable() } break - case 'invidious': + case API_DATA_SOURCES.INVIDIOUS_API: if (this.backendFallback) { this.getLiveChatLocal() } else { 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 ec0ccd27cfc1..c2902a49bb3a 100644 --- a/src/renderer/components/watch-video-playlist/watch-video-playlist.js +++ b/src/renderer/components/watch-video-playlist/watch-video-playlist.js @@ -11,6 +11,7 @@ import { } from '../../helpers/api/local' import { invidiousGetPlaylistInfo } from '../../helpers/api/invidious' import { getSortedPlaylistItems, SORT_BY_VALUES } from '../../helpers/playlists' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'WatchVideoPlaylist', @@ -454,7 +455,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (this.backendPreference === 'local' && this.backendFallback) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) { showToast(this.$t('Falling back to Invidious API')) this.getPlaylistInformationInvidious() } else { diff --git a/src/renderer/helpers/api/invidious.js b/src/renderer/helpers/api/invidious.js index f05c4af95e92..7b2bebbd1069 100644 --- a/src/renderer/helpers/api/invidious.js +++ b/src/renderer/helpers/api/invidious.js @@ -3,6 +3,7 @@ import { stripHTML, toLocalePublicationString } from '../utils' import { isNullOrEmpty } from '../strings' import autolinker from 'autolinker' import { FormatUtils, Misc, Player } from 'youtubei.js' +import { API_DATA_SOURCES } from '../../../constants' function getCurrentInstanceUrl() { return store.getters.getCurrentInvidiousInstanceUrl @@ -168,7 +169,7 @@ function parseInvidiousCommentData(response) { comment.authorThumb = youtubeImageUrlToInvidious(comment.authorThumbnails.at(-1).url) comment.likes = comment.likeCount comment.text = autolinker.link(stripHTML(invidiousImageUrlToInvidious(comment.contentHtml, getCurrentInstanceUrl()))) - comment.dataType = 'invidious' + comment.dataType = API_DATA_SOURCES.INVIDIOUS_API comment.isOwner = comment.authorIsChannelOwner comment.numReplies = comment.replies?.replyCount ?? 0 comment.hasReplyToken = !!comment.replies?.continuation @@ -384,7 +385,7 @@ export function filterInvidiousFormats(formats) { }) } -export async function getHashtagInvidious(hashtag, page) { +export async function getHashtagInvidious(hashtag, page = 1) { const payload = { resource: 'hashtag', id: hashtag, diff --git a/src/renderer/helpers/api/local.js b/src/renderer/helpers/api/local.js index 83454169b75f..5d1dfe252c05 100644 --- a/src/renderer/helpers/api/local.js +++ b/src/renderer/helpers/api/local.js @@ -1,6 +1,6 @@ import { ClientType, Endpoints, Innertube, Misc, Parser, UniversalCache, Utils, YT } from 'youtubei.js' import Autolinker from 'autolinker' -import { SEARCH_CHAR_LIMIT } from '../../../constants' +import { API_DATA_SOURCES, SEARCH_CHAR_LIMIT } from '../../../constants' import { PlayerCache } from './PlayerCache' import { @@ -778,7 +778,7 @@ export function parseLocalListPlaylist(playlist, channelId = undefined, channelN return { type: 'playlist', - dataSource: 'local', + dataSource: API_DATA_SOURCES.LOCAL_API, title: lockupView.metadata.title.text, thumbnail: lockupView.content_image.primary_thumbnail.image[0].url, channelName, @@ -815,7 +815,7 @@ export function parseLocalListPlaylist(playlist, channelId = undefined, channelN return { type: 'playlist', - dataSource: 'local', + dataSource: API_DATA_SOURCES.LOCAL_API, title: playlist.title.text, thumbnail: thumbnailRenderer ? thumbnailRenderer.thumbnail[0].url : playlist.thumbnails[0].url, channelName: internalChannelName, @@ -834,7 +834,7 @@ export function parseLocalListPlaylist(playlist, channelId = undefined, channelN export function parseLocalCompactStation(compactStation, channelId, channelName) { return { type: 'playlist', - dataSource: 'local', + dataSource: API_DATA_SOURCES.LOCAL_API, title: compactStation.title.text, thumbnail: compactStation.thumbnail[1].url, channelName, @@ -1045,7 +1045,7 @@ function parseListItem(item) { return { type: 'channel', - dataSource: 'local', + dataSource: API_DATA_SOURCES.LOCAL_API, thumbnail: channel.author.best_thumbnail?.url, name: channel.author.name, id: channel.author.id, @@ -1287,7 +1287,7 @@ export function parseLocalComment(comment, commentThread = undefined) { const parsed = { id: comment.comment_id, - dataType: 'local', + dataType: API_DATA_SOURCES.LOCAL_API, authorLink: comment.author.id, author: comment.author.name, authorId: comment.author.id, diff --git a/src/renderer/helpers/channels.js b/src/renderer/helpers/channels.js index 3161e5f8dcec..c9f2ccaf450e 100644 --- a/src/renderer/helpers/channels.js +++ b/src/renderer/helpers/channels.js @@ -1,3 +1,4 @@ +import { API_DATA_SOURCES } from '../../constants' import { invidiousGetChannelInfo } from './api/invidious' import { getLocalChannel, parseLocalChannelHeader } from './api/local' @@ -25,7 +26,7 @@ async function findChannelById(id, backendOptions) { if (backendOptions.preference === 'invidious') { return await getLocalChannel(id) } - if (backendOptions.preference === 'local') { + if (backendOptions.preference === API_DATA_SOURCES.LOCAL_API) { return await invidiousGetChannelInfo(id) } } else { diff --git a/src/renderer/store/modules/settings.js b/src/renderer/store/modules/settings.js index aa4cc8b8eaf0..c267704735c4 100644 --- a/src/renderer/store/modules/settings.js +++ b/src/renderer/store/modules/settings.js @@ -1,6 +1,6 @@ import i18n, { loadLocale } from '../../i18n/index' import allLocales from '../../../../static/locales/activeLocales.json' -import { MAIN_PROFILE_ID, IpcChannels, SyncEvents } from '../../../constants' +import { MAIN_PROFILE_ID, IpcChannels, SyncEvents, API_DATA_SOURCES } from '../../../constants' import { DBSettingHandlers } from '../../../datastores/handlers/index' import { getSystemLocale, showToast } from '../../helpers/utils' @@ -166,7 +166,7 @@ const state = { autoplayPlaylists: true, autoplayVideos: true, backendFallback: process.env.SUPPORTS_LOCAL_API, - backendPreference: !process.env.SUPPORTS_LOCAL_API ? 'invidious' : 'local', + backendPreference: !process.env.SUPPORTS_LOCAL_API ? API_DATA_SOURCES.INVIDIOUS_API : API_DATA_SOURCES.LOCAL_API, barColor: false, checkForBlogPosts: true, checkForUpdates: true, diff --git a/src/renderer/views/Channel/Channel.js b/src/renderer/views/Channel/Channel.js index 96730bdcd154..ceafb58e5f4a 100644 --- a/src/renderer/views/Channel/Channel.js +++ b/src/renderer/views/Channel/Channel.js @@ -44,6 +44,7 @@ import { getLocalPlaylist, parseLocalPlaylistVideo } from '../../helpers/api/local' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'Channel', @@ -356,7 +357,7 @@ export default defineComponent({ this.errorMessage = '' // Re-enable auto refresh on sort value change AFTER update done - if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') { + if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { this.getChannelInfoInvidious() this.autoRefreshOnSortByChangeEnabled = true } else { @@ -372,10 +373,10 @@ export default defineComponent({ this.isElementListLoading = true this.latestVideos = [] switch (this.apiUsed) { - case 'local': + case API_DATA_SOURCES.LOCAL_API: this.getChannelVideosLocal() break - case 'invidious': + case API_DATA_SOURCES.INVIDIOUS_API: this.channelInvidiousVideos(true) break default: @@ -389,10 +390,10 @@ export default defineComponent({ this.isElementListLoading = true this.latestShorts = [] switch (this.apiUsed) { - case 'local': + case API_DATA_SOURCES.LOCAL_API: this.getChannelShortsLocal() break - case 'invidious': + case API_DATA_SOURCES.INVIDIOUS_API: this.channelInvidiousShorts(true) break default: @@ -406,10 +407,10 @@ export default defineComponent({ this.isElementListLoading = true this.latestLive = [] switch (this.apiUsed) { - case 'local': + case API_DATA_SOURCES.LOCAL_API: this.getChannelLiveLocal() break - case 'invidious': + case API_DATA_SOURCES.INVIDIOUS_API: this.channelInvidiousLive(true) break default: @@ -424,10 +425,10 @@ export default defineComponent({ this.latestPlaylists = [] this.playlistContinuationData = null switch (this.apiUsed) { - case 'local': + case API_DATA_SOURCES.LOCAL_API: this.getChannelPlaylistsLocal() break - case 'invidious': + case API_DATA_SOURCES.INVIDIOUS_API: this.getPlaylistsInvidious() break default: @@ -452,7 +453,7 @@ export default defineComponent({ } // Enable auto refresh on sort value change AFTER initial update done - if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') { + if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { this.getChannelInfoInvidious() this.autoRefreshOnSortByChangeEnabled = true } else { @@ -465,7 +466,7 @@ export default defineComponent({ resolveChannelUrl: async function (url, tab = undefined) { let id - if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') { + if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { id = await invidiousGetChannelId(url) } else { id = await getLocalChannelId(url) @@ -496,7 +497,7 @@ export default defineComponent({ }, getChannelLocal: async function () { - this.apiUsed = 'local' + this.apiUsed = API_DATA_SOURCES.LOCAL_API this.isLoading = true const expectedId = this.id @@ -702,7 +703,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (this.backendPreference === 'local' && this.backendFallback) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) { showToast(this.$t('Falling back to Invidious API')) this.getChannelInfoInvidious() } else { @@ -755,7 +756,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (this.backendPreference === 'local' && this.backendFallback) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) { showToast(this.$t('Falling back to Invidious API')) this.getChannelInfoInvidious() } else { @@ -827,7 +828,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (this.backendPreference === 'local' && this.backendFallback) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) { showToast(this.$t('Falling back to Invidious API')) this.getChannelInfoInvidious() } else { @@ -903,7 +904,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (this.backendPreference === 'local' && this.backendFallback) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) { showToast(this.$t('Falling back to Invidious API')) this.getChannelInfoInvidious() } else { @@ -980,7 +981,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (this.backendPreference === 'local' && this.backendFallback) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) { showToast(this.$t('Falling back to Invidious API')) this.getChannelInfoInvidious() } else { @@ -1009,7 +1010,7 @@ export default defineComponent({ getChannelInfoInvidious: function () { this.isLoading = true - this.apiUsed = 'invidious' + this.apiUsed = API_DATA_SOURCES.INVIDIOUS_API this.channelInstance = null const expectedId = this.id @@ -1101,7 +1102,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) { + if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API && this.backendFallback) { showToast(this.$t('Falling back to Local API')) this.getChannelLocal() } else { @@ -1323,7 +1324,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (this.backendPreference === 'local' && this.backendFallback) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) { showToast(this.$t('Falling back to Invidious API')) this.getPlaylistsInvidious() } else { @@ -1372,7 +1373,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) { + if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API && this.backendFallback) { showToast(this.$t('Falling back to Local API')) if (!this.channelInstance) { this.channelInstance = await getLocalChannel(this.id) @@ -1413,7 +1414,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) { + if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API && this.backendFallback) { showToast(this.$t('Falling back to Local API')) this.getChannelLocal() } else { @@ -1459,7 +1460,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (this.backendPreference === 'local' && this.backendFallback) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) { showToast(this.$t('Falling back to Invidious API')) this.getChannelReleasesInvidious() } else { @@ -1514,7 +1515,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) { + if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API && this.backendFallback) { showToast(this.$t('Falling back to Local API')) if (!this.channelInstance) { this.channelInstance = await getLocalChannel(this.id) @@ -1548,7 +1549,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) { + if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API && this.backendFallback) { showToast(this.$t('Falling back to Local API')) this.getChannelLocal() } else { @@ -1581,7 +1582,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (this.backendPreference === 'local' && this.backendFallback) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) { showToast(this.$t('Falling back to Invidious API')) this.channelInvidiousPodcasts() } else { @@ -1627,7 +1628,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) { + if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API && this.backendFallback) { showToast(this.$t('Falling back to Local API')) if (!this.channelInstance) { this.channelInstance = await getLocalChannel(this.id) @@ -1661,7 +1662,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) { + if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API && this.backendFallback) { showToast(this.$t('Falling back to Local API')) this.getChannelLocal() } else { @@ -1717,7 +1718,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (this.backendPreference === 'local' && this.backendFallback) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) { showToast(this.$t('Falling back to Invidious API')) this.getCommunityPostsInvidious() } else { @@ -1781,7 +1782,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) { + if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API && this.backendFallback) { showToast(this.$t('Falling back to Local API')) if (!this.channelInstance) { this.channelInstance = await getLocalChannel(this.id) @@ -1807,30 +1808,30 @@ export default defineComponent({ switch (this.currentTab) { case 'videos': switch (this.apiUsed) { - case 'local': + case API_DATA_SOURCES.LOCAL_API: this.channelLocalNextPage() break - case 'invidious': + case API_DATA_SOURCES.INVIDIOUS_API: this.channelInvidiousVideos() break } break case 'shorts': switch (this.apiUsed) { - case 'local': + case API_DATA_SOURCES.LOCAL_API: this.getChannelShortsLocalMore() break - case 'invidious': + case API_DATA_SOURCES.INVIDIOUS_API: this.channelInvidiousShorts() break } break case 'live': switch (this.apiUsed) { - case 'local': + case API_DATA_SOURCES.LOCAL_API: this.getChannelLiveLocalMore() break - case 'invidious': + case API_DATA_SOURCES.INVIDIOUS_API: this.channelInvidiousLive() break } @@ -1843,30 +1844,30 @@ export default defineComponent({ break case 'playlists': switch (this.apiUsed) { - case 'local': + case API_DATA_SOURCES.LOCAL_API: this.getChannelPlaylistsLocalMore() break - case 'invidious': + case API_DATA_SOURCES.INVIDIOUS_API: this.getPlaylistsInvidiousMore() break } break case 'search': switch (this.apiUsed) { - case 'local': + case API_DATA_SOURCES.LOCAL_API: this.searchChannelLocal() break - case 'invidious': + case API_DATA_SOURCES.INVIDIOUS_API: this.searchChannelInvidious() break } break case 'community': switch (this.apiUsed) { - case 'local': + case API_DATA_SOURCES.LOCAL_API: this.getCommunityPostsLocalMore() break - case 'invidious': + case API_DATA_SOURCES.INVIDIOUS_API: this.getCommunityPostsInvidious() break } @@ -1892,10 +1893,10 @@ export default defineComponent({ this.searchResults = [] this.changeTab('search') switch (this.apiUsed) { - case 'local': + case API_DATA_SOURCES.LOCAL_API: this.searchChannelLocal() break - case 'invidious': + case API_DATA_SOURCES.INVIDIOUS_API: this.searchChannelInvidious() break } @@ -1946,7 +1947,7 @@ export default defineComponent({ copyToClipboard(err) }) if (isNewSearch) { - if (this.backendPreference === 'local' && this.backendFallback) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) { showToast(this.$t('Falling back to Invidious API')) this.searchChannelInvidious() } else { @@ -1982,7 +1983,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) { + if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API && this.backendFallback) { showToast(this.$t('Falling back to Local API')) this.searchChannelLocal() } else { diff --git a/src/renderer/views/Hashtag/Hashtag.js b/src/renderer/views/Hashtag/Hashtag.js index 27e65e4a2898..bb5748301b43 100644 --- a/src/renderer/views/Hashtag/Hashtag.js +++ b/src/renderer/views/Hashtag/Hashtag.js @@ -9,6 +9,7 @@ import { getHashtagLocal, parseLocalListVideo } from '../../helpers/api/local' import { copyToClipboard, setPublishedTimestampsInvidious, showToast } from '../../helpers/utils' import { isNullOrEmpty } from '../../helpers/strings' import { getHashtagInvidious } from '../../helpers/api/invidious' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'Hashtag', @@ -24,7 +25,7 @@ export default defineComponent({ hashtag: '', hashtagContinuationData: null, videos: [], - apiUsed: 'local', + apiUsed: API_DATA_SOURCES.LOCAL_API, pageNumber: 1, isLoading: true } @@ -39,7 +40,7 @@ export default defineComponent({ }, showFetchMoreButton() { - return !isNullOrEmpty(this.hashtagContinuationData) || this.apiUsed === 'invidious' + return !isNullOrEmpty(this.hashtagContinuationData) || this.apiUsed === API_DATA_SOURCES.INVIDIOUS_API }, }, watch: { @@ -58,13 +59,13 @@ export default defineComponent({ this.hashtag = '' this.hashtagContinuationData = null this.videos = [] - this.apiUsed = 'local' + this.apiUsed = API_DATA_SOURCES.LOCAL_API this.pageNumber = 1 }, getHashtag: async function() { const hashtag = decodeURIComponent(this.$route.params.hashtag) - if (this.backendFallback || this.backendPreference === 'local') { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API) { await this.getLocalHashtag(hashtag) } else { await this.getInvidiousHashtag(hashtag) @@ -78,7 +79,7 @@ export default defineComponent({ setPublishedTimestampsInvidious(videos) this.hashtag = '#' + hashtag this.isLoading = false - this.apiUsed = 'invidious' + this.apiUsed = API_DATA_SOURCES.INVIDIOUS_API this.videos = this.videos.concat(videos) this.pageNumber += 1 } catch (error) { @@ -87,7 +88,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${error}`, 10000, () => { copyToClipboard(error) }) - if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) { + if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API && this.backendFallback) { showToast(this.$t('Falling back to Local API')) this.resetData() this.getLocalHashtag(hashtag) @@ -120,7 +121,7 @@ export default defineComponent({ } this.videos = hashtagData.videos.map(parseLocalListVideo) - this.apiUsed = 'local' + this.apiUsed = API_DATA_SOURCES.LOCAL_API this.hashtagContinuationData = hashtagData.has_continuation ? hashtagData : null this.isLoading = false } catch (error) { @@ -129,7 +130,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${error}`, 10000, () => { copyToClipboard(error) }) - if (this.backendPreference === 'local' && this.backendFallback) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) { showToast(this.$t('Falling back to Invidious API')) this.resetData() this.getInvidiousHashtag(hashtag) @@ -151,7 +152,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${error}`, 10000, () => { copyToClipboard(error) }) - if (this.backendPreference === 'local' && this.backendFallback) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) { showToast(this.$t('Falling back to Invidious API')) const hashtag = this.hashtag.substring(1) this.resetData() @@ -163,9 +164,9 @@ export default defineComponent({ }, handleFetchMore: function() { - if (this.apiUsed === 'local') { + if (this.apiUsed === API_DATA_SOURCES.LOCAL_API) { this.getLocalHashtagMore() - } else if (this.apiUsed === 'invidious') { + } else if (this.apiUsed === API_DATA_SOURCES.INVIDIOUS_API) { this.getInvidiousHashtag(this.hashtag.substring(1), this.pageNumber) } } diff --git a/src/renderer/views/Playlist/Playlist.js b/src/renderer/views/Playlist/Playlist.js index 7e838e955c0b..70ba0256d5cc 100644 --- a/src/renderer/views/Playlist/Playlist.js +++ b/src/renderer/views/Playlist/Playlist.js @@ -24,7 +24,7 @@ import { import { invidiousGetPlaylistInfo, youtubeImageUrlToInvidious } from '../../helpers/api/invidious' import { getSortedPlaylistItems, SORT_BY_VALUES } from '../../helpers/playlists' import packageDetails from '../../../../package.json' -import { MOBILE_WIDTH_THRESHOLD, PLAYLIST_HEIGHT_FORCE_LIST_THRESHOLD } from '../../../constants' +import { API_DATA_SOURCES, MOBILE_WIDTH_THRESHOLD, PLAYLIST_HEIGHT_FORCE_LIST_THRESHOLD } from '../../../constants' export default defineComponent({ name: 'Playlist', @@ -66,7 +66,7 @@ export default defineComponent({ channelName: '', channelThumbnail: '', channelId: '', - infoSource: 'local', + infoSource: API_DATA_SOURCES.LOCAL_API, playlistItems: [], userPlaylistVisibleLimit: 100, continuationData: null, @@ -284,10 +284,10 @@ export default defineComponent({ } switch (this.backendPreference) { - case 'local': + case API_DATA_SOURCES.LOCAL_API: this.getPlaylistLocal() break - case 'invidious': + case API_DATA_SOURCES.INVIDIOUS_API: this.getPlaylistInvidious() break } @@ -315,7 +315,7 @@ export default defineComponent({ this.channelName = channelName ?? '' this.channelThumbnail = result.info.author?.best_thumbnail?.url ?? '' this.channelId = result.info.author?.id - this.infoSource = 'local' + this.infoSource = API_DATA_SOURCES.LOCAL_API this.updateSubscriptionDetails({ channelThumbnailUrl: this.channelThumbnail, @@ -339,7 +339,7 @@ export default defineComponent({ this.isLoading = false }).catch((err) => { console.error(err) - if (this.backendPreference === 'local' && this.backendFallback) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) { console.warn('Falling back to Invidious API') this.getPlaylistInvidious() } else { @@ -358,7 +358,7 @@ export default defineComponent({ this.channelName = result.author this.channelThumbnail = youtubeImageUrlToInvidious(result.authorThumbnails[2].url, this.currentInvidiousInstanceUrl) this.channelId = result.authorId - this.infoSource = 'invidious' + this.infoSource = API_DATA_SOURCES.INVIDIOUS_API this.updateSubscriptionDetails({ channelThumbnailUrl: result.authorThumbnails[2].url, @@ -378,7 +378,7 @@ export default defineComponent({ this.isLoading = false }).catch((err) => { console.error(err) - if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) { + if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API && this.backendFallback) { console.warn('Error getting data with Invidious, falling back to local backend') this.getPlaylistLocal() } else { @@ -420,7 +420,7 @@ export default defineComponent({ getNextPage: function () { switch (this.infoSource) { - case 'local': + case API_DATA_SOURCES.LOCAL_API: this.getNextPageLocal() break case 'user': @@ -437,7 +437,7 @@ export default defineComponent({ this.isLoadingMore = false }) break - case 'invidious': + case API_DATA_SOURCES.INVIDIOUS_API: console.error('Playlist pagination is not currently supported when the Invidious backend is selected.') break } diff --git a/src/renderer/views/Post/Post.js b/src/renderer/views/Post/Post.js index d13bb906bbf9..afd03c87a861 100644 --- a/src/renderer/views/Post/Post.js +++ b/src/renderer/views/Post/Post.js @@ -5,6 +5,7 @@ import FtLoader from '../../components/ft-loader/ft-loader.vue' import WatchVideoComments from '../../components/watch-video-comments/watch-video-comments.vue' import { getInvidiousCommunityPost } from '../../helpers/api/invidious' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'Post', @@ -31,7 +32,7 @@ export default defineComponent({ return this.$store.getters.getBackendFallback }, isInvidiousAllowed: function() { - return this.backendPreference === 'invidious' || this.backendFallback + return this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API || this.backendFallback } }, watch: { diff --git a/src/renderer/views/Search/Search.js b/src/renderer/views/Search/Search.js index 1b4984704bd3..e9b4f52cb5ba 100644 --- a/src/renderer/views/Search/Search.js +++ b/src/renderer/views/Search/Search.js @@ -11,7 +11,7 @@ import { } from '../../helpers/utils' import { getLocalSearchContinuation, getLocalSearchResults } from '../../helpers/api/local' import { invidiousAPICall } from '../../helpers/api/invidious' -import { SEARCH_CHAR_LIMIT } from '../../../constants' +import { API_DATA_SOURCES, SEARCH_CHAR_LIMIT } from '../../../constants' export default defineComponent({ name: 'Search', @@ -24,7 +24,7 @@ export default defineComponent({ data: function () { return { isLoading: false, - apiUsed: 'local', + apiUsed: API_DATA_SOURCES.LOCAL_API, amountOfResults: 0, query: '', searchPage: 1, @@ -125,10 +125,10 @@ export default defineComponent({ this.searchSettings = payload.searchSettings switch (this.backendPreference) { - case 'local': + case API_DATA_SOURCES.LOCAL_API: this.performSearchLocal(payload) break - case 'invidious': + case API_DATA_SOURCES.INVIDIOUS_API: this.performSearchInvidious(payload, { resetSearchPage: true }) break } @@ -141,7 +141,7 @@ export default defineComponent({ try { const { results, continuationData } = await getLocalSearchResults(payload.query, payload.searchSettings, this.showFamilyFriendlyOnly) - this.apiUsed = 'local' + this.apiUsed = API_DATA_SOURCES.LOCAL_API this.shownResults = results this.nextPageRef = continuationData @@ -163,7 +163,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (this.backendPreference === 'local' && this.backendFallback) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) { showToast(this.$t('Falling back to Invidious API')) this.performSearchInvidious(payload) } else { @@ -180,7 +180,7 @@ export default defineComponent({ return } - this.apiUsed = 'local' + this.apiUsed = API_DATA_SOURCES.LOCAL_API this.shownResults = this.shownResults.concat(results) this.nextPageRef = continuationData @@ -200,7 +200,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (this.backendPreference === 'local' && this.backendFallback) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) { showToast(this.$t('Falling back to Invidious API')) this.performSearchInvidious(payload) } else { @@ -236,7 +236,7 @@ export default defineComponent({ return } - this.apiUsed = 'invidious' + this.apiUsed = API_DATA_SOURCES.INVIDIOUS_API const returnData = result.filter((item) => { return item.type === 'video' || item.type === 'channel' || item.type === 'playlist' || item.type === 'hashtag' @@ -269,7 +269,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) { + if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API && this.backendFallback) { showToast(this.$t('Falling back to Local API')) this.performSearchLocal(payload) } else { @@ -288,7 +288,7 @@ export default defineComponent({ } } - if (this.apiUsed === 'local') { + if (this.apiUsed === API_DATA_SOURCES.LOCAL_API) { if (this.nextPageRef !== null) { showToast(this.$t('Search Filters["Fetching results. Please wait"]')) this.getNextpageLocal(payload) diff --git a/src/renderer/views/SubscribedChannels/SubscribedChannels.js b/src/renderer/views/SubscribedChannels/SubscribedChannels.js index eda06ec8ee14..2af1397d8597 100644 --- a/src/renderer/views/SubscribedChannels/SubscribedChannels.js +++ b/src/renderer/views/SubscribedChannels/SubscribedChannels.js @@ -7,6 +7,7 @@ import FtSubscribeButton from '../../components/ft-subscribe-button/ft-subscribe import { invidiousGetChannelInfo, youtubeImageUrlToInvidious, invidiousImageUrlToInvidious } from '../../helpers/api/invidious' import { getLocalChannel, parseLocalChannelHeader } from '../../helpers/api/local' import { ctrlFHandler } from '../../helpers/utils' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'SubscribedChannels', @@ -119,11 +120,11 @@ export default defineComponent({ } const hostname = new URL(newURL).hostname if (hostname === 'yt3.ggpht.com' || hostname === 'yt3.googleusercontent.com') { - if (this.backendPreference === 'invidious') { // YT to IV + if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { // YT to IV newURL = youtubeImageUrlToInvidious(newURL, this.currentInvidiousInstanceUrl) } } else { - if (this.backendPreference === 'local') { // IV to YT + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API) { // IV to YT newURL = newURL.replace(this.re.ivToYt, `${this.ytBaseURL}/$1`) } else { // IV to IV newURL = invidiousImageUrlToInvidious(newURL, this.currentInvidiousInstanceUrl) @@ -135,7 +136,7 @@ export default defineComponent({ updateThumbnail: function(channel) { this.errorCount += 1 - if (this.backendPreference === 'local') { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API) { // avoid too many concurrent requests setTimeout(() => { getLocalChannel(channel.id).then(response => { diff --git a/src/renderer/views/Trending/Trending.js b/src/renderer/views/Trending/Trending.js index 533f9cf8b56e..cc4ecd6faee9 100644 --- a/src/renderer/views/Trending/Trending.js +++ b/src/renderer/views/Trending/Trending.js @@ -10,6 +10,7 @@ import FtRefreshWidget from '../../components/ft-refresh-widget/ft-refresh-widge import { copyToClipboard, getRelativeTimeFromDate, setPublishedTimestampsInvidious, showToast } from '../../helpers/utils' import { getLocalTrending } from '../../helpers/api/local' import { invidiousAPICall } from '../../helpers/api/invidious' +import { API_DATA_SOURCES } from '../../../constants' export default defineComponent({ name: 'Trending', @@ -90,7 +91,7 @@ export default defineComponent({ this.$store.commit('clearTrendingCache') } - if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') { + if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { this.getTrendingInfoInvidious() } else { this.getTrendingInfoLocal() @@ -119,7 +120,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (this.backendPreference === 'local' && this.backendFallback) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) { showToast(this.$t('Falling back to Invidious API')) this.getTrendingInfoInvidious() } else { @@ -168,7 +169,7 @@ export default defineComponent({ copyToClipboard(err) }) - if (process.env.SUPPORTS_LOCAL_API && (this.backendPreference === 'invidious' && this.backendFallback)) { + if (process.env.SUPPORTS_LOCAL_API && (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API && this.backendFallback)) { showToast(this.$t('Falling back to Local API')) this.getTrendingInfoLocal() } else { diff --git a/src/renderer/views/Watch/Watch.js b/src/renderer/views/Watch/Watch.js index 30e87e82610c..3e94103e66c2 100644 --- a/src/renderer/views/Watch/Watch.js +++ b/src/renderer/views/Watch/Watch.js @@ -36,6 +36,7 @@ import { mapInvidiousLegacyFormat, youtubeImageUrlToInvidious } from '../../helpers/api/invidious' +import { API_DATA_SOURCES } from '../../../constants' const MANIFEST_TYPE_DASH = 'application/dash+xml' const MANIFEST_TYPE_HLS = 'application/x-mpegurl' @@ -252,10 +253,10 @@ export default defineComponent({ this.checkIfPlaylist() switch (this.backendPreference) { - case 'local': + case API_DATA_SOURCES.LOCAL_API: this.getVideoInformationLocal(this.videoId) break - case 'invidious': + case API_DATA_SOURCES.INVIDIOUS_API: this.getVideoInformationInvidious(this.videoId) break } @@ -288,7 +289,7 @@ export default defineComponent({ // this has to be below checkIfPlaylist() as theatrePossible needs to know if there is a playlist or not this.useTheatreMode = this.defaultTheatreMode && this.theatrePossible - if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') { + if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { this.getVideoInformationInvidious() } else { this.getVideoInformationLocal() @@ -709,7 +710,7 @@ export default defineComponent({ copyToClipboard(err) }) console.error(err) - if (this.backendPreference === 'local' && this.backendFallback && !err.toString().includes('private')) { + if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback && !err.toString().includes('private')) { showToast(this.$t('Falling back to Invidious API')) this.getVideoInformationInvidious() } else { @@ -911,7 +912,7 @@ export default defineComponent({ copyToClipboard(err) }) console.error(err) - if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) { + if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API && this.backendFallback) { showToast(this.$t('Falling back to Local API')) this.getVideoInformationLocal() } else { From 866611fdad59bcd12c182400986ab06afa31b12a Mon Sep 17 00:00:00 2001 From: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Thu, 12 Sep 2024 00:36:55 -0400 Subject: [PATCH 2/2] Update files i forgot to include in commit --- .../watch-video-comments/watch-video-comments.js | 2 +- .../watch-video-playlist/watch-video-playlist.js | 8 ++++---- src/renderer/helpers/channels.js | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) 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 5ce0843a02fb..4cc8601414a1 100644 --- a/src/renderer/components/watch-video-comments/watch-video-comments.js +++ b/src/renderer/components/watch-video-comments/watch-video-comments.js @@ -355,7 +355,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (process.env.SUPPORTS_LOCAL_API && this.backendFallback && this.backendPreference === 'invidious') { + if (process.env.SUPPORTS_LOCAL_API && this.backendFallback && this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { showToast(this.$t('Falling back to Local API')) this.getCommentDataLocal() } else { 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 c2902a49bb3a..acf9128be3e0 100644 --- a/src/renderer/components/watch-video-playlist/watch-video-playlist.js +++ b/src/renderer/components/watch-video-playlist/watch-video-playlist.js @@ -198,7 +198,7 @@ export default defineComponent({ }, playlistId: function (newVal, oldVal) { if (oldVal !== newVal) { - if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') { + if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { this.getPlaylistInformationInvidious() } else { this.getPlaylistInformationLocal() @@ -254,7 +254,7 @@ export default defineComponent({ if (this.selectedUserPlaylist != null) { this.parseUserPlaylist(this.selectedUserPlaylist) - } else if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') { + } else if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) { this.getPlaylistInformationInvidious() } else { this.getPlaylistInformationLocal() @@ -406,7 +406,7 @@ export default defineComponent({ this.channelName = cachedPlaylist.channelName this.channelId = cachedPlaylist.channelId - if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious' || cachedPlaylist.continuationData === null) { + if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API || cachedPlaylist.continuationData === null) { this.playlistItems = cachedPlaylist.items } else { const videos = cachedPlaylist.items @@ -482,7 +482,7 @@ export default defineComponent({ showToast(`${errorMessage}: ${err}`, 10000, () => { copyToClipboard(err) }) - if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) { + if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API && this.backendFallback) { showToast(this.$t('Falling back to Local API')) this.getPlaylistInformationLocal() } else { diff --git a/src/renderer/helpers/channels.js b/src/renderer/helpers/channels.js index c9f2ccaf450e..d93d3bab06e7 100644 --- a/src/renderer/helpers/channels.js +++ b/src/renderer/helpers/channels.js @@ -12,7 +12,7 @@ import { getLocalChannel, parseLocalChannelHeader } from './api/local' */ async function findChannelById(id, backendOptions) { try { - if (!process.env.SUPPORTS_LOCAL_API || backendOptions.preference === 'invidious') { + if (!process.env.SUPPORTS_LOCAL_API || backendOptions.preference === API_DATA_SOURCES.INVIDIOUS_API) { return await invidiousGetChannelInfo(id) } else { return await getLocalChannel(id) @@ -23,7 +23,7 @@ async function findChannelById(id, backendOptions) { return { invalid: true } } if (process.env.SUPPORTS_LOCAL_API && backendOptions.fallback) { - if (backendOptions.preference === 'invidious') { + if (backendOptions.preference === API_DATA_SOURCES.INVIDIOUS_API) { return await getLocalChannel(id) } if (backendOptions.preference === API_DATA_SOURCES.LOCAL_API) { @@ -47,7 +47,7 @@ export async function findChannelTagInfo(id, backendOptions) { if (!checkYoutubeChannelId(id)) return { invalidId: true } try { const channel = await findChannelById(id, backendOptions) - if (!process.env.SUPPORTS_LOCAL_API || backendOptions.preference === 'invidious') { + if (!process.env.SUPPORTS_LOCAL_API || backendOptions.preference === API_DATA_SOURCES.INVIDIOUS_API) { if (channel.invalid) return { invalidId: true } return { preferredName: channel.author,