2022-03-18 01:10:47 +01:00
|
|
|
const Path = require('path')
|
2023-01-06 00:45:27 +01:00
|
|
|
const { encodeUriPath } = require('../../utils/fileUtils')
|
2022-04-03 23:01:59 +02:00
|
|
|
|
2022-03-18 01:10:47 +01:00
|
|
|
class AudioTrack {
|
|
|
|
constructor() {
|
|
|
|
this.index = null
|
|
|
|
this.startOffset = null
|
|
|
|
this.duration = null
|
|
|
|
this.title = null
|
|
|
|
this.contentUrl = null
|
|
|
|
this.mimeType = null
|
2022-04-03 23:01:59 +02:00
|
|
|
this.metadata = null
|
2022-03-18 01:10:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
toJSON() {
|
|
|
|
return {
|
|
|
|
index: this.index,
|
|
|
|
startOffset: this.startOffset,
|
|
|
|
duration: this.duration,
|
|
|
|
title: this.title,
|
|
|
|
contentUrl: this.contentUrl,
|
2022-04-03 23:01:59 +02:00
|
|
|
mimeType: this.mimeType,
|
|
|
|
metadata: this.metadata ? this.metadata.toJSON() : null
|
2022-03-18 01:10:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setData(itemId, audioFile, startOffset) {
|
|
|
|
this.index = audioFile.index
|
|
|
|
this.startOffset = startOffset
|
|
|
|
this.duration = audioFile.duration
|
|
|
|
this.title = audioFile.metadata.filename || ''
|
2022-10-01 23:07:30 +02:00
|
|
|
this.contentUrl = Path.join(`${global.RouterBasePath}/s/item/${itemId}`, encodeUriPath(audioFile.metadata.relPath))
|
2022-03-18 01:10:47 +01:00
|
|
|
this.mimeType = audioFile.mimeType
|
2022-04-03 23:01:59 +02:00
|
|
|
this.metadata = audioFile.metadata.clone()
|
2022-03-18 01:10:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
setFromStream(title, duration, contentUrl) {
|
|
|
|
this.index = 1
|
|
|
|
this.startOffset = 0
|
|
|
|
this.duration = duration
|
|
|
|
this.title = title
|
|
|
|
this.contentUrl = contentUrl
|
|
|
|
this.mimeType = 'application/vnd.apple.mpegurl'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = AudioTrack
|