audiobookshelf/server/scanner/MediaProbeData.js

82 lines
2.2 KiB
JavaScript
Raw Permalink Normal View History

const AudioMetaTags = require('../objects/metadata/AudioMetaTags')
2022-05-31 02:26:53 +02:00
class MediaProbeData {
constructor(probeData) {
this.embeddedCoverArt = null
this.format = null
this.duration = null
this.size = null
2022-05-31 02:26:53 +02:00
this.audioStream = null
this.videoStream = null
this.bitRate = null
this.codec = null
this.timeBase = null
this.language = null
this.channelLayout = null
this.channels = null
this.sampleRate = null
this.chapters = []
this.audioMetaTags = null
this.trackNumber = null
this.trackTotal = null
this.discNumber = null
this.discTotal = null
if (probeData) {
this.construct(probeData)
}
}
construct(probeData) {
for (const key in probeData) {
if (key === 'audioMetaTags' && probeData[key]) {
this[key] = new AudioMetaTags(probeData[key])
} else if (this[key] !== undefined) {
this[key] = probeData[key]
}
}
}
getEmbeddedCoverArt(videoStream) {
const ImageCodecs = ['mjpeg', 'jpeg', 'png']
return ImageCodecs.includes(videoStream.codec) ? videoStream.codec : null
}
setData(data) {
this.embeddedCoverArt = data.video_stream ? this.getEmbeddedCoverArt(data.video_stream) : null
this.format = data.format
this.duration = data.duration
this.size = data.size
2022-05-31 02:26:53 +02:00
this.audioStream = data.audio_stream
2022-05-31 02:26:53 +02:00
this.videoStream = this.embeddedCoverArt ? null : data.video_stream || null
this.bitRate = this.audioStream.bit_rate || data.bit_rate
this.codec = this.audioStream.codec
this.timeBase = this.audioStream.time_base
this.language = this.audioStream.language
this.channelLayout = this.audioStream.channel_layout
this.channels = this.audioStream.channels
this.sampleRate = this.audioStream.sample_rate
this.chapters = data.chapters || []
this.audioMetaTags = new AudioMetaTags()
this.audioMetaTags.setData(data.tags)
}
setDataFromTone(data) {
// TODO: Implement
this.format = data.format
this.duration = data.duration
this.size = data.size
this.audioMetaTags = new AudioMetaTags()
this.audioMetaTags.setDataFromTone(data.tags)
}
}
2022-05-31 02:26:53 +02:00
module.exports = MediaProbeData