2022-05-31 02:26:53 +02:00
|
|
|
const Path = require('path')
|
2023-01-06 00:45:27 +01:00
|
|
|
const { encodeUriPath } = require('../../utils/fileUtils')
|
2022-05-31 02:26:53 +02:00
|
|
|
|
|
|
|
class VideoTrack {
|
|
|
|
constructor() {
|
|
|
|
this.index = null
|
|
|
|
this.duration = null
|
|
|
|
this.title = null
|
|
|
|
this.contentUrl = null
|
|
|
|
this.mimeType = null
|
2023-01-07 22:58:57 +01:00
|
|
|
this.codec = null
|
2022-05-31 02:26:53 +02:00
|
|
|
this.metadata = null
|
|
|
|
}
|
|
|
|
|
|
|
|
toJSON() {
|
|
|
|
return {
|
|
|
|
index: this.index,
|
|
|
|
duration: this.duration,
|
|
|
|
title: this.title,
|
|
|
|
contentUrl: this.contentUrl,
|
|
|
|
mimeType: this.mimeType,
|
2023-01-07 22:58:57 +01:00
|
|
|
codec: this.codec,
|
2022-05-31 02:26:53 +02:00
|
|
|
metadata: this.metadata ? this.metadata.toJSON() : null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setData(itemId, videoFile) {
|
|
|
|
this.index = videoFile.index
|
|
|
|
this.duration = videoFile.duration
|
|
|
|
this.title = videoFile.metadata.filename || ''
|
2023-06-27 22:56:33 +02:00
|
|
|
this.contentUrl = Path.join(`${global.RouterBasePath}/api/items/${itemId}/file/${videoFile.ino}`, encodeUriPath(videoFile.metadata.relPath))
|
2022-05-31 02:26:53 +02:00
|
|
|
this.mimeType = videoFile.mimeType
|
2023-01-07 22:58:57 +01:00
|
|
|
this.codec = videoFile.codec
|
2022-05-31 02:26:53 +02:00
|
|
|
this.metadata = videoFile.metadata.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
setFromStream(title, duration, contentUrl) {
|
|
|
|
this.index = 1
|
|
|
|
this.duration = duration
|
|
|
|
this.title = title
|
|
|
|
this.contentUrl = contentUrl
|
|
|
|
this.mimeType = 'application/vnd.apple.mpegurl'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = VideoTrack
|