Update search filters to work with updated search module
This commit is contained in:
parent
cb8cf1ef43
commit
1a9cdacd75
|
@ -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 () {
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue