1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 09:49:20 +02:00

Fix chapters import

This commit is contained in:
Chocobozzz 2023-11-29 14:11:57 +01:00
parent 7a953a6b2f
commit f9e710e7d4
No known key found for this signature in database
GPG key ID: 583A612D890159BE
4 changed files with 31 additions and 14 deletions

View file

@ -2,7 +2,7 @@ import { timeToInt, timecodeRegexString } from '../common/date.js'
const timecodeRegex = new RegExp(`^(${timecodeRegexString})\\s`)
export function parseChapters (text: string) {
export function parseChapters (text: string, maxTitleLength: number) {
if (!text) return []
const lines = text.split(/\r?\n|\r|\n/g)
@ -25,8 +25,11 @@ export function parseChapters (text: string) {
const timecode = timeToInt(timecodeText)
const title = line.replace(matched[0], '')
chapters.push({ timecode, title })
chapters.push({ timecode, title: title.slice(0, maxTitleLength) })
}
return chapters
// Only consider chapters if there are more than one
if (chapters.length > 1) return chapters
return []
}