import { pathExists, readdir, remove } from 'fs-extra'
import { basename, join } from 'path'
import { logger } from '@server/helpers/logger'
+import { VIDEO_LIVE } from '@server/initializers/constants'
import { MStreamingPlaylist, MStreamingPlaylistVideo, MVideo } from '@server/types/models'
-import { VideoStorage } from '@shared/models'
-import { listHLSFileKeysOf, removeHLSFileObjectStorage, removeHLSObjectStorage } from '../object-storage'
+import { LiveVideoLatencyMode, VideoStorage } from '@shared/models'
+import { listHLSFileKeysOf, removeHLSFileObjectStorageByFullKey, removeHLSObjectStorage } from '../object-storage'
import { getLiveDirectory } from '../paths'
function buildConcatenatedName (segmentOrPlaylistPath: string) {
await cleanupTMPLiveFilesFromFilesystem(video)
}
+function getLiveSegmentTime (latencyMode: LiveVideoLatencyMode) {
+ if (latencyMode === LiveVideoLatencyMode.SMALL_LATENCY) {
+ return VIDEO_LIVE.SEGMENT_TIME_SECONDS.SMALL_LATENCY
+ }
+
+ return VIDEO_LIVE.SEGMENT_TIME_SECONDS.DEFAULT_LATENCY
+}
+
export {
cleanupAndDestroyPermanentLive,
cleanupUnsavedNormalLive,
cleanupTMPLiveFiles,
+ getLiveSegmentTime,
buildConcatenatedName
}
async function cleanupTMPLiveFilesFromObjectStorage (streamingPlaylist: MStreamingPlaylistVideo) {
if (streamingPlaylist.storage !== VideoStorage.OBJECT_STORAGE) return
+ logger.info('Cleanup TMP live files from object storage for %s.', streamingPlaylist.Video.uuid)
+
const keys = await listHLSFileKeysOf(streamingPlaylist)
for (const key of keys) {
if (isTMPLiveFile(key)) {
- await removeHLSFileObjectStorage(streamingPlaylist, key)
+ await removeHLSFileObjectStorageByFullKey(key)
}
}
}