mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-02-03 08:49:40 +00:00
Add:Server setting to ignore "The" infront of titles and series when sorting #361
This commit is contained in:
parent
e0a6631396
commit
f15be4c96e
6 changed files with 93 additions and 20 deletions
|
|
@ -144,10 +144,19 @@ class LibraryController {
|
|||
}
|
||||
|
||||
if (payload.sortBy) {
|
||||
var sortKey = payload.sortBy
|
||||
|
||||
// Handle server setting sortingIgnorePrefix
|
||||
if ((sortKey === 'book.series' || sortKey === 'book.title') && this.db.serverSettings.sortingIgnorePrefix) {
|
||||
// Book.js has seriesIgnorePrefix and titleIgnorePrefix getters
|
||||
sortKey += 'IgnorePrefix'
|
||||
}
|
||||
|
||||
var direction = payload.sortDesc ? 'desc' : 'asc'
|
||||
audiobooks = naturalSort(audiobooks)[direction]((ab) => {
|
||||
|
||||
// Supports dot notation strings i.e. "book.title"
|
||||
return payload.sortBy.split('.').reduce((a, b) => a[b], ab)
|
||||
return sortKey.split('.').reduce((a, b) => a[b], ab)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -202,7 +211,14 @@ class LibraryController {
|
|||
}
|
||||
|
||||
var series = libraryHelpers.getSeriesFromBooks(audiobooks, payload.minified)
|
||||
series = sort(series).asc(s => s.name)
|
||||
|
||||
var sortingIgnorePrefix = this.db.serverSettings.sortingIgnorePrefix
|
||||
series = sort(series).asc(s => {
|
||||
if (sortingIgnorePrefix && s.name.toLowerCase().startsWith('the')) {
|
||||
return s.name.substr(4)
|
||||
}
|
||||
return s.name
|
||||
})
|
||||
payload.total = series.length
|
||||
|
||||
if (payload.limit) {
|
||||
|
|
|
|||
|
|
@ -49,6 +49,20 @@ class Book {
|
|||
get _asin() { return this.asin || '' }
|
||||
get genresCommaSeparated() { return this._genres.join(', ') }
|
||||
|
||||
get titleIgnorePrefix() {
|
||||
if (this._title.toLowerCase().startsWith('the ')) {
|
||||
return this._title.substr(4) + ', The'
|
||||
}
|
||||
return this._title
|
||||
}
|
||||
|
||||
get seriesIgnorePrefix() {
|
||||
if (this._series.toLowerCase().startsWith('the ')) {
|
||||
return this._series.substr(4) + ', The'
|
||||
}
|
||||
return this._series
|
||||
}
|
||||
|
||||
get shouldSearchForCover() {
|
||||
if (this.cover) return false
|
||||
if (this.authorFL !== this.lastCoverSearchAuthor || this.title !== this.lastCoverSearchTitle || !this.lastCoverSearch) return true
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ class ServerSettings {
|
|||
this.coverAspectRatio = BookCoverAspectRatio.SQUARE
|
||||
this.bookshelfView = BookshelfView.STANDARD
|
||||
|
||||
this.sortingIgnorePrefix = false
|
||||
|
||||
this.logLevel = Logger.logLevel
|
||||
this.version = null
|
||||
|
||||
|
|
@ -70,6 +72,8 @@ class ServerSettings {
|
|||
this.coverAspectRatio = !isNaN(settings.coverAspectRatio) ? settings.coverAspectRatio : BookCoverAspectRatio.SQUARE
|
||||
this.bookshelfView = settings.bookshelfView || BookshelfView.STANDARD
|
||||
|
||||
this.sortingIgnorePrefix = !!settings.sortingIgnorePrefix
|
||||
|
||||
this.logLevel = settings.logLevel || Logger.logLevel
|
||||
this.version = settings.version || null
|
||||
|
||||
|
|
@ -99,6 +103,7 @@ class ServerSettings {
|
|||
loggerScannerLogsToKeep: this.loggerScannerLogsToKeep,
|
||||
coverAspectRatio: this.coverAspectRatio,
|
||||
bookshelfView: this.bookshelfView,
|
||||
sortingIgnorePrefix: this.sortingIgnorePrefix,
|
||||
logLevel: this.logLevel,
|
||||
version: this.version
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,4 @@
|
|||
const ffprobe = require('node-ffprobe')
|
||||
|
||||
if (process.env.FFPROBE_PATH) {
|
||||
ffprobe.FFPROBE_PATH = process.env.FFPROBE_PATH
|
||||
}
|
||||
|
||||
const AudioProbeData = require('../scanner/AudioProbeData')
|
||||
|
||||
const Logger = require('../Logger')
|
||||
|
|
@ -281,6 +276,10 @@ function parseProbeData(data, verbose = false) {
|
|||
|
||||
// Updated probe returns AudioProbeData object
|
||||
function probe(filepath, verbose = false) {
|
||||
if (process.env.FFPROBE_PATH) {
|
||||
ffprobe.FFPROBE_PATH = process.env.FFPROBE_PATH
|
||||
}
|
||||
|
||||
return ffprobe(filepath)
|
||||
.then(raw => {
|
||||
var rawProbeData = parseProbeData(raw, verbose)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue