Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of DeArrow titles #3825

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 17 additions & 13 deletions src/renderer/components/ft-list-video/ft-list-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,17 @@ export default defineComponent({
},

displayTitle: function () {
let title
if (this.useDeArrowTitles && this.deArrowCache?.title) {
title = this.deArrowCache.title
} else {
title = this.title
}

if (this.showDistractionFreeTitles) {
return toDistractionFreeTitle(this.title)
return toDistractionFreeTitle(title)
} else {
return this.title
return title
}
},

Expand Down Expand Up @@ -327,7 +334,7 @@ export default defineComponent({
},

deArrowCache: function () {
return this.$store.getters.getDeArrowCache(this.id)
return this.$store.getters.getDeArrowCache[this.id]
}
},
watch: {
Expand All @@ -338,15 +345,13 @@ export default defineComponent({
created: function () {
this.parseVideoData()
this.checkIfWatched()

if (this.useDeArrowTitles && !this.deArrowCache) {
this.fetchDeArrowData()
}
},
methods: {
getDeArrowDataEntry: async function() {
// Read from local cache or remote
// Write to cache if read from remote
if (!this.useDeArrowTitles) { return null }

if (this.deArrowCache) { return this.deArrowCache }

fetchDeArrowData: async function() {
const videoId = this.id
const data = await deArrowData(this.id)
const cacheData = { videoId, title: null }
Expand All @@ -356,7 +361,6 @@ export default defineComponent({

// Save data to cache whether data available or not to prevent duplicate requests
this.$store.commit('addVideoToDeArrowCache', cacheData)
return cacheData
},

handleExternalPlayer: function () {
Expand Down Expand Up @@ -429,9 +433,9 @@ export default defineComponent({
}
},

parseVideoData: async function () {
parseVideoData: function () {
this.id = this.data.videoId
this.title = (await this.getDeArrowDataEntry())?.title ?? this.data.title
this.title = this.data.title
// this.thumbnail = this.data.videoThumbnails[4].url

this.channelName = this.data.author ?? null
Expand Down
9 changes: 6 additions & 3 deletions src/renderer/store/modules/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs/promises'
import path from 'path'
import i18n from '../../i18n/index'
import { set as vueSet } from 'vue'

import { IpcChannels } from '../../../constants'
import { pathExists } from '../../helpers/filesystem'
Expand Down Expand Up @@ -58,8 +59,8 @@ const getters = {
return state.sessionSearchHistory
},

getDeArrowCache: (state) => (videoId) => {
return state.deArrowCache[videoId]
getDeArrowCache: (state) => {
return state.deArrowCache
},

getPopularCache () {
Expand Down Expand Up @@ -639,7 +640,9 @@ const mutations = {
const sameVideo = state.deArrowCache[payload.videoId]

if (!sameVideo) {
state.deArrowCache[payload.videoId] = payload
// setting properties directly doesn't trigger watchers in Vue 2,
// so we need to use Vue's set function
vueSet(state.deArrowCache, payload.videoId, payload)
}
},

Expand Down