mirror of https://github.com/FreeTubeApp/FreeTube
Add SUPPORTS_LOCAL_API build flag (#4931)
This commit is contained in:
parent
559671fd24
commit
af2913592e
|
@ -119,6 +119,7 @@ const config = {
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'process.env.IS_ELECTRON': true,
|
'process.env.IS_ELECTRON': true,
|
||||||
'process.env.IS_ELECTRON_MAIN': false,
|
'process.env.IS_ELECTRON_MAIN': false,
|
||||||
|
'process.env.SUPPORTS_LOCAL_API': true,
|
||||||
'process.env.LOCALE_NAMES': JSON.stringify(processLocalesPlugin.localeNames),
|
'process.env.LOCALE_NAMES': JSON.stringify(processLocalesPlugin.localeNames),
|
||||||
'process.env.GEOLOCATION_NAMES': JSON.stringify(readdirSync(path.join(__dirname, '..', 'static', 'geolocations')).map(filename => filename.replace('.json', ''))),
|
'process.env.GEOLOCATION_NAMES': JSON.stringify(readdirSync(path.join(__dirname, '..', 'static', 'geolocations')).map(filename => filename.replace('.json', ''))),
|
||||||
'process.env.SWIPER_VERSION': `'${swiperVersion}'`
|
'process.env.SWIPER_VERSION': `'${swiperVersion}'`
|
||||||
|
|
|
@ -116,6 +116,7 @@ const config = {
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'process.env.IS_ELECTRON': false,
|
'process.env.IS_ELECTRON': false,
|
||||||
'process.env.IS_ELECTRON_MAIN': false,
|
'process.env.IS_ELECTRON_MAIN': false,
|
||||||
|
'process.env.SUPPORTS_LOCAL_API': false,
|
||||||
'process.env.SWIPER_VERSION': `'${swiperVersion}'`,
|
'process.env.SWIPER_VERSION': `'${swiperVersion}'`,
|
||||||
|
|
||||||
// video.js' vhs-utils supports both atob() in web browsers and Buffer in node
|
// video.js' vhs-utils supports both atob() in web browsers and Buffer in node
|
||||||
|
|
|
@ -1152,7 +1152,7 @@ export default defineComponent({
|
||||||
copyToClipboard(err)
|
copyToClipboard(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (process.env.IS_ELECTRON && this.backendFallback && this.backendPreference === 'invidious') {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendFallback && this.backendPreference === 'invidious') {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
resolve(this.getChannelInfoLocal(channelId))
|
resolve(this.getChannelInfoLocal(channelId))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -95,7 +95,7 @@ export default defineComponent({
|
||||||
this.postText = 'Shared post'
|
this.postText = 'Shared post'
|
||||||
this.type = 'text'
|
this.type = 'text'
|
||||||
let authorThumbnails = ['', 'https://yt3.ggpht.com/ytc/AAUvwnjm-0qglHJkAHqLFsCQQO97G7cCNDuDLldsrn25Lg=s88-c-k-c0x00ffffff-no-rj']
|
let authorThumbnails = ['', 'https://yt3.ggpht.com/ytc/AAUvwnjm-0qglHJkAHqLFsCQQO97G7cCNDuDLldsrn25Lg=s88-c-k-c0x00ffffff-no-rj']
|
||||||
if (!process.env.IS_ELECTRON || this.backendPreference === 'invidious') {
|
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
|
||||||
authorThumbnails = authorThumbnails.map(thumbnail => {
|
authorThumbnails = authorThumbnails.map(thumbnail => {
|
||||||
thumbnail.url = youtubeImageUrlToInvidious(thumbnail.url)
|
thumbnail.url = youtubeImageUrlToInvidious(thumbnail.url)
|
||||||
return thumbnail
|
return thumbnail
|
||||||
|
@ -106,7 +106,7 @@ export default defineComponent({
|
||||||
}
|
}
|
||||||
this.postText = autolinker.link(this.data.postText)
|
this.postText = autolinker.link(this.data.postText)
|
||||||
const authorThumbnails = deepCopy(this.data.authorThumbnails)
|
const authorThumbnails = deepCopy(this.data.authorThumbnails)
|
||||||
if (!process.env.IS_ELECTRON || this.backendPreference === 'invidious') {
|
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
|
||||||
authorThumbnails.forEach(thumbnail => {
|
authorThumbnails.forEach(thumbnail => {
|
||||||
thumbnail.url = youtubeImageUrlToInvidious(thumbnail.url)
|
thumbnail.url = youtubeImageUrlToInvidious(thumbnail.url)
|
||||||
})
|
})
|
||||||
|
|
|
@ -1314,7 +1314,7 @@ export default defineComponent({
|
||||||
|
|
||||||
this.useDash = false
|
this.useDash = false
|
||||||
this.useHls = false
|
this.useHls = false
|
||||||
this.activeSourceList = (this.proxyVideos || !process.env.IS_ELECTRON)
|
this.activeSourceList = (this.proxyVideos || !process.env.SUPPORTS_LOCAL_API)
|
||||||
// use map here to return slightly different list without modifying original
|
// use map here to return slightly different list without modifying original
|
||||||
? this.sourceList.map((source) => {
|
? this.sourceList.map((source) => {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -24,10 +24,14 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
backendValues: [
|
backendValues: process.env.SUPPORTS_LOCAL_API
|
||||||
'invidious',
|
? [
|
||||||
'local'
|
'invidious',
|
||||||
],
|
'local'
|
||||||
|
]
|
||||||
|
: [
|
||||||
|
'invidious'
|
||||||
|
],
|
||||||
viewTypeValues: [
|
viewTypeValues: [
|
||||||
'grid',
|
'grid',
|
||||||
'list'
|
'list'
|
||||||
|
@ -99,6 +103,10 @@ export default defineComponent({
|
||||||
return this.defaultPages.map((route) => route.path.substring(1))
|
return this.defaultPages.map((route) => route.path.substring(1))
|
||||||
},
|
},
|
||||||
backendPreference: function () {
|
backendPreference: function () {
|
||||||
|
if (!process.env.SUPPORTS_LOCAL_API && this.$store.getters.getBackendPreference === 'local') {
|
||||||
|
this.handlePreferredApiBackend('invidious')
|
||||||
|
}
|
||||||
|
|
||||||
return this.$store.getters.getBackendPreference
|
return this.$store.getters.getBackendPreference
|
||||||
},
|
},
|
||||||
landingPage: function () {
|
landingPage: function () {
|
||||||
|
@ -149,10 +157,16 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
|
|
||||||
backendNames: function () {
|
backendNames: function () {
|
||||||
return [
|
if (process.env.SUPPORTS_LOCAL_API) {
|
||||||
this.$t('Settings.General Settings.Preferred API Backend.Invidious API'),
|
return [
|
||||||
this.$t('Settings.General Settings.Preferred API Backend.Local API')
|
this.$t('Settings.General Settings.Preferred API Backend.Invidious API'),
|
||||||
]
|
this.$t('Settings.General Settings.Preferred API Backend.Local API')
|
||||||
|
]
|
||||||
|
} else {
|
||||||
|
return [
|
||||||
|
this.$t('Settings.General Settings.Preferred API Backend.Invidious API')
|
||||||
|
]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
viewTypeNames: function () {
|
viewTypeNames: function () {
|
||||||
|
|
|
@ -125,7 +125,7 @@ export default defineComponent({
|
||||||
|
|
||||||
const postListFromRemote = (await Promise.all(channelsToLoadFromRemote.map(async (channel) => {
|
const postListFromRemote = (await Promise.all(channelsToLoadFromRemote.map(async (channel) => {
|
||||||
let posts = []
|
let posts = []
|
||||||
if (!process.env.IS_ELECTRON || this.backendPreference === 'invidious') {
|
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
|
||||||
posts = await this.getChannelPostsInvidious(channel)
|
posts = await this.getChannelPostsInvidious(channel)
|
||||||
} else {
|
} else {
|
||||||
posts = await this.getChannelPostsLocal(channel)
|
posts = await this.getChannelPostsLocal(channel)
|
||||||
|
@ -229,7 +229,7 @@ export default defineComponent({
|
||||||
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
||||||
copyToClipboard(err)
|
copyToClipboard(err)
|
||||||
})
|
})
|
||||||
if (process.env.IS_ELECTRON && this.backendPreference === 'invidious' && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
resolve(this.getChannelPostsLocal(channel))
|
resolve(this.getChannelPostsLocal(channel))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -135,7 +135,7 @@ export default defineComponent({
|
||||||
let videos = []
|
let videos = []
|
||||||
let name, thumbnailUrl
|
let name, thumbnailUrl
|
||||||
|
|
||||||
if (!process.env.IS_ELECTRON || this.backendPreference === 'invidious') {
|
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
|
||||||
if (useRss) {
|
if (useRss) {
|
||||||
({ videos, name, thumbnailUrl } = await this.getChannelLiveInvidiousRSS(channel))
|
({ videos, name, thumbnailUrl } = await this.getChannelLiveInvidiousRSS(channel))
|
||||||
} else {
|
} else {
|
||||||
|
@ -315,7 +315,7 @@ export default defineComponent({
|
||||||
resolve(this.getChannelLiveInvidiousRSS(channel, failedAttempts + 1))
|
resolve(this.getChannelLiveInvidiousRSS(channel, failedAttempts + 1))
|
||||||
break
|
break
|
||||||
case 1:
|
case 1:
|
||||||
if (process.env.IS_ELECTRON && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
resolve(this.getChannelLiveLocal(channel, failedAttempts + 1))
|
resolve(this.getChannelLiveLocal(channel, failedAttempts + 1))
|
||||||
} else {
|
} else {
|
||||||
|
@ -360,7 +360,7 @@ export default defineComponent({
|
||||||
case 0:
|
case 0:
|
||||||
return this.getChannelLiveInvidious(channel, failedAttempts + 1)
|
return this.getChannelLiveInvidious(channel, failedAttempts + 1)
|
||||||
case 1:
|
case 1:
|
||||||
if (process.env.IS_ELECTRON && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
return this.getChannelLiveLocalRSS(channel, failedAttempts + 1)
|
return this.getChannelLiveLocalRSS(channel, failedAttempts + 1)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -120,7 +120,7 @@ export default defineComponent({
|
||||||
let videos = []
|
let videos = []
|
||||||
let name
|
let name
|
||||||
|
|
||||||
if (!process.env.IS_ELECTRON || this.backendPreference === 'invidious') {
|
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
|
||||||
({ videos, name } = await this.getChannelShortsInvidious(channel))
|
({ videos, name } = await this.getChannelShortsInvidious(channel))
|
||||||
} else {
|
} else {
|
||||||
({ videos, name } = await this.getChannelShortsLocal(channel))
|
({ videos, name } = await this.getChannelShortsLocal(channel))
|
||||||
|
@ -234,7 +234,7 @@ export default defineComponent({
|
||||||
})
|
})
|
||||||
switch (failedAttempts) {
|
switch (failedAttempts) {
|
||||||
case 0:
|
case 0:
|
||||||
if (process.env.IS_ELECTRON && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
return this.getChannelShortsLocal(channel, failedAttempts + 1)
|
return this.getChannelShortsLocal(channel, failedAttempts + 1)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -135,7 +135,7 @@ export default defineComponent({
|
||||||
let videos = []
|
let videos = []
|
||||||
let name, thumbnailUrl
|
let name, thumbnailUrl
|
||||||
|
|
||||||
if (!process.env.IS_ELECTRON || this.backendPreference === 'invidious') {
|
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
|
||||||
if (useRss) {
|
if (useRss) {
|
||||||
({ videos, name, thumbnailUrl } = await this.getChannelVideosInvidiousRSS(channel))
|
({ videos, name, thumbnailUrl } = await this.getChannelVideosInvidiousRSS(channel))
|
||||||
} else {
|
} else {
|
||||||
|
@ -312,7 +312,7 @@ export default defineComponent({
|
||||||
resolve(this.getChannelVideosInvidiousRSS(channel, failedAttempts + 1))
|
resolve(this.getChannelVideosInvidiousRSS(channel, failedAttempts + 1))
|
||||||
break
|
break
|
||||||
case 1:
|
case 1:
|
||||||
if (process.env.IS_ELECTRON && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
resolve(this.getChannelVideosLocalScraper(channel, failedAttempts + 1))
|
resolve(this.getChannelVideosLocalScraper(channel, failedAttempts + 1))
|
||||||
} else {
|
} else {
|
||||||
|
@ -358,7 +358,7 @@ export default defineComponent({
|
||||||
case 0:
|
case 0:
|
||||||
return this.getChannelVideosInvidiousScraper(channel, failedAttempts + 1)
|
return this.getChannelVideosInvidiousScraper(channel, failedAttempts + 1)
|
||||||
case 1:
|
case 1:
|
||||||
if (process.env.IS_ELECTRON && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
return this.getChannelVideosLocalRSS(channel, failedAttempts + 1)
|
return this.getChannelVideosLocalRSS(channel, failedAttempts + 1)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -284,7 +284,7 @@ export default defineComponent({
|
||||||
this.searchSuggestionsDataList = results.suggestions
|
this.searchSuggestionsDataList = results.suggestions
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
if (process.env.IS_ELECTRON && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendFallback) {
|
||||||
console.error(
|
console.error(
|
||||||
'Error gettings search suggestions. Falling back to Local API'
|
'Error gettings search suggestions. Falling back to Local API'
|
||||||
)
|
)
|
||||||
|
|
|
@ -151,7 +151,7 @@ export default defineComponent({
|
||||||
|
|
||||||
getCommentData: function () {
|
getCommentData: function () {
|
||||||
this.isLoading = true
|
this.isLoading = true
|
||||||
if (!process.env.IS_ELECTRON || this.backendPreference === 'invidious') {
|
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
|
||||||
this.getCommentDataInvidious()
|
this.getCommentDataInvidious()
|
||||||
} else {
|
} else {
|
||||||
this.getCommentDataLocal()
|
this.getCommentDataLocal()
|
||||||
|
@ -162,7 +162,7 @@ export default defineComponent({
|
||||||
if (this.commentData.length === 0 || this.nextPageToken === null || typeof this.nextPageToken === 'undefined') {
|
if (this.commentData.length === 0 || this.nextPageToken === null || typeof this.nextPageToken === 'undefined') {
|
||||||
showToast(this.$t('Comments.There are no more comments for this video'))
|
showToast(this.$t('Comments.There are no more comments for this video'))
|
||||||
} else {
|
} else {
|
||||||
if (!process.env.IS_ELECTRON || this.backendPreference === 'invidious') {
|
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
|
||||||
this.getCommentDataInvidious()
|
this.getCommentDataInvidious()
|
||||||
} else {
|
} else {
|
||||||
this.getCommentDataLocal(true)
|
this.getCommentDataLocal(true)
|
||||||
|
@ -179,7 +179,7 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
|
|
||||||
getCommentReplies: function (index) {
|
getCommentReplies: function (index) {
|
||||||
if (process.env.IS_ELECTRON) {
|
if (process.env.SUPPORTS_LOCAL_API) {
|
||||||
switch (this.commentData[index].dataType) {
|
switch (this.commentData[index].dataType) {
|
||||||
case 'local':
|
case 'local':
|
||||||
this.getCommentRepliesLocal(index)
|
this.getCommentRepliesLocal(index)
|
||||||
|
@ -292,7 +292,7 @@ export default defineComponent({
|
||||||
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
||||||
copyToClipboard(err)
|
copyToClipboard(err)
|
||||||
})
|
})
|
||||||
if (process.env.IS_ELECTRON && this.backendFallback && this.backendPreference === 'invidious') {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendFallback && this.backendPreference === 'invidious') {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
this.getCommentDataLocal()
|
this.getCommentDataLocal()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -94,7 +94,7 @@ export default defineComponent({
|
||||||
this.liveChatInstance = null
|
this.liveChatInstance = null
|
||||||
},
|
},
|
||||||
created: function () {
|
created: function () {
|
||||||
if (!process.env.IS_ELECTRON) {
|
if (!process.env.SUPPORTS_LOCAL_API) {
|
||||||
this.hasError = true
|
this.hasError = true
|
||||||
this.errorMessage = this.$t('Video["Live Chat is currently not supported in this build."]')
|
this.errorMessage = this.$t('Video["Live Chat is currently not supported in this build."]')
|
||||||
this.isLoading = false
|
this.isLoading = false
|
||||||
|
|
|
@ -210,7 +210,7 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
playlistId: function (newVal, oldVal) {
|
playlistId: function (newVal, oldVal) {
|
||||||
if (oldVal !== newVal) {
|
if (oldVal !== newVal) {
|
||||||
if (!process.env.IS_ELECTRON || this.backendPreference === 'invidious') {
|
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
|
||||||
this.getPlaylistInformationInvidious()
|
this.getPlaylistInformationInvidious()
|
||||||
} else {
|
} else {
|
||||||
this.getPlaylistInformationLocal()
|
this.getPlaylistInformationLocal()
|
||||||
|
@ -249,7 +249,7 @@ export default defineComponent({
|
||||||
|
|
||||||
if (this.selectedUserPlaylist != null) {
|
if (this.selectedUserPlaylist != null) {
|
||||||
this.parseUserPlaylist(this.selectedUserPlaylist)
|
this.parseUserPlaylist(this.selectedUserPlaylist)
|
||||||
} else if (!process.env.IS_ELECTRON || this.backendPreference === 'invidious') {
|
} else if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
|
||||||
this.getPlaylistInformationInvidious()
|
this.getPlaylistInformationInvidious()
|
||||||
} else {
|
} else {
|
||||||
this.getPlaylistInformationLocal()
|
this.getPlaylistInformationLocal()
|
||||||
|
@ -386,7 +386,7 @@ export default defineComponent({
|
||||||
this.channelName = cachedPlaylist.channelName
|
this.channelName = cachedPlaylist.channelName
|
||||||
this.channelId = cachedPlaylist.channelId
|
this.channelId = cachedPlaylist.channelId
|
||||||
|
|
||||||
if (!process.env.IS_ELECTRON || this.backendPreference === 'invidious' || cachedPlaylist.continuationData === null) {
|
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious' || cachedPlaylist.continuationData === null) {
|
||||||
this.playlistItems = cachedPlaylist.items
|
this.playlistItems = cachedPlaylist.items
|
||||||
} else {
|
} else {
|
||||||
const videos = cachedPlaylist.items
|
const videos = cachedPlaylist.items
|
||||||
|
@ -462,7 +462,7 @@ export default defineComponent({
|
||||||
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
||||||
copyToClipboard(err)
|
copyToClipboard(err)
|
||||||
})
|
})
|
||||||
if (process.env.IS_ELECTRON && this.backendPreference === 'invidious' && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
this.getPlaylistInformationLocal()
|
this.getPlaylistInformationLocal()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -321,10 +321,10 @@ export function filterInvidiousFormats(formats, allowAv1 = false) {
|
||||||
// Which is caused by Invidious API limitation on AV1 formats (see related issues)
|
// Which is caused by Invidious API limitation on AV1 formats (see related issues)
|
||||||
// Commented code to be restored after Invidious issue fixed
|
// Commented code to be restored after Invidious issue fixed
|
||||||
//
|
//
|
||||||
// As we generate our own DASH manifest (using YouTube.js) for multiple audio track support in Electron,
|
// As we generate our own DASH manifest (using YouTube.js) for multiple audio track support when the local API is supported,
|
||||||
// we can allow AV1 in that situation. If we aren't in electron,
|
// we can allow AV1 in that situation. When the local API isn't supported,
|
||||||
// we still can't use them until Invidious fixes the issue on their side
|
// we still can't use them until Invidious fixes the issue on their side
|
||||||
if (process.env.IS_ELECTRON && allowAv1 && av1Formats.length > 0) {
|
if (process.env.SUPPORTS_LOCAL_API && allowAv1 && av1Formats.length > 0) {
|
||||||
return [...audioFormats, ...av1Formats]
|
return [...audioFormats, ...av1Formats]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { ClientType, Endpoints, Innertube, Misc, Utils, YT } from 'youtubei.js'
|
import { ClientType, Endpoints, Innertube, Misc, UniversalCache, Utils, YT } from 'youtubei.js'
|
||||||
import Autolinker from 'autolinker'
|
import Autolinker from 'autolinker'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
|
|
||||||
|
@ -39,8 +39,12 @@ const TRACKING_PARAM_NAMES = [
|
||||||
async function createInnertube({ withPlayer = false, location = undefined, safetyMode = false, clientType = undefined, generateSessionLocally = true } = {}) {
|
async function createInnertube({ withPlayer = false, location = undefined, safetyMode = false, clientType = undefined, generateSessionLocally = true } = {}) {
|
||||||
let cache
|
let cache
|
||||||
if (withPlayer) {
|
if (withPlayer) {
|
||||||
const userData = await getUserDataPath()
|
if (process.env.IS_ELECTRON) {
|
||||||
cache = new PlayerCache(join(userData, 'player_cache'))
|
const userData = await getUserDataPath()
|
||||||
|
cache = new PlayerCache(join(userData, 'player_cache'))
|
||||||
|
} else {
|
||||||
|
cache = new UniversalCache(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return await Innertube.create({
|
return await Innertube.create({
|
||||||
|
|
|
@ -11,7 +11,7 @@ import { getLocalChannel } from './api/local'
|
||||||
*/
|
*/
|
||||||
async function findChannelById(id, backendOptions) {
|
async function findChannelById(id, backendOptions) {
|
||||||
try {
|
try {
|
||||||
if (!process.env.IS_ELECTRON || backendOptions.preference === 'invidious') {
|
if (!process.env.SUPPORTS_LOCAL_API || backendOptions.preference === 'invidious') {
|
||||||
return await invidiousGetChannelInfo(id)
|
return await invidiousGetChannelInfo(id)
|
||||||
} else {
|
} else {
|
||||||
return await getLocalChannel(id)
|
return await getLocalChannel(id)
|
||||||
|
@ -21,7 +21,7 @@ async function findChannelById(id, backendOptions) {
|
||||||
if (err.message && err.message === 'This channel does not exist.') {
|
if (err.message && err.message === 'This channel does not exist.') {
|
||||||
return { invalid: true }
|
return { invalid: true }
|
||||||
}
|
}
|
||||||
if (process.env.IS_ELECTRON && backendOptions.fallback) {
|
if (process.env.SUPPORTS_LOCAL_API && backendOptions.fallback) {
|
||||||
if (backendOptions.preference === 'invidious') {
|
if (backendOptions.preference === 'invidious') {
|
||||||
return await getLocalChannel(id)
|
return await getLocalChannel(id)
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ export async function findChannelTagInfo(id, backendOptions) {
|
||||||
if (!checkYoutubeChannelId(id)) return { invalidId: true }
|
if (!checkYoutubeChannelId(id)) return { invalidId: true }
|
||||||
try {
|
try {
|
||||||
const channel = await findChannelById(id, backendOptions)
|
const channel = await findChannelById(id, backendOptions)
|
||||||
if (!process.env.IS_ELECTRON || backendOptions.preference === 'invidious') {
|
if (!process.env.SUPPORTS_LOCAL_API || backendOptions.preference === 'invidious') {
|
||||||
if (channel.invalid) return { invalidId: true }
|
if (channel.invalid) return { invalidId: true }
|
||||||
return {
|
return {
|
||||||
preferredName: channel.author,
|
preferredName: channel.author,
|
||||||
|
|
|
@ -28,7 +28,7 @@ const actions = {
|
||||||
return !(instance[0].includes('.onion') ||
|
return !(instance[0].includes('.onion') ||
|
||||||
instance[0].includes('.i2p') ||
|
instance[0].includes('.i2p') ||
|
||||||
!instance[1].api ||
|
!instance[1].api ||
|
||||||
(!process.env.IS_ELECTRON && !instance[1].cors))
|
(!process.env.SUPPORTS_LOCAL_API && !instance[1].cors))
|
||||||
}).map((instance) => {
|
}).map((instance) => {
|
||||||
return instance[1].uri.replace(/\/$/, '')
|
return instance[1].uri.replace(/\/$/, '')
|
||||||
})
|
})
|
||||||
|
@ -50,7 +50,7 @@ const actions = {
|
||||||
console.warn('reading static file for invidious instances')
|
console.warn('reading static file for invidious instances')
|
||||||
const fileData = process.env.IS_ELECTRON ? await fs.readFile(filePath, 'utf8') : await (await fetch(createWebURL(filePath))).text()
|
const fileData = process.env.IS_ELECTRON ? await fs.readFile(filePath, 'utf8') : await (await fetch(createWebURL(filePath))).text()
|
||||||
instances = JSON.parse(fileData).filter(e => {
|
instances = JSON.parse(fileData).filter(e => {
|
||||||
return process.env.IS_ELECTRON || e.cors
|
return process.env.SUPPORTS_LOCAL_API || e.cors
|
||||||
}).map(e => {
|
}).map(e => {
|
||||||
return e.url
|
return e.url
|
||||||
})
|
})
|
||||||
|
|
|
@ -165,8 +165,8 @@ const state = {
|
||||||
allSettingsSectionsExpandedByDefault: false,
|
allSettingsSectionsExpandedByDefault: false,
|
||||||
autoplayPlaylists: true,
|
autoplayPlaylists: true,
|
||||||
autoplayVideos: true,
|
autoplayVideos: true,
|
||||||
backendFallback: process.env.IS_ELECTRON,
|
backendFallback: process.env.SUPPORTS_LOCAL_API,
|
||||||
backendPreference: !process.env.IS_ELECTRON ? 'invidious' : 'local',
|
backendPreference: !process.env.SUPPORTS_LOCAL_API ? 'invidious' : 'local',
|
||||||
barColor: false,
|
barColor: false,
|
||||||
checkForBlogPosts: true,
|
checkForBlogPosts: true,
|
||||||
checkForUpdates: true,
|
checkForUpdates: true,
|
||||||
|
@ -237,7 +237,7 @@ const state = {
|
||||||
proxyHostname: '127.0.0.1',
|
proxyHostname: '127.0.0.1',
|
||||||
proxyPort: '9050',
|
proxyPort: '9050',
|
||||||
proxyProtocol: 'socks5',
|
proxyProtocol: 'socks5',
|
||||||
proxyVideos: !process.env.IS_ELECTRON,
|
proxyVideos: !process.env.SUPPORTS_LOCAL_API,
|
||||||
region: 'US',
|
region: 'US',
|
||||||
rememberHistory: true,
|
rememberHistory: true,
|
||||||
saveWatchedProgress: true,
|
saveWatchedProgress: true,
|
||||||
|
|
|
@ -351,7 +351,7 @@ export default defineComponent({
|
||||||
this.errorMessage = ''
|
this.errorMessage = ''
|
||||||
|
|
||||||
// Re-enable auto refresh on sort value change AFTER update done
|
// Re-enable auto refresh on sort value change AFTER update done
|
||||||
if (!process.env.IS_ELECTRON || this.backendPreference === 'invidious') {
|
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
|
||||||
this.getChannelInfoInvidious()
|
this.getChannelInfoInvidious()
|
||||||
this.autoRefreshOnSortByChangeEnabled = true
|
this.autoRefreshOnSortByChangeEnabled = true
|
||||||
} else {
|
} else {
|
||||||
|
@ -449,7 +449,7 @@ export default defineComponent({
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable auto refresh on sort value change AFTER initial update done
|
// Enable auto refresh on sort value change AFTER initial update done
|
||||||
if (!process.env.IS_ELECTRON || this.backendPreference === 'invidious') {
|
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
|
||||||
this.getChannelInfoInvidious()
|
this.getChannelInfoInvidious()
|
||||||
this.autoRefreshOnSortByChangeEnabled = true
|
this.autoRefreshOnSortByChangeEnabled = true
|
||||||
} else {
|
} else {
|
||||||
|
@ -462,7 +462,7 @@ export default defineComponent({
|
||||||
resolveChannelUrl: async function (url, tab = undefined) {
|
resolveChannelUrl: async function (url, tab = undefined) {
|
||||||
let id
|
let id
|
||||||
|
|
||||||
if (!process.env.IS_ELECTRON || this.backendPreference === 'invidious') {
|
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
|
||||||
id = await invidiousGetChannelId(url)
|
id = await invidiousGetChannelId(url)
|
||||||
} else {
|
} else {
|
||||||
id = await getLocalChannelId(url)
|
id = await getLocalChannelId(url)
|
||||||
|
@ -1051,7 +1051,7 @@ export default defineComponent({
|
||||||
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
||||||
copyToClipboard(err)
|
copyToClipboard(err)
|
||||||
})
|
})
|
||||||
if (process.env.IS_ELECTRON && this.backendPreference === 'invidious' && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
this.getChannelLocal()
|
this.getChannelLocal()
|
||||||
} else {
|
} else {
|
||||||
|
@ -1329,7 +1329,7 @@ export default defineComponent({
|
||||||
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
||||||
copyToClipboard(err)
|
copyToClipboard(err)
|
||||||
})
|
})
|
||||||
if (process.env.IS_ELECTRON && this.backendPreference === 'invidious' && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
if (!this.channelInstance) {
|
if (!this.channelInstance) {
|
||||||
this.channelInstance = await getLocalChannel(this.id)
|
this.channelInstance = await getLocalChannel(this.id)
|
||||||
|
@ -1370,7 +1370,7 @@ export default defineComponent({
|
||||||
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
||||||
copyToClipboard(err)
|
copyToClipboard(err)
|
||||||
})
|
})
|
||||||
if (process.env.IS_ELECTRON && this.backendPreference === 'invidious' && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
this.getChannelLocal()
|
this.getChannelLocal()
|
||||||
} else {
|
} else {
|
||||||
|
@ -1449,7 +1449,7 @@ export default defineComponent({
|
||||||
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
||||||
copyToClipboard(err)
|
copyToClipboard(err)
|
||||||
})
|
})
|
||||||
if (process.env.IS_ELECTRON && this.backendPreference === 'invidious' && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
if (!this.channelInstance) {
|
if (!this.channelInstance) {
|
||||||
this.channelInstance = await getLocalChannel(this.id)
|
this.channelInstance = await getLocalChannel(this.id)
|
||||||
|
@ -1483,7 +1483,7 @@ export default defineComponent({
|
||||||
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
||||||
copyToClipboard(err)
|
copyToClipboard(err)
|
||||||
})
|
})
|
||||||
if (process.env.IS_ELECTRON && this.backendPreference === 'invidious' && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
this.getChannelLocal()
|
this.getChannelLocal()
|
||||||
} else {
|
} else {
|
||||||
|
@ -1562,7 +1562,7 @@ export default defineComponent({
|
||||||
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
||||||
copyToClipboard(err)
|
copyToClipboard(err)
|
||||||
})
|
})
|
||||||
if (process.env.IS_ELECTRON && this.backendPreference === 'invidious' && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
if (!this.channelInstance) {
|
if (!this.channelInstance) {
|
||||||
this.channelInstance = await getLocalChannel(this.id)
|
this.channelInstance = await getLocalChannel(this.id)
|
||||||
|
@ -1596,7 +1596,7 @@ export default defineComponent({
|
||||||
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
||||||
copyToClipboard(err)
|
copyToClipboard(err)
|
||||||
})
|
})
|
||||||
if (process.env.IS_ELECTRON && this.backendPreference === 'invidious' && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
this.getChannelLocal()
|
this.getChannelLocal()
|
||||||
} else {
|
} else {
|
||||||
|
@ -1716,7 +1716,7 @@ export default defineComponent({
|
||||||
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
||||||
copyToClipboard(err)
|
copyToClipboard(err)
|
||||||
})
|
})
|
||||||
if (process.env.IS_ELECTRON && this.backendPreference === 'invidious' && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
if (!this.channelInstance) {
|
if (!this.channelInstance) {
|
||||||
this.channelInstance = await getLocalChannel(this.id)
|
this.channelInstance = await getLocalChannel(this.id)
|
||||||
|
@ -1939,7 +1939,7 @@ export default defineComponent({
|
||||||
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
||||||
copyToClipboard(err)
|
copyToClipboard(err)
|
||||||
})
|
})
|
||||||
if (process.env.IS_ELECTRON && this.backendPreference === 'invidious' && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
this.searchChannelLocal()
|
this.searchChannelLocal()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -85,7 +85,7 @@ export default defineComponent({
|
||||||
showToast(`${errorMessage}: ${error}`, 10000, () => {
|
showToast(`${errorMessage}: ${error}`, 10000, () => {
|
||||||
copyToClipboard(error)
|
copyToClipboard(error)
|
||||||
})
|
})
|
||||||
if (process.env.IS_ELECTRON && this.backendPreference === 'invidious' && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
this.resetData()
|
this.resetData()
|
||||||
this.getLocalHashtag(hashtag)
|
this.getLocalHashtag(hashtag)
|
||||||
|
|
|
@ -313,7 +313,7 @@ export default defineComponent({
|
||||||
this.isLoading = false
|
this.isLoading = false
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
if (process.env.IS_ELECTRON && this.backendPreference === 'invidious' && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) {
|
||||||
console.warn('Error getting data with Invidious, falling back to local backend')
|
console.warn('Error getting data with Invidious, falling back to local backend')
|
||||||
this.getPlaylistLocal()
|
this.getPlaylistLocal()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -246,7 +246,7 @@ export default defineComponent({
|
||||||
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
showToast(`${errorMessage}: ${err}`, 10000, () => {
|
||||||
copyToClipboard(err)
|
copyToClipboard(err)
|
||||||
})
|
})
|
||||||
if (process.env.IS_ELECTRON && this.backendPreference === 'invidious' && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
this.performSearchLocal(payload)
|
this.performSearchLocal(payload)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -85,7 +85,7 @@ export default defineComponent({
|
||||||
this.$store.commit('clearTrendingCache')
|
this.$store.commit('clearTrendingCache')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!process.env.IS_ELECTRON || this.backendPreference === 'invidious') {
|
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
|
||||||
this.getTrendingInfoInvidious()
|
this.getTrendingInfoInvidious()
|
||||||
} else {
|
} else {
|
||||||
this.getTrendingInfoLocal()
|
this.getTrendingInfoLocal()
|
||||||
|
@ -161,7 +161,7 @@ export default defineComponent({
|
||||||
copyToClipboard(err.responseText)
|
copyToClipboard(err.responseText)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (process.env.IS_ELECTRON && (this.backendPreference === 'invidious' && this.backendFallback)) {
|
if (process.env.SUPPORTS_LOCAL_API && (this.backendPreference === 'invidious' && this.backendFallback)) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
this.getTrendingInfoLocal()
|
this.getTrendingInfoLocal()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -289,7 +289,7 @@ export default defineComponent({
|
||||||
this.checkIfPlaylist()
|
this.checkIfPlaylist()
|
||||||
this.checkIfTimestamp()
|
this.checkIfTimestamp()
|
||||||
|
|
||||||
if (!process.env.IS_ELECTRON || this.backendPreference === 'invidious') {
|
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
|
||||||
this.getVideoInformationInvidious()
|
this.getVideoInformationInvidious()
|
||||||
} else {
|
} else {
|
||||||
this.getVideoInformationLocal()
|
this.getVideoInformationLocal()
|
||||||
|
@ -870,8 +870,8 @@ export default defineComponent({
|
||||||
this.audioTracks = []
|
this.audioTracks = []
|
||||||
this.dashSrc = await this.createInvidiousDashManifest()
|
this.dashSrc = await this.createInvidiousDashManifest()
|
||||||
|
|
||||||
if (process.env.IS_ELECTRON && this.audioTracks.length > 0) {
|
if (process.env.SUPPORTS_LOCAL_API && this.audioTracks.length > 0) {
|
||||||
// when we are in Electron and the video has multiple audio tracks,
|
// when the local API is supported and the video has multiple audio tracks,
|
||||||
// we populate the list inside createInvidiousDashManifest
|
// we populate the list inside createInvidiousDashManifest
|
||||||
// as we need to work out the different audio tracks for the DASH manifest anyway
|
// as we need to work out the different audio tracks for the DASH manifest anyway
|
||||||
this.audioSourceList = this.audioTracks.find(track => track.isDefault).sourceList
|
this.audioSourceList = this.audioTracks.find(track => track.isDefault).sourceList
|
||||||
|
@ -908,7 +908,7 @@ export default defineComponent({
|
||||||
copyToClipboard(err.responseText)
|
copyToClipboard(err.responseText)
|
||||||
})
|
})
|
||||||
console.error(err)
|
console.error(err)
|
||||||
if (process.env.IS_ELECTRON && this.backendPreference === 'invidious' && this.backendFallback) {
|
if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) {
|
||||||
showToast(this.$t('Falling back to Local API'))
|
showToast(this.$t('Falling back to Local API'))
|
||||||
this.getVideoInformationLocal()
|
this.getVideoInformationLocal()
|
||||||
} else {
|
} else {
|
||||||
|
@ -1233,7 +1233,7 @@ export default defineComponent({
|
||||||
copyToClipboard(err)
|
copyToClipboard(err)
|
||||||
})
|
})
|
||||||
console.error(err)
|
console.error(err)
|
||||||
if (!process.env.IS_ELECTRON || (this.backendPreference === 'local' && this.backendFallback)) {
|
if (!process.env.SUPPORTS_LOCAL_API || (this.backendPreference === 'local' && this.backendFallback)) {
|
||||||
showToast(this.$t('Falling back to Invidious API'))
|
showToast(this.$t('Falling back to Invidious API'))
|
||||||
this.getVideoInformationInvidious()
|
this.getVideoInformationInvidious()
|
||||||
}
|
}
|
||||||
|
@ -1471,7 +1471,7 @@ export default defineComponent({
|
||||||
// If we are in Electron,
|
// If we are in Electron,
|
||||||
// we can use YouTube.js' DASH manifest generator to generate the manifest.
|
// we can use YouTube.js' DASH manifest generator to generate the manifest.
|
||||||
// Using YouTube.js' gives us support for multiple audio tracks (currently not supported by Invidious)
|
// Using YouTube.js' gives us support for multiple audio tracks (currently not supported by Invidious)
|
||||||
if (process.env.IS_ELECTRON) {
|
if (process.env.SUPPORTS_LOCAL_API) {
|
||||||
// Invidious' API response doesn't include the height and width (and fps and qualityLabel for AV1) of video streams
|
// Invidious' API response doesn't include the height and width (and fps and qualityLabel for AV1) of video streams
|
||||||
// so we need to extract them from Invidious' manifest
|
// so we need to extract them from Invidious' manifest
|
||||||
const response = await fetch(url)
|
const response = await fetch(url)
|
||||||
|
|
Loading…
Reference in New Issue