+
+// ---------------------------------------------------------------------------
+
+function isTMPLiveFile (name: string) {
+ return name.endsWith('.ts') ||
+ name.endsWith('.m3u8') ||
+ name.endsWith('.json') ||
+ name.endsWith('.mpd') ||
+ name.endsWith('.m4s') ||
+ name.endsWith('.tmp')
+}
+
+async function cleanupTMPLiveFilesFromFilesystem (video: MVideo) {
+ const hlsDirectory = getLiveDirectory(video)
+
+ if (!await pathExists(hlsDirectory)) return
+
+ logger.info('Cleanup TMP live files from filesystem of %s.', hlsDirectory)
+
+ const files = await readdir(hlsDirectory)
+
+ for (const filename of files) {
+ if (isTMPLiveFile(filename)) {
+ const p = join(hlsDirectory, filename)
+
+ remove(p)
+ .catch(err => logger.error('Cannot remove %s.', p, { err }))
+ }
+ }
+}
+
+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 removeHLSFileObjectStorageByFullKey(key)
+ }
+ }
+}