2022-03-11 01:45:02 +01:00
|
|
|
var { bytesPretty } = require('../../utils/fileUtils')
|
2021-08-18 00:01:11 +02:00
|
|
|
|
|
|
|
class AudioTrack {
|
|
|
|
constructor(audioTrack = null) {
|
|
|
|
this.index = null
|
2021-08-26 00:36:54 +02:00
|
|
|
this.ino = null
|
|
|
|
|
2021-08-18 00:01:11 +02:00
|
|
|
this.path = null
|
|
|
|
this.fullPath = null
|
|
|
|
this.ext = null
|
|
|
|
this.filename = null
|
|
|
|
|
|
|
|
this.format = null
|
|
|
|
this.duration = null
|
|
|
|
this.size = null
|
|
|
|
this.bitRate = null
|
|
|
|
this.language = null
|
|
|
|
this.codec = null
|
|
|
|
this.timeBase = null
|
|
|
|
this.channels = null
|
|
|
|
this.channelLayout = null
|
|
|
|
|
|
|
|
if (audioTrack) {
|
|
|
|
this.construct(audioTrack)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
construct(audioTrack) {
|
|
|
|
this.index = audioTrack.index
|
2021-08-26 00:36:54 +02:00
|
|
|
this.ino = audioTrack.ino || null
|
|
|
|
|
2021-08-18 00:01:11 +02:00
|
|
|
this.path = audioTrack.path
|
|
|
|
this.fullPath = audioTrack.fullPath
|
|
|
|
this.ext = audioTrack.ext
|
|
|
|
this.filename = audioTrack.filename
|
|
|
|
|
|
|
|
this.format = audioTrack.format
|
|
|
|
this.duration = audioTrack.duration
|
|
|
|
this.size = audioTrack.size
|
|
|
|
this.bitRate = audioTrack.bitRate
|
|
|
|
this.language = audioTrack.language
|
|
|
|
this.codec = audioTrack.codec
|
|
|
|
this.timeBase = audioTrack.timeBase
|
|
|
|
this.channels = audioTrack.channels
|
|
|
|
this.channelLayout = audioTrack.channelLayout
|
|
|
|
}
|
|
|
|
|
|
|
|
get name() {
|
|
|
|
return `${String(this.index).padStart(3, '0')}: ${this.filename} (${bytesPretty(this.size)}) [${this.duration}]`
|
|
|
|
}
|
|
|
|
|
|
|
|
toJSON() {
|
|
|
|
return {
|
|
|
|
index: this.index,
|
2021-08-26 00:36:54 +02:00
|
|
|
ino: this.ino,
|
2021-08-18 00:01:11 +02:00
|
|
|
path: this.path,
|
|
|
|
fullPath: this.fullPath,
|
|
|
|
ext: this.ext,
|
|
|
|
filename: this.filename,
|
|
|
|
format: this.format,
|
|
|
|
duration: this.duration,
|
|
|
|
size: this.size,
|
|
|
|
bitRate: this.bitRate,
|
|
|
|
language: this.language,
|
2021-10-02 01:42:48 +02:00
|
|
|
codec: this.codec,
|
2021-08-18 00:01:11 +02:00
|
|
|
timeBase: this.timeBase,
|
|
|
|
channels: this.channels,
|
2021-08-26 00:36:54 +02:00
|
|
|
channelLayout: this.channelLayout,
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setData(probeData) {
|
|
|
|
this.index = probeData.index
|
2021-08-26 00:36:54 +02:00
|
|
|
this.ino = probeData.ino || null
|
|
|
|
|
2021-08-18 00:01:11 +02:00
|
|
|
this.path = probeData.path
|
|
|
|
this.fullPath = probeData.fullPath
|
|
|
|
this.ext = probeData.ext
|
|
|
|
this.filename = probeData.filename
|
|
|
|
|
|
|
|
this.format = probeData.format
|
|
|
|
this.duration = probeData.duration
|
|
|
|
this.size = probeData.size
|
2021-09-08 16:15:54 +02:00
|
|
|
this.bitRate = probeData.bitRate
|
2021-08-18 00:01:11 +02:00
|
|
|
this.language = probeData.language
|
2021-10-02 01:42:48 +02:00
|
|
|
this.codec = probeData.codec || null
|
2021-09-08 16:15:54 +02:00
|
|
|
this.timeBase = probeData.timeBase
|
2021-08-18 00:01:11 +02:00
|
|
|
this.channels = probeData.channels
|
2021-09-08 16:15:54 +02:00
|
|
|
this.channelLayout = probeData.channelLayout
|
2021-10-01 01:52:32 +02:00
|
|
|
}
|
2021-08-18 00:01:11 +02:00
|
|
|
|
2021-10-01 01:52:32 +02:00
|
|
|
syncMetadata(audioFile) {
|
|
|
|
var hasUpdates = false
|
|
|
|
var keysToSync = ['format', 'duration', 'size', 'bitRate', 'language', 'codec', 'timeBase', 'channels', 'channelLayout']
|
|
|
|
keysToSync.forEach((key) => {
|
|
|
|
if (audioFile[key] !== undefined && audioFile[key] !== this[key]) {
|
|
|
|
hasUpdates = true
|
|
|
|
this[key] = audioFile[key]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return hasUpdates
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
2021-08-26 00:36:54 +02:00
|
|
|
|
|
|
|
syncFile(newFile) {
|
|
|
|
var hasUpdates = false
|
|
|
|
var keysToSync = ['path', 'fullPath', 'ext', 'filename']
|
|
|
|
keysToSync.forEach((key) => {
|
|
|
|
if (newFile[key] !== undefined && newFile[key] !== this[key]) {
|
|
|
|
hasUpdates = true
|
|
|
|
this[key] = newFile[key]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return hasUpdates
|
|
|
|
}
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
module.exports = AudioTrack
|