Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
move invidious out of stores
  • Loading branch information
ChunkyProgrammer committed Jan 10, 2023
commit 5b8ab1ecb85421977289d19036609ef8180a2651
4 changes: 2 additions & 2 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ function runApp() {
darkTheme: nativeTheme.shouldUseDarkColors,
icon: process.env.NODE_ENV === 'development'
? path.join(__dirname, '../../_icons/iconColor.png')
/* eslint-disable-next-line */
/* eslint-disable-next-line n/no-path-concat */
: `${__dirname}/_icons/iconColor.png`,
autoHideMenuBar: true,
// useContentSize: true,
Expand Down Expand Up @@ -548,7 +548,7 @@ function runApp() {
if (windowStartupUrl != null) {
newWindow.loadURL(windowStartupUrl)
} else {
/* eslint-disable-next-line */
/* eslint-disable-next-line n/no-path-concat */
newWindow.loadFile(`${__dirname}/index.html`)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/top-nav/top-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import debounce from 'lodash.debounce'
import { IpcChannels } from '../../../constants'
import { openInternalPath, showToast } from '../../helpers/utils'
import { clearLocalSearchSuggestionsSession, getLocalSearchSuggestions } from '../../helpers/api/local'
import { invidiousAPICall } from '../../helpers/api/invidious'

export default Vue.extend({
name: 'TopNav',
Expand Down Expand Up @@ -257,7 +258,7 @@ export default Vue.extend({
}
}

this.invidiousAPICall(searchPayload).then((results) => {
invidiousAPICall(searchPayload).then((results) => {
this.searchSuggestionsDataList = results.suggestions
}).catch((err) => {
console.error(err)
Expand Down Expand Up @@ -339,7 +340,6 @@ export default Vue.extend({
},
...mapActions([
'getYoutubeUrlInfo',
'invidiousAPICall'
])
}
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Vue from 'vue'
import { mapActions } from 'vuex'
import FtCard from '../ft-card/ft-card.vue'
import FtLoader from '../../components/ft-loader/ft-loader.vue'
import FtSelect from '../../components/ft-select/ft-select.vue'
Expand All @@ -12,6 +11,7 @@ import {
stripHTML,
toLocalePublicationString
} from '../../helpers/utils'
import { invidiousGetCommentReplies, invidiousGetComments } from '../../helpers/api/invidious'

export default Vue.extend({
name: 'WatchVideoComments',
Expand Down Expand Up @@ -245,50 +245,12 @@ export default Vue.extend({
}
},

parseInvidiousCommentData: function (response) {
return response.comments.map((comment) => {
comment.showReplies = false
comment.authorLink = comment.authorId
comment.authorThumb = comment.authorThumbnails[1].url.replace('https://yt3.ggpht.com', `${this.currentInvidiousInstance}/ggpht/`)
if (this.hideCommentLikes) {
comment.likes = null
} else {
comment.likes = comment.likeCount
}
comment.text = autolinker.link(stripHTML(comment.content))
comment.dataType = 'invidious'
comment.isOwner = comment.authorIsChannelOwner

if (typeof (comment.replies) !== 'undefined' && typeof (comment.replies.replyCount) !== 'undefined') {
comment.numReplies = comment.replies.replyCount
comment.replyContinuation = comment.replies.continuation
} else {
comment.numReplies = 0
comment.replyContinuation = ''
}

comment.replies = []
comment.time = toLocalePublicationString({
publishText: comment.publishedText
})

return comment
})
},

getCommentDataInvidious: function () {
const payload = {
resource: 'comments',
invidiousGetComments({
id: this.id,
params: {
continuation: this.nextPageToken ?? '',
sort_by: this.sortNewest ? 'new' : 'top'
}
}

this.invidiousAPICall(payload).then((response) => {
const commentData = this.parseInvidiousCommentData(response)

nextPageToken: this.nextPageToken,
sortNewest: this.sortNewest
}).then(({ response, commentData }) => {
this.commentData = this.commentData.concat(commentData)
this.nextPageToken = response.continuation
this.isLoading = false
Expand All @@ -310,32 +272,20 @@ export default Vue.extend({

getCommentRepliesInvidious: function (index) {
showToast(this.$t('Comments.Getting comment replies, please wait'))
const payload = {
resource: 'comments',
id: this.id,
params: {
continuation: this.commentData[index].replyContinuation
}
}

this.invidiousAPICall(payload).then((response) => {
const commentData = this.parseInvidiousCommentData(response)

this.commentData[index].replies = commentData
this.commentData[index].showReplies = true
this.isLoading = false
}).catch((xhr) => {
console.error(xhr)
const errorMessage = this.$t('Invidious API Error (Click to copy)')
showToast(`${errorMessage}: ${xhr.responseText}`, 10000, () => {
copyToClipboard(xhr.responseText)
const replyContinuation = this.commentData[index].replyContinuation
invidiousGetCommentReplies({ id: this.id, replyContinuation: replyContinuation })
.then((commentData) => {
this.commentData[index].replies = commentData
this.commentData[index].showReplies = true
this.isLoading = false
}).catch((xhr) => {
console.error(xhr)
const errorMessage = this.$t('Invidious API Error (Click to copy)')
showToast(`${errorMessage}: ${xhr.responseText}`, 10000, () => {
copyToClipboard(xhr.responseText)
})
this.isLoading = false
})
this.isLoading = false
})
},

...mapActions([
'invidiousAPICall'
])
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ export default Vue.extend({
},
mounted: function () {
if ('mediaSession' in navigator) {
/* eslint-disable-next-line */
navigator.mediaSession.metadata = new MediaMetadata({
title: this.title,
artist: this.channelName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Vue from 'vue'
import { mapActions, mapMutations } from 'vuex'
import { mapMutations } from 'vuex'
import FtLoader from '../ft-loader/ft-loader.vue'
import FtCard from '../ft-card/ft-card.vue'
import FtListVideoLazy from '../ft-list-video-lazy/ft-list-video-lazy.vue'
import { copyToClipboard, showToast } from '../../helpers/utils'
import { getLocalPlaylist, parseLocalPlaylistVideo } from '../../helpers/api/local'
import { invidiousGetPlaylistInfo } from '../../helpers/api/invidious'

export default Vue.extend({
name: 'WatchVideoPlaylist',
Expand Down Expand Up @@ -316,12 +317,7 @@ export default Vue.extend({
getPlaylistInformationInvidious: function () {
this.isLoading = true

const payload = {
resource: 'playlists',
id: this.playlistId
}

this.invidiousGetPlaylistInfo(payload).then((result) => {
invidiousGetPlaylistInfo({ playlistId: this.playlistId }).then((result) => {
this.playlistTitle = result.title
this.channelName = result.author
this.channelId = result.authorId
Expand Down Expand Up @@ -364,10 +360,6 @@ export default Vue.extend({
this.randomizedPlaylistItems = items
},

...mapActions([
'invidiousGetPlaylistInfo'
]),

...mapMutations([
'setCachedPlaylist'
])
Expand Down
112 changes: 112 additions & 0 deletions src/renderer/helpers/api/invidious.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import store from '../../store/index'
import { stripHTML, toLocalePublicationString } from '../utils'
import autolinker from 'autolinker'

function getCurrentInstance() {
return store.getters.getCurrentInvidiousInstance
}

export function invidiousAPICall({ resource, id = '', params = {} }) {
return new Promise((resolve, reject) => {
const requestUrl = getCurrentInstance() + '/api/v1/' + resource + '/' + id + '?' + new URLSearchParams(params).toString()

fetch(requestUrl)
.then((response) => response.json())
.then((json) => {
resolve(json)
})
.catch((error) => {
console.error('Invidious API error', requestUrl, error)
reject(error)
})
})
}

export async function invidiousGetChannelInfo(channelId) {
return new Promise((resolve, reject) => {
invidiousAPICall({
resource: 'channels',
id: channelId,
}).then(response => {
resolve(response)
}).catch(xhr => {
console.error(xhr)
reject(xhr)
})
})
}

export async function invidiousGetPlaylistInfo(playlistId) {
const payload = {
resource: 'playlists',
id: playlistId
}
return new Promise((resolve, reject) => {
invidiousAPICall(payload).then((response) => {
resolve(response)
}).catch((xhr) => {
console.error(xhr)
reject(xhr)
})
})
}

export async function invidiousGetVideoInformation(videoId) {
return new Promise((resolve, reject) => {
invidiousAPICall({ resource: 'videos', id: videoId }).then((response) => {
resolve(response)
}).catch((xhr) => {
console.error(xhr)
reject(xhr)
})
})
}
export async function invidiousGetComments({ id, nextPageToken = '', sortNewest = true }) {
const payload = {
resource: 'comments',
id: id,
params: {
continuation: nextPageToken ?? '',
sort_by: sortNewest ? 'new' : 'top'
}
}
const response = await invidiousAPICall(payload)

const commentData = parseInvidiousCommentData(response)

return { response, commentData }
}

export async function invidiousGetCommentReplies({ id, replyContinuation }) {
const payload = {
resource: 'comments',
id: id,
params: {
continuation: replyContinuation
}
}

const response = await invidiousAPICall(payload)
return parseInvidiousCommentData(response)
}

function parseInvidiousCommentData(comments) {
return comments.map((comment) => {
comment.showReplies = false
comment.authorLink = comment.authorId
comment.authorThumb = comment.authorThumbnails[1].url.replace('https://yt3.ggpht.com', `${getCurrentInstance()}/ggpht/`)
comment.likes = comment.likeCount
comment.text = autolinker.link(stripHTML(comment.content))
comment.dataType = 'invidious'
comment.isOwner = comment.authorIsChannelOwner
comment.numReplies = comment.replies?.replyCount ?? 0
comment.replyContinuation = comment.replies?.continuation ?? ''
comment.isHearted = comment.creatorHeart !== undefined
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added support for hearted comments

comment.replies = []
comment.time = toLocalePublicationString({
publishText: comment.publishedText
})

return comment
})
}
2 changes: 1 addition & 1 deletion src/renderer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ library.add(

Vue.component('FontAwesomeIcon', FontAwesomeIcon)

/* eslint-disable-next-line */
/* eslint-disable-next-line no-new */
new Vue({
el: '#app',
router,
Expand Down
Loading