mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-03 00:06:46 +01:00
Cleanup rebuild tracks/set chapters
This commit is contained in:
parent
35315843f2
commit
a8b57a1ce9
@ -51,8 +51,8 @@ export default {
|
|||||||
tooltip.style.zIndex = 100
|
tooltip.style.zIndex = 100
|
||||||
tooltip.style.backgroundColor = 'rgba(0,0,0,0.85)'
|
tooltip.style.backgroundColor = 'rgba(0,0,0,0.85)'
|
||||||
tooltip.innerHTML = this.text
|
tooltip.innerHTML = this.text
|
||||||
tooltip.addEventListener('mouseover', this.cancelHide);
|
tooltip.addEventListener('mouseover', this.cancelHide)
|
||||||
tooltip.addEventListener('mouseleave', this.hideTooltip);
|
tooltip.addEventListener('mouseleave', this.hideTooltip)
|
||||||
|
|
||||||
this.setTooltipPosition(tooltip)
|
this.setTooltipPosition(tooltip)
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ export default {
|
|||||||
this.isShowing = false
|
this.isShowing = false
|
||||||
},
|
},
|
||||||
cancelHide() {
|
cancelHide() {
|
||||||
if (this.hideTimeout) clearTimeout(this.hideTimeout);
|
if (this.hideTimeout) clearTimeout(this.hideTimeout)
|
||||||
},
|
},
|
||||||
mouseover() {
|
mouseover() {
|
||||||
if (!this.isShowing) this.showTooltip()
|
if (!this.isShowing) this.showTooltip()
|
||||||
|
@ -356,9 +356,9 @@ class Book {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateAudioTracks(orderedFileData) {
|
updateAudioTracks(orderedFileData) {
|
||||||
var index = 1
|
let index = 1
|
||||||
this.audioFiles = orderedFileData.map((fileData) => {
|
this.audioFiles = orderedFileData.map((fileData) => {
|
||||||
var audioFile = this.audioFiles.find(af => af.ino === fileData.ino)
|
const audioFile = this.audioFiles.find(af => af.ino === fileData.ino)
|
||||||
audioFile.manuallyVerified = true
|
audioFile.manuallyVerified = true
|
||||||
audioFile.invalid = false
|
audioFile.invalid = false
|
||||||
audioFile.error = null
|
audioFile.error = null
|
||||||
@ -376,11 +376,11 @@ class Book {
|
|||||||
this.rebuildTracks()
|
this.rebuildTracks()
|
||||||
}
|
}
|
||||||
|
|
||||||
rebuildTracks(preferOverdriveMediaMarker) {
|
rebuildTracks() {
|
||||||
Logger.debug(`[Book] Tracks being rebuilt...!`)
|
Logger.debug(`[Book] Tracks being rebuilt...!`)
|
||||||
this.audioFiles.sort((a, b) => a.index - b.index)
|
this.audioFiles.sort((a, b) => a.index - b.index)
|
||||||
this.missingParts = []
|
this.missingParts = []
|
||||||
this.setChapters(preferOverdriveMediaMarker)
|
this.setChapters()
|
||||||
this.checkUpdateMissingTracks()
|
this.checkUpdateMissingTracks()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -412,14 +412,16 @@ class Book {
|
|||||||
return wasUpdated
|
return wasUpdated
|
||||||
}
|
}
|
||||||
|
|
||||||
setChapters(preferOverdriveMediaMarker = false) {
|
setChapters() {
|
||||||
|
const preferOverdriveMediaMarker = !!global.ServerSettings.scannerPreferOverdriveMediaMarker
|
||||||
|
|
||||||
// If 1 audio file without chapters, then no chapters will be set
|
// If 1 audio file without chapters, then no chapters will be set
|
||||||
var includedAudioFiles = this.audioFiles.filter(af => !af.exclude)
|
const includedAudioFiles = this.audioFiles.filter(af => !af.exclude)
|
||||||
if (!includedAudioFiles.length) return
|
if (!includedAudioFiles.length) return
|
||||||
|
|
||||||
// If overdrive media markers are present and preferred, use those instead
|
// If overdrive media markers are present and preferred, use those instead
|
||||||
if (preferOverdriveMediaMarker) {
|
if (preferOverdriveMediaMarker) {
|
||||||
var overdriveChapters = parseOverdriveMediaMarkersAsChapters(includedAudioFiles)
|
const overdriveChapters = parseOverdriveMediaMarkersAsChapters(includedAudioFiles)
|
||||||
if (overdriveChapters) {
|
if (overdriveChapters) {
|
||||||
Logger.info('[Book] Overdrive Media Markers and preference found! Using these for chapter definitions')
|
Logger.info('[Book] Overdrive Media Markers and preference found! Using these for chapter definitions')
|
||||||
this.chapters = overdriveChapters
|
this.chapters = overdriveChapters
|
||||||
@ -462,15 +464,17 @@ class Book {
|
|||||||
} else if (includedAudioFiles.length > 1) {
|
} else if (includedAudioFiles.length > 1) {
|
||||||
// Build chapters from audio files
|
// Build chapters from audio files
|
||||||
this.chapters = []
|
this.chapters = []
|
||||||
var currChapterId = 0
|
let currChapterId = 0
|
||||||
var currStartTime = 0
|
let currStartTime = 0
|
||||||
includedAudioFiles.forEach((file) => {
|
includedAudioFiles.forEach((file) => {
|
||||||
if (file.duration) {
|
if (file.duration) {
|
||||||
|
const title = file.metadata.filename ? Path.basename(file.metadata.filename, Path.extname(file.metadata.filename)) : `Chapter ${currChapterId}`
|
||||||
|
|
||||||
this.chapters.push({
|
this.chapters.push({
|
||||||
id: currChapterId++,
|
id: currChapterId++,
|
||||||
start: currStartTime,
|
start: currStartTime,
|
||||||
end: currStartTime + file.duration,
|
end: currStartTime + file.duration,
|
||||||
title: file.metadata.filename ? Path.basename(file.metadata.filename, Path.extname(file.metadata.filename)) : `Chapter ${currChapterId}`
|
title
|
||||||
})
|
})
|
||||||
currStartTime += file.duration
|
currStartTime += file.duration
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ class MediaFileScanner {
|
|||||||
*/
|
*/
|
||||||
async scanMediaFiles(mediaLibraryFiles, libraryItem, libraryScan = null) {
|
async scanMediaFiles(mediaLibraryFiles, libraryItem, libraryScan = null) {
|
||||||
const preferAudioMetadata = libraryScan ? !!libraryScan.preferAudioMetadata : !!global.ServerSettings.scannerPreferAudioMetadata
|
const preferAudioMetadata = libraryScan ? !!libraryScan.preferAudioMetadata : !!global.ServerSettings.scannerPreferAudioMetadata
|
||||||
const preferOverdriveMediaMarker = libraryScan ? !!libraryScan.preferOverdriveMediaMarker : !!global.ServerSettings.scannerPreferOverdriveMediaMarker
|
const preferOverdriveMediaMarker = !!global.ServerSettings.scannerPreferOverdriveMediaMarker
|
||||||
|
|
||||||
let hasUpdated = false
|
let hasUpdated = false
|
||||||
|
|
||||||
@ -280,7 +280,7 @@ class MediaFileScanner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hasUpdated) {
|
if (hasUpdated) {
|
||||||
libraryItem.media.rebuildTracks(preferOverdriveMediaMarker)
|
libraryItem.media.rebuildTracks()
|
||||||
}
|
}
|
||||||
} else if (libraryItem.mediaType === 'podcast') { // Podcast Media Type
|
} else if (libraryItem.mediaType === 'podcast') { // Podcast Media Type
|
||||||
const existingAudioFiles = mediaScanResult.audioFiles.filter(af => libraryItem.media.findFileWithInode(af.ino))
|
const existingAudioFiles = mediaScanResult.audioFiles.filter(af => libraryItem.media.findFileWithInode(af.ino))
|
||||||
|
Loading…
Reference in New Issue
Block a user