mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-04 02:05:06 +02:00
Add remaining personalized shelf queries for podcasts
This commit is contained in:
parent
09eefae808
commit
91b6c4412d
6 changed files with 219 additions and 73 deletions
|
@ -59,10 +59,14 @@ module.exports = {
|
|||
count
|
||||
}
|
||||
} else {
|
||||
// TODO: Get episodes in progress
|
||||
const { libraryItems, count } = await libraryItemsPodcastFilters.getFilteredPodcastEpisodes(library.id, userId, 'progress', 'in-progress', 'progress', true, limit, 0)
|
||||
return {
|
||||
count: 0,
|
||||
items: []
|
||||
count,
|
||||
items: libraryItems.map(li => {
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified()
|
||||
oldLibraryItem.recentEpisode = li.recentEpisode
|
||||
return oldLibraryItem
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -160,10 +164,14 @@ module.exports = {
|
|||
count
|
||||
}
|
||||
} else {
|
||||
// TODO: Get podcast episodes finished
|
||||
const { libraryItems, count } = await libraryItemsPodcastFilters.getFilteredPodcastEpisodes(library.id, userId, 'progress', 'finished', 'progress', true, limit, 0)
|
||||
return {
|
||||
items: [],
|
||||
count: 0
|
||||
count,
|
||||
items: libraryItems.map(li => {
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified()
|
||||
oldLibraryItem.recentEpisode = li.recentEpisode
|
||||
return oldLibraryItem
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -299,5 +307,26 @@ module.exports = {
|
|||
}),
|
||||
count
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Get podcast episodes most recently added
|
||||
* @param {oldLibrary} library
|
||||
* @param {string} userId
|
||||
* @param {number} limit
|
||||
* @returns {object} {libraryItems:oldLibraryItem[], count:number}
|
||||
*/
|
||||
async getNewestPodcastEpisodes(library, userId, limit) {
|
||||
if (library.mediaType !== 'podcast') return { libraryItems: [], count: 0 }
|
||||
|
||||
const { libraryItems, count } = await libraryItemsPodcastFilters.getFilteredPodcastEpisodes(library.id, userId, null, null, 'createdAt', true, limit, 0)
|
||||
return {
|
||||
count,
|
||||
libraryItems: libraryItems.map(li => {
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified()
|
||||
oldLibraryItem.recentEpisode = li.recentEpisode
|
||||
return oldLibraryItem
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
|
@ -230,7 +230,7 @@ module.exports = {
|
|||
}
|
||||
} else if (sortBy === 'sequence') {
|
||||
const nullDir = sortDesc ? 'DESC NULLS FIRST' : 'ASC NULLS LAST'
|
||||
return [[Sequelize.literal(`CAST(\`series.bookSeries.sequence\` AS INTEGER) COLLATE NOCASE ${nullDir}`)]]
|
||||
return [[Sequelize.literal(`CAST(\`series.bookSeries.sequence\` AS INTEGER) ${nullDir}`)]]
|
||||
} else if (sortBy === 'progress') {
|
||||
return [[Sequelize.literal('mediaProgresses.updatedAt'), dir]]
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ module.exports = {
|
|||
}
|
||||
],
|
||||
order: [
|
||||
Sequelize.literal('CAST(`books.bookSeries.sequence` AS INTEGER) COLLATE NOCASE ASC NULLS LAST')
|
||||
Sequelize.literal('CAST(`books.bookSeries.sequence` AS INTEGER) ASC NULLS LAST')
|
||||
]
|
||||
})
|
||||
const bookSeriesToInclude = []
|
||||
|
@ -426,7 +426,7 @@ module.exports = {
|
|||
})
|
||||
if (sortBy !== 'sequence') {
|
||||
// Secondary sort by sequence
|
||||
sortOrder.push([Sequelize.literal('CAST(`series.bookSeries.sequence` AS INTEGER) COLLATE NOCASE ASC NULLS LAST')])
|
||||
sortOrder.push([Sequelize.literal('CAST(`series.bookSeries.sequence` AS INTEGER) ASC NULLS LAST')])
|
||||
}
|
||||
} else if (filterGroup === 'issues') {
|
||||
libraryItemWhere[Sequelize.Op.or] = [
|
||||
|
|
|
@ -148,6 +148,96 @@ module.exports = {
|
|||
return libraryItem
|
||||
})
|
||||
|
||||
return {
|
||||
libraryItems,
|
||||
count
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Get podcast episodes filtered and sorted
|
||||
* @param {string} libraryId
|
||||
* @param {string} userId
|
||||
* @param {[string]} filterGroup
|
||||
* @param {[string]} filterValue
|
||||
* @param {string} sortBy
|
||||
* @param {string} sortDesc
|
||||
* @param {number} limit
|
||||
* @param {number} offset
|
||||
* @returns {object} {libraryItems:LibraryItem[], count:number}
|
||||
*/
|
||||
async getFilteredPodcastEpisodes(libraryId, userId, filterGroup, filterValue, sortBy, sortDesc, limit, offset) {
|
||||
if (sortBy === 'progress' && filterGroup !== 'progress') {
|
||||
Logger.warn('Cannot sort podcast episodes by progress without filtering by progress')
|
||||
sortBy = 'createdAt'
|
||||
}
|
||||
|
||||
const podcastEpisodeIncludes = []
|
||||
let podcastEpisodeWhere = {}
|
||||
if (filterGroup === 'progress') {
|
||||
podcastEpisodeIncludes.push({
|
||||
model: Database.models.mediaProgress,
|
||||
where: {
|
||||
userId
|
||||
},
|
||||
attributes: ['id', 'isFinished', 'currentTime', 'updatedAt']
|
||||
})
|
||||
|
||||
if (filterValue === 'in-progress') {
|
||||
podcastEpisodeWhere = [
|
||||
{
|
||||
'$mediaProgresses.isFinished$': false
|
||||
},
|
||||
{
|
||||
'$mediaProgresses.currentTime$': {
|
||||
[Sequelize.Op.gt]: 0
|
||||
}
|
||||
}
|
||||
]
|
||||
} else if (filterValue === 'finished') {
|
||||
podcastEpisodeWhere['$mediaProgresses.isFinished$'] = true
|
||||
}
|
||||
}
|
||||
|
||||
const podcastEpisodeOrder = []
|
||||
if (sortBy === 'createdAt') {
|
||||
podcastEpisodeOrder.push(['createdAt', sortDesc ? 'DESC' : 'ASC'])
|
||||
} else if (sortBy === 'progress') {
|
||||
podcastEpisodeOrder.push([Sequelize.literal('mediaProgresses.updatedAt'), sortDesc ? 'DESC' : 'ASC'])
|
||||
}
|
||||
|
||||
const { rows: podcastEpisodes, count } = await Database.models.podcastEpisode.findAndCountAll({
|
||||
where: podcastEpisodeWhere,
|
||||
include: [
|
||||
{
|
||||
model: Database.models.podcast,
|
||||
include: [
|
||||
{
|
||||
model: Database.models.libraryItem,
|
||||
where: {
|
||||
libraryId
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
...podcastEpisodeIncludes
|
||||
],
|
||||
distinct: true,
|
||||
subQuery: false,
|
||||
order: podcastEpisodeOrder,
|
||||
limit,
|
||||
offset
|
||||
})
|
||||
|
||||
const libraryItems = podcastEpisodes.map((ep) => {
|
||||
const libraryItem = ep.podcast.libraryItem.toJSON()
|
||||
const podcast = ep.podcast.toJSON()
|
||||
delete podcast.libraryItem
|
||||
libraryItem.media = podcast
|
||||
libraryItem.recentEpisode = ep.getOldPodcastEpisode(libraryItem.id)
|
||||
return libraryItem
|
||||
})
|
||||
|
||||
return {
|
||||
libraryItems,
|
||||
count
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue