mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Merge branch 'master' of https://github.com/advplyr/audiobookshelf
This commit is contained in:
		
						commit
						36626d43a1
					
				@ -288,7 +288,7 @@ class LibraryController {
 | 
				
			|||||||
          } else if (payload.sortBy === 'addedAt') {
 | 
					          } else if (payload.sortBy === 'addedAt') {
 | 
				
			||||||
            return se.addedAt
 | 
					            return se.addedAt
 | 
				
			||||||
          } else { // sort by name
 | 
					          } else { // sort by name
 | 
				
			||||||
            return this.db.serverSettings.sortingIgnorePrefix ? se.nameIgnorePrefix : se.name
 | 
					            return this.db.serverSettings.sortingIgnorePrefix ? se.nameIgnorePrefixSort : se.name
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
const Logger = require('../../Logger')
 | 
					const Logger = require('../../Logger')
 | 
				
			||||||
const { areEquivalent, copyValue, cleanStringForSearch, getTitleIgnorePrefix } = require('../../utils/index')
 | 
					const { areEquivalent, copyValue, cleanStringForSearch, getTitleIgnorePrefix, getTitlePrefixAtEnd } = require('../../utils/index')
 | 
				
			||||||
const parseNameString = require('../../utils/parsers/parseNameString')
 | 
					const parseNameString = require('../../utils/parsers/parseNameString')
 | 
				
			||||||
class BookMetadata {
 | 
					class BookMetadata {
 | 
				
			||||||
  constructor(metadata) {
 | 
					  constructor(metadata) {
 | 
				
			||||||
@ -62,7 +62,7 @@ class BookMetadata {
 | 
				
			|||||||
  toJSONMinified() {
 | 
					  toJSONMinified() {
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
      title: this.title,
 | 
					      title: this.title,
 | 
				
			||||||
      titleIgnorePrefix: this.titleIgnorePrefix,
 | 
					      titleIgnorePrefix: this.titlePrefixAtEnd,
 | 
				
			||||||
      subtitle: this.subtitle,
 | 
					      subtitle: this.subtitle,
 | 
				
			||||||
      authorName: this.authorName,
 | 
					      authorName: this.authorName,
 | 
				
			||||||
      authorNameLF: this.authorNameLF,
 | 
					      authorNameLF: this.authorNameLF,
 | 
				
			||||||
@ -83,7 +83,7 @@ class BookMetadata {
 | 
				
			|||||||
  toJSONExpanded() {
 | 
					  toJSONExpanded() {
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
      title: this.title,
 | 
					      title: this.title,
 | 
				
			||||||
      titleIgnorePrefix: this.titleIgnorePrefix,
 | 
					      titleIgnorePrefix: this.titlePrefixAtEnd,
 | 
				
			||||||
      subtitle: this.subtitle,
 | 
					      subtitle: this.subtitle,
 | 
				
			||||||
      authors: this.authors.map(a => ({ ...a })), // Author JSONMinimal with name and id
 | 
					      authors: this.authors.map(a => ({ ...a })), // Author JSONMinimal with name and id
 | 
				
			||||||
      narrators: [...this.narrators],
 | 
					      narrators: [...this.narrators],
 | 
				
			||||||
@ -111,6 +111,9 @@ class BookMetadata {
 | 
				
			|||||||
  get titleIgnorePrefix() {
 | 
					  get titleIgnorePrefix() {
 | 
				
			||||||
    return getTitleIgnorePrefix(this.title)
 | 
					    return getTitleIgnorePrefix(this.title)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  get titlePrefixAtEnd() {
 | 
				
			||||||
 | 
					    return getTitlePrefixAtEnd(this.title)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  get authorName() {
 | 
					  get authorName() {
 | 
				
			||||||
    if (!this.authors.length) return ''
 | 
					    if (!this.authors.length) return ''
 | 
				
			||||||
    return this.authors.map(au => au.name).join(', ')
 | 
					    return this.authors.map(au => au.name).join(', ')
 | 
				
			||||||
@ -133,6 +136,13 @@ class BookMetadata {
 | 
				
			|||||||
      return `${getTitleIgnorePrefix(se.name)} #${se.sequence}`
 | 
					      return `${getTitleIgnorePrefix(se.name)} #${se.sequence}`
 | 
				
			||||||
    }).join(', ')
 | 
					    }).join(', ')
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  get seriesNamePrefixAtEnd() {
 | 
				
			||||||
 | 
					    if (!this.series.length) return ''
 | 
				
			||||||
 | 
					    return this.series.map(se => {
 | 
				
			||||||
 | 
					      if (!se.sequence) return getTitlePrefixAtEnd(se.name)
 | 
				
			||||||
 | 
					      return `${getTitlePrefixAtEnd(se.name)} #${se.sequence}`
 | 
				
			||||||
 | 
					    }).join(', ')
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  get firstSeriesName() {
 | 
					  get firstSeriesName() {
 | 
				
			||||||
    if (!this.series.length) return ''
 | 
					    if (!this.series.length) return ''
 | 
				
			||||||
    return this.series[0].name
 | 
					    return this.series[0].name
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
const Logger = require('../../Logger')
 | 
					const Logger = require('../../Logger')
 | 
				
			||||||
const { areEquivalent, copyValue, cleanStringForSearch } = require('../../utils/index')
 | 
					const { areEquivalent, copyValue, cleanStringForSearch, getTitleIgnorePrefix, getTitlePrefixAtEnd } = require('../../utils/index')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PodcastMetadata {
 | 
					class PodcastMetadata {
 | 
				
			||||||
  constructor(metadata) {
 | 
					  constructor(metadata) {
 | 
				
			||||||
@ -56,7 +56,7 @@ class PodcastMetadata {
 | 
				
			|||||||
  toJSONMinified() {
 | 
					  toJSONMinified() {
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
      title: this.title,
 | 
					      title: this.title,
 | 
				
			||||||
      titleIgnorePrefix: this.titleIgnorePrefix,
 | 
					      titleIgnorePrefix: this.titlePrefixAtEnd,
 | 
				
			||||||
      author: this.author,
 | 
					      author: this.author,
 | 
				
			||||||
      description: this.description,
 | 
					      description: this.description,
 | 
				
			||||||
      releaseDate: this.releaseDate,
 | 
					      releaseDate: this.releaseDate,
 | 
				
			||||||
@ -80,15 +80,11 @@ class PodcastMetadata {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  get titleIgnorePrefix() {
 | 
					  get titleIgnorePrefix() {
 | 
				
			||||||
    if (!this.title) return ''
 | 
					    return getTitleIgnorePrefix(this.title)
 | 
				
			||||||
    var prefixesToIgnore = global.ServerSettings.sortingPrefixes || []
 | 
					  }
 | 
				
			||||||
    for (const prefix of prefixesToIgnore) {
 | 
					
 | 
				
			||||||
      // e.g. for prefix "the". If title is "The Book Title" return "Book Title, The"
 | 
					  get titlePrefixAtEnd() {
 | 
				
			||||||
      if (this.title.toLowerCase().startsWith(`${prefix} `)) {
 | 
					    return getTitlePrefixAtEnd(this.title)
 | 
				
			||||||
        return this.title.substr(prefix.length + 1) + `, ${prefix.substr(0, 1).toUpperCase() + prefix.substr(1)}`
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return this.title
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  searchQuery(query) { // Returns key if match is found
 | 
					  searchQuery(query) { // Returns key if match is found
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
const Logger = require('../../Logger')
 | 
					const Logger = require('../../Logger')
 | 
				
			||||||
const { areEquivalent, copyValue } = require('../../utils/index')
 | 
					const { areEquivalent, copyValue, getTitleIgnorePrefix, getTitlePrefixAtEnd } = require('../../utils/index')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class VideoMetadata {
 | 
					class VideoMetadata {
 | 
				
			||||||
  constructor(metadata) {
 | 
					  constructor(metadata) {
 | 
				
			||||||
@ -32,7 +32,7 @@ class VideoMetadata {
 | 
				
			|||||||
  toJSONMinified() {
 | 
					  toJSONMinified() {
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
      title: this.title,
 | 
					      title: this.title,
 | 
				
			||||||
      titleIgnorePrefix: this.titleIgnorePrefix,
 | 
					      titleIgnorePrefix: this.titlePrefixAtEnd,
 | 
				
			||||||
      description: this.description,
 | 
					      description: this.description,
 | 
				
			||||||
      explicit: this.explicit,
 | 
					      explicit: this.explicit,
 | 
				
			||||||
      language: this.language
 | 
					      language: this.language
 | 
				
			||||||
@ -48,15 +48,11 @@ class VideoMetadata {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  get titleIgnorePrefix() {
 | 
					  get titleIgnorePrefix() {
 | 
				
			||||||
    if (!this.title) return ''
 | 
					    return getTitleIgnorePrefix(this.title)
 | 
				
			||||||
    var prefixesToIgnore = global.ServerSettings.sortingPrefixes || []
 | 
					  }
 | 
				
			||||||
    for (const prefix of prefixesToIgnore) {
 | 
					
 | 
				
			||||||
      // e.g. for prefix "the". If title is "The Book Title" return "Book Title, The"
 | 
					  get titlePrefixAtEnd() {
 | 
				
			||||||
      if (this.title.toLowerCase().startsWith(`${prefix} `)) {
 | 
					    return getTitlePrefixAtEnd(this.title)
 | 
				
			||||||
        return this.title.substr(prefix.length + 1) + `, ${prefix.substr(0, 1).toUpperCase() + prefix.substr(1)}`
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return this.title
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  searchQuery(query) { // Returns key if match is found
 | 
					  searchQuery(query) { // Returns key if match is found
 | 
				
			||||||
 | 
				
			|||||||
@ -140,14 +140,24 @@ module.exports.cleanStringForSearch = (str) => {
 | 
				
			|||||||
  return str.toLowerCase().replace(/[\'\.\`\",]/g, '').trim()
 | 
					  return str.toLowerCase().replace(/[\'\.\`\",]/g, '').trim()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports.getTitleIgnorePrefix = (title) => {
 | 
					const getTitleParts = (title) => {
 | 
				
			||||||
  if (!title) return ''
 | 
					  if (!title) return ['', null]
 | 
				
			||||||
  var prefixesToIgnore = global.ServerSettings.sortingPrefixes || []
 | 
					  var prefixesToIgnore = global.ServerSettings.sortingPrefixes || []
 | 
				
			||||||
 | 
					  prefixes = []
 | 
				
			||||||
  for (const prefix of prefixesToIgnore) {
 | 
					  for (const prefix of prefixesToIgnore) {
 | 
				
			||||||
    // e.g. for prefix "the". If title is "The Book" return "Book, The"
 | 
					    // e.g. for prefix "the". If title is "The Book" return "Book, The"
 | 
				
			||||||
    if (title.toLowerCase().startsWith(`${prefix} `)) {
 | 
					    if (title.toLowerCase().startsWith(`${prefix} `)) {
 | 
				
			||||||
      return title.substr(prefix.length + 1) + `, ${prefix.substr(0, 1).toUpperCase() + prefix.substr(1)}`
 | 
					      return [title.substr(prefix.length + 1), `${prefix.substr(0, 1).toUpperCase() + prefix.substr(1)}`]
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  return title
 | 
					  return [title, null]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module.exports.getTitleIgnorePrefix = (title) => {
 | 
				
			||||||
 | 
					  return getTitleParts(title)[0]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module.exports.getTitlePrefixAtEnd = (title) => {
 | 
				
			||||||
 | 
					  let [sort, prefix] = getTitleParts(title)
 | 
				
			||||||
 | 
					  return prefix ? `${sort}, ${prefix}` : title
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
const { sort, createNewSortInstance } = require('../libs/fastSort')
 | 
					const { sort, createNewSortInstance } = require('../libs/fastSort')
 | 
				
			||||||
const { getTitleIgnorePrefix, isNullOrNaN } = require('../utils/index')
 | 
					const { getTitlePrefixAtEnd, isNullOrNaN, getTitleIgnorePrefix } = require('../utils/index')
 | 
				
			||||||
const naturalSort = createNewSortInstance({
 | 
					const naturalSort = createNewSortInstance({
 | 
				
			||||||
  comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare
 | 
					  comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
@ -183,7 +183,8 @@ module.exports = {
 | 
				
			|||||||
          _series[bookSeriesObj.id] = {
 | 
					          _series[bookSeriesObj.id] = {
 | 
				
			||||||
            id: bookSeriesObj.id,
 | 
					            id: bookSeriesObj.id,
 | 
				
			||||||
            name: bookSeriesObj.name,
 | 
					            name: bookSeriesObj.name,
 | 
				
			||||||
            nameIgnorePrefix: getTitleIgnorePrefix(bookSeriesObj.name),
 | 
					            nameIgnorePrefix: getTitlePrefixAtEnd(bookSeriesObj.name),
 | 
				
			||||||
 | 
					            nameIgnorePrefixSort: getTitleIgnorePrefix(bookSeriesObj.name),
 | 
				
			||||||
            type: 'series',
 | 
					            type: 'series',
 | 
				
			||||||
            books: [abJson],
 | 
					            books: [abJson],
 | 
				
			||||||
            addedAt: series ? series.addedAt : 0,
 | 
					            addedAt: series ? series.addedAt : 0,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user