mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Merge pull request #2734 from mikiher/fix-sequence-cleanup
Make series sequence cleanup slighlty less aggressive
This commit is contained in:
commit
91248b496e
@ -29,10 +29,9 @@ class Audible {
|
|||||||
*/
|
*/
|
||||||
cleanSeriesSequence(seriesName, sequence) {
|
cleanSeriesSequence(seriesName, sequence) {
|
||||||
if (!sequence) return ''
|
if (!sequence) return ''
|
||||||
let updatedSequence = sequence.replace(/Book /, '').trim()
|
// match any number with optional decimal (e.g, 1 or 1.5 or .5)
|
||||||
if (updatedSequence.includes(' ')) {
|
let numberFound = sequence.match(/\.\d+|\d+(?:\.\d+)?/)
|
||||||
updatedSequence = updatedSequence.split(' ').shift().replace(/,$/, '')
|
let updatedSequence = numberFound ? numberFound[0] : sequence
|
||||||
}
|
|
||||||
if (sequence !== updatedSequence) {
|
if (sequence !== updatedSequence) {
|
||||||
Logger.debug(`[Audible] Series "${seriesName}" sequence was cleaned from "${sequence}" to "${updatedSequence}"`)
|
Logger.debug(`[Audible] Series "${seriesName}" sequence was cleaned from "${sequence}" to "${updatedSequence}"`)
|
||||||
}
|
}
|
||||||
|
48
test/server/providers/Audible.test.js
Normal file
48
test/server/providers/Audible.test.js
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
const Audible = require('../../../server/providers/Audible')
|
||||||
|
const { expect } = require('chai')
|
||||||
|
const sinon = require('sinon')
|
||||||
|
|
||||||
|
describe('Audible', () => {
|
||||||
|
let audible;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
audible = new Audible();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('cleanSeriesSequence', () => {
|
||||||
|
it('should return an empty string if sequence is falsy', () => {
|
||||||
|
const result = audible.cleanSeriesSequence('Series Name', null)
|
||||||
|
expect(result).to.equal('')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return the sequence as is if it does not contain a number', () => {
|
||||||
|
const result = audible.cleanSeriesSequence('Series Name', 'part a')
|
||||||
|
expect(result).to.equal('part a')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return the sequence as is if contains just a number', () => {
|
||||||
|
const result = audible.cleanSeriesSequence('Series Name', '2')
|
||||||
|
expect(result).to.equal('2')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return the sequence as is if contains just a number with decimals', () => {
|
||||||
|
const result = audible.cleanSeriesSequence('Series Name', '2.3')
|
||||||
|
expect(result).to.equal('2.3')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should extract and return the first number from the sequence', () => {
|
||||||
|
const result = audible.cleanSeriesSequence('Series Name', 'Book 1')
|
||||||
|
expect(result).to.equal('1')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should extract and return the number with decimals from the sequence', () => {
|
||||||
|
const result = audible.cleanSeriesSequence('Series Name', 'Book 1.5')
|
||||||
|
expect(result).to.equal('1.5')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should extract and return the number even if it has no leading zero', () => {
|
||||||
|
const result = audible.cleanSeriesSequence('Series Name', 'Book .5')
|
||||||
|
expect(result).to.equal('.5')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user