aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/live/live-utils.ts
blob: 46c7fd2f826cdf1d5aa3070c143573bf59887217 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { remove } from 'fs-extra'
import { basename } from 'path'
import { MStreamingPlaylist, MVideo } from '@server/types/models'
import { getLiveDirectory } from '../paths'

function buildConcatenatedName (segmentOrPlaylistPath: string) {
  const num = basename(segmentOrPlaylistPath).match(/^(\d+)(-|\.)/)

  return 'concat-' + num[1] + '.ts'
}

async function cleanupLive (video: MVideo, streamingPlaylist?: MStreamingPlaylist) {
  const hlsDirectory = getLiveDirectory(video)

  await remove(hlsDirectory)

  if (streamingPlaylist) await streamingPlaylist.destroy()
}

export {
  cleanupLive,
  buildConcatenatedName
}