Skip to content

Commit

Permalink
Move Invidious API calls into Invidious file (#6313)
Browse files Browse the repository at this point in the history
* Move Invidious API calls into Invidious file

* Fix typo in search function

Co-authored-by: ChunkyProgrammer <[email protected]>

---------

Co-authored-by: ChunkyProgrammer <[email protected]>
  • Loading branch information
absidue and ChunkyProgrammer authored Dec 10, 2024
1 parent 2d33022 commit ad7c19d
Show file tree
Hide file tree
Showing 12 changed files with 329 additions and 262 deletions.
16 changes: 3 additions & 13 deletions src/renderer/components/subscriptions-live/subscriptions-live.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import SubscriptionsTabUI from '../subscriptions-tab-ui/subscriptions-tab-ui.vue

import {
getChannelPlaylistId,
setPublishedTimestampsInvidious,
copyToClipboard,
getRelativeTimeFromDate,
showToast
} from '../../helpers/utils'
import { invidiousAPICall, invidiousFetch } from '../../helpers/api/invidious'
import { getInvidiousChannelLive, invidiousFetch } from '../../helpers/api/invidious'
import { getLocalChannelLiveStreams } from '../../helpers/api/local'
import { parseYouTubeRSSFeed, updateVideoListAfterProcessing } from '../../helpers/subscriptions'

Expand Down Expand Up @@ -338,17 +337,8 @@ export default defineComponent({

getChannelLiveInvidious: function (channel, failedAttempts = 0) {
return new Promise((resolve, reject) => {
const subscriptionsPayload = {
resource: 'channels',
id: channel.id,
subResource: 'streams',
params: {}
}

invidiousAPICall(subscriptionsPayload).then((result) => {
const videos = result.videos.filter(e => e.type === 'video')

setPublishedTimestampsInvidious(videos)
getInvidiousChannelLive(channel.id).then((result) => {
const videos = result.videos

let name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { mapActions, mapMutations } from 'vuex'
import SubscriptionsTabUI from '../subscriptions-tab-ui/subscriptions-tab-ui.vue'

import {
setPublishedTimestampsInvidious,
copyToClipboard,
getRelativeTimeFromDate,
showToast,
getChannelPlaylistId
} from '../../helpers/utils'
import { invidiousAPICall, invidiousFetch } from '../../helpers/api/invidious'
import { getInvidiousChannelVideos, invidiousFetch } from '../../helpers/api/invidious'
import { getLocalChannelVideos } from '../../helpers/api/local'
import { parseYouTubeRSSFeed, updateVideoListAfterProcessing } from '../../helpers/subscriptions'

Expand Down Expand Up @@ -342,16 +341,7 @@ export default defineComponent({

getChannelVideosInvidiousScraper: function (channel, failedAttempts = 0) {
return new Promise((resolve, reject) => {
const subscriptionsPayload = {
resource: 'channels',
id: channel.id,
subResource: 'videos',
params: {}
}

invidiousAPICall(subscriptionsPayload).then((result) => {
setPublishedTimestampsInvidious(result.videos)

getInvidiousChannelVideos(channel.id).then((result) => {
let name

if (result.videos.length > 0) {
Expand Down
12 changes: 2 additions & 10 deletions src/renderer/components/top-nav/top-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IpcChannels, KeyboardShortcuts, MOBILE_WIDTH_THRESHOLD } from '../../..
import { localizeAndAddKeyboardShortcutToActionTitle, openInternalPath } from '../../helpers/utils'
import { translateWindowTitle } from '../../helpers/strings'
import { clearLocalSearchSuggestionsSession, getLocalSearchSuggestions } from '../../helpers/api/local'
import { invidiousAPICall } from '../../helpers/api/invidious'
import { getInvidiousSearchSuggestions } from '../../helpers/api/invidious'

const NAV_HISTORY_DISPLAY_LIMIT = 15
const HALF_OF_NAV_HISTORY_DISPLAY_LIMIT = Math.floor(NAV_HISTORY_DISPLAY_LIMIT / 2)
Expand Down Expand Up @@ -326,15 +326,7 @@ export default defineComponent({
return
}

const searchPayload = {
resource: 'search/suggestions',
id: '',
params: {
q: query
}
}

invidiousAPICall(searchPayload).then((results) => {
getInvidiousSearchSuggestions(query).then((results) => {
this.searchSuggestionsDataList = results.suggestions
}).catch((err) => {
console.error(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mapMutations } from 'vuex'
import FtLoader from '../ft-loader/ft-loader.vue'
import FtCard from '../ft-card/ft-card.vue'
import FtListVideoNumbered from '../ft-list-video-numbered/ft-list-video-numbered.vue'
import { copyToClipboard, setPublishedTimestampsInvidious, showToast } from '../../helpers/utils'
import { copyToClipboard, showToast } from '../../helpers/utils'
import {
getLocalPlaylist,
parseLocalPlaylistVideo,
Expand Down Expand Up @@ -471,7 +471,6 @@ export default defineComponent({
this.channelName = result.author
this.channelId = result.authorId

setPublishedTimestampsInvidious(result.videos)
this.playlistItems = this.playlistItems.concat(result.videos)

this.isLoading = false
Expand Down
Loading

0 comments on commit ad7c19d

Please sign in to comment.