From 1a9cdacd752bc7766134b5cd5c79bc4af1ce50e6 Mon Sep 17 00:00:00 2001 From: Preston Date: Mon, 14 Dec 2020 14:15:29 -0500 Subject: [PATCH] Update search filters to work with updated search module --- .../ft-list-channel/ft-list-channel.js | 11 +- src/renderer/store/modules/ytdl.js | 117 ++++++++++++------ 2 files changed, 86 insertions(+), 42 deletions(-) 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 286ab0d3..93f0b117 100644 --- a/src/renderer/components/ft-list-channel/ft-list-channel.js +++ b/src/renderer/components/ft-list-channel/ft-list-channel.js @@ -51,13 +51,18 @@ export default Vue.extend({ this.channelName = this.data.name this.id = this.data.channelID - if (this.hideChannelSubscriptions) { + if (this.hideChannelSubscriptions || this.data.subscribers === null) { this.subscriberCount = null } else { this.subscriberCount = this.data.subscribers.replace(/ subscriber(s)?/, '') } - this.videoCount = this.data.videos.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') - this.description = this.data.description_short + if (this.data.videos === null) { + this.videoCount = 0 + } else { + this.videoCount = this.data.videos.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') + } + + this.description = this.data.descriptionShort }, parseInvidiousData: function () { diff --git a/src/renderer/store/modules/ytdl.js b/src/renderer/store/modules/ytdl.js index d0bdaf18..8682ca8e 100644 --- a/src/renderer/store/modules/ytdl.js +++ b/src/renderer/store/modules/ytdl.js @@ -39,7 +39,9 @@ const actions = { payload.options.nextpageRef = filter } - ytsr(payload.query, payload.options).then((result) => { + const query = filter || payload.query + + ytsr(query, payload.options).then((result) => { console.log(result) console.log('done') resolve(result) @@ -51,6 +53,7 @@ const actions = { }) }).catch((err) => { console.log(err) + commit('toggleIsYtSearchRunning') reject(err) }) } else { @@ -68,52 +71,88 @@ const actions = { }) }, - ytSearchGetFilters ({ rootState }, payload) { - return new Promise((resolve, reject) => { - let filter = payload.query - let searchSettings = payload.searchSettings + async ytSearchGetFilters ({ rootState }, payload) { + let filter = await ytsr.getFilters(payload.query) + let filterUrl = null + let searchSettings = payload.searchSettings - if (typeof (searchSettings) === 'undefined') { - searchSettings = rootState.utils.searchSettings + if (typeof (searchSettings) === 'undefined') { + searchSettings = rootState.utils.searchSettings + } + + console.log(searchSettings) + console.log(filter) + + if (searchSettings.sortBy !== 'relevance') { + let filterValue + switch (searchSettings.sortBy) { + case 'rating': + filterValue = 'Rating' + break + case 'upload_date': + filterValue = 'Upload date' + break + case 'view_count': + filterValue = 'View count' + break + } + filterUrl = filter.get('Sort by').get(filterValue).url + filter = await ytsr.getFilters(filterUrl) + } + + console.log(`Current ref: ${filterUrl}`) + + if (searchSettings.duration !== '') { + let filterValue = null + if (searchSettings.duration === 'short') { + filterValue = 'Short (< 4 minutes)' + } else if (searchSettings.duration === 'long') { + filterValue = 'Long (> 20 minutes)' } - console.log(searchSettings) + filterUrl = filter.get('Duration').get(filterValue).url + filter = await ytsr.getFilters(filterUrl) + } - // This is extremely ugly, though this is the recommended way to accomplish this - // in the GitHub documentation - console.log(`Current ref: ${filter}`) - ytsr.getFilters(filter).then((filters) => { - if (searchSettings.type !== 'all') { - filter = filters.get('Type').find(o => o.name.toLowerCase().includes(rootState.utils.searchSettings.type)).ref - } + console.log(`Current ref: ${filterUrl}`) - console.log(`Current ref: ${filter}`) - ytsr.getFilters(filter).then((filters) => { - if (searchSettings.time !== '') { - filter = filters.get('Upload date').find(o => o.name.toLowerCase().includes(rootState.utils.searchSettings.time)).ref - } + if (searchSettings.time !== '') { + let filterValue = null - console.log(`Current ref: ${filter}`) - ytsr.getFilters(filter).then((filters) => { - if (searchSettings.duration !== '') { - filter = filters.get('Duration').find(o => o.name.toLowerCase().includes(rootState.utils.searchSettings.duration)).ref - } + switch (searchSettings.time) { + case 'hour': + filterValue = 'Last Hour' + break + case 'today': + filterValue = 'Today' + break + case 'week': + filterValue = 'This week' + break + case 'month': + filterValue = 'This month' + break + case 'year': + filterValue = 'This year' + break + } - console.log(`Current ref: ${filter}`) - ytsr.getFilters(filter).then((filters) => { - if (searchSettings.sortBy !== 'relevance') { - const sortBy = rootState.utils.searchSettings.sortBy.replace('_', ' ') - filter = filters.get('Sort by').find(o => o.name.toLowerCase().includes(sortBy)).ref - } + filterUrl = filter.get('Upload date').get(filterValue).url + filter = await ytsr.getFilters(filterUrl) + } - console.log(`Final ref: ${filter}`) - resolve(filter) - }) - }) - }) - }).catch((err) => { - reject(err) - }) + console.log(`Current ref: ${filterUrl}`) + + if (searchSettings.type !== 'all') { + const filterValue = searchSettings.type.charAt(0).toUpperCase() + searchSettings.type.slice(1) + filterUrl = filter.get('Type').get(filterValue).url + filter = await ytsr.getFilters(filterUrl) + } + + console.log(`Current ref: ${filterUrl}`) + + return new Promise((resolve, reject) => { + resolve(filterUrl) }) },