mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-05-24 12:21:42 +00:00
Early out if the description doesn't contain and timestamps
This commit is contained in:
parent
8710816a6f
commit
7f88d4b036
3 changed files with 24 additions and 3 deletions
|
|
@ -91,8 +91,12 @@ class PodcastEpisode extends Model {
|
||||||
Logger.debug("[PodcastEpisode] New episode doesn't have chapters, attempting to generate them from timestamps", rssPodcastEpisode.title)
|
Logger.debug("[PodcastEpisode] New episode doesn't have chapters, attempting to generate them from timestamps", rssPodcastEpisode.title)
|
||||||
try {
|
try {
|
||||||
podcastEpisode.chapters = parsePodcastDescriptionForChapters.parse(podcastEpisode.description, podcastEpisode.audioFile.duration)
|
podcastEpisode.chapters = parsePodcastDescriptionForChapters.parse(podcastEpisode.description, podcastEpisode.audioFile.duration)
|
||||||
|
|
||||||
|
if (podcastEpisode.chapters.length > 0) {
|
||||||
|
Logger.info(`[PodcastEpisode] Successfully generated ${podcastEpisode.chapters.length} chapters`)
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(`[PodcastEpisode] createFromRssPodcastEpisode: Failed to auto generate chapters for "${podcastEpisode.title}"`, error)
|
Logger.error(`[PodcastEpisode] createFromRssPodcastEpisode: Failed to generate chapters for "${podcastEpisode.title}"`, error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,12 @@ module.exports.parse = (podcastDescription, audioDurationSecs) => {
|
||||||
// Split on "</p>", "<br />", "\n", </li>
|
// Split on "</p>", "<br />", "\n", </li>
|
||||||
const descriptionLineSplitRegex = /\<\s*\/\s*p\s*\>|\<\s*br\s*\/\>|\n|\<\s*\/\s*li\s*\>/
|
const descriptionLineSplitRegex = /\<\s*\/\s*p\s*\>|\<\s*br\s*\/\>|\n|\<\s*\/\s*li\s*\>/
|
||||||
|
|
||||||
|
// Early out if there aren't any timestamps in the entire description
|
||||||
|
if (timestampRegex.exec(podcastDescription) == null) {
|
||||||
|
Logger.debug('No timestamps found in description, bailing out early')
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
var descriptionLines = podcastDescription.split(descriptionLineSplitRegex)
|
var descriptionLines = podcastDescription.split(descriptionLineSplitRegex)
|
||||||
var newChapters = []
|
var newChapters = []
|
||||||
|
|
||||||
|
|
@ -98,8 +104,6 @@ module.exports.parse = (podcastDescription, audioDurationSecs) => {
|
||||||
newChapters[newChapters.length - 1].end = audioDurationSecs
|
newChapters[newChapters.length - 1].end = audioDurationSecs
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.info(`Successfully generated ${newChapters.length} chapters`)
|
|
||||||
|
|
||||||
if (newChapters.length == 1) {
|
if (newChapters.length == 1) {
|
||||||
throw new Error('Only one chapter found, treating as invalid description')
|
throw new Error('Only one chapter found, treating as invalid description')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,21 @@
|
||||||
const chai = require('chai')
|
const chai = require('chai')
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
const parsePodcastDescriptionForChapters = require('../../../../server/utils/parsers/parsePodcastDescriptionForChapters')
|
const parsePodcastDescriptionForChapters = require('../../../../server/utils/parsers/parsePodcastDescriptionForChapters')
|
||||||
|
const sinon = require('sinon')
|
||||||
|
const Logger = require('../../../../server/Logger')
|
||||||
|
|
||||||
describe('parsePodcastDescriptionForChapters', () => {
|
describe('parsePodcastDescriptionForChapters', () => {
|
||||||
|
it("should early out if description doens't contain timestamps", () => {
|
||||||
|
let loggerDebugStub = sinon.stub(Logger, 'debug')
|
||||||
|
let description = '<p>Introduction text paragraph 1</p><p>Introduction text paragraph 2</p>'
|
||||||
|
let chapters = parsePodcastDescriptionForChapters.parse(description, 1000)
|
||||||
|
|
||||||
|
expect(chapters).to.be.empty
|
||||||
|
expect(loggerDebugStub.calledWith('No timestamps found in description, bailing out early')).to.be.true
|
||||||
|
|
||||||
|
sinon.restore()
|
||||||
|
})
|
||||||
|
|
||||||
var testCasesTestingSuccess = [
|
var testCasesTestingSuccess = [
|
||||||
{
|
{
|
||||||
testName: 'Should handle descriptions using html paragraphs',
|
testName: 'Should handle descriptions using html paragraphs',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue