2019-11-15 09:06:03 -05:00
|
|
|
import { join } from 'path'
|
2021-07-22 08:28:03 -04:00
|
|
|
import { buildUUID } from '@server/helpers/uuid'
|
2021-08-17 02:26:20 -04:00
|
|
|
import { CONFIG } from '@server/initializers/config'
|
|
|
|
import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants'
|
|
|
|
import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/types/models'
|
2021-07-23 05:20:00 -04:00
|
|
|
import { removeFragmentedMP4Ext } from '@shared/core-utils'
|
2019-11-15 09:06:03 -05:00
|
|
|
|
|
|
|
// ################## Video file name ##################
|
|
|
|
|
2021-07-22 08:28:03 -04:00
|
|
|
function generateWebTorrentVideoFilename (resolution: number, extname: string) {
|
2021-07-23 05:20:00 -04:00
|
|
|
return buildUUID() + '-' + resolution + extname
|
2019-11-15 09:06:03 -05:00
|
|
|
}
|
|
|
|
|
2021-07-22 08:28:03 -04:00
|
|
|
function generateHLSVideoFilename (resolution: number) {
|
2021-07-23 05:20:00 -04:00
|
|
|
return `${buildUUID()}-${resolution}-fragmented.mp4`
|
2019-11-15 09:06:03 -05:00
|
|
|
}
|
|
|
|
|
2021-08-17 02:26:20 -04:00
|
|
|
// ################## Streaming playlist ##################
|
2021-02-16 10:25:53 -05:00
|
|
|
|
2021-08-17 02:26:20 -04:00
|
|
|
function getLiveDirectory (video: MVideoUUID) {
|
|
|
|
return getHLSDirectory(video)
|
2021-02-16 10:25:53 -05:00
|
|
|
}
|
|
|
|
|
2021-08-17 02:26:20 -04:00
|
|
|
function getHLSDirectory (video: MVideoUUID) {
|
|
|
|
return join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid)
|
2019-11-15 09:06:03 -05:00
|
|
|
}
|
|
|
|
|
2021-08-17 02:26:20 -04:00
|
|
|
function getHLSRedundancyDirectory (video: MVideoUUID) {
|
|
|
|
return join(HLS_REDUNDANCY_DIRECTORY, video.uuid)
|
2019-11-21 06:16:27 -05:00
|
|
|
}
|
|
|
|
|
2021-07-23 05:20:00 -04:00
|
|
|
function getHlsResolutionPlaylistFilename (videoFilename: string) {
|
|
|
|
// Video file name already contain resolution
|
|
|
|
return removeFragmentedMP4Ext(videoFilename) + '.m3u8'
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateHLSMasterPlaylistFilename (isLive = false) {
|
|
|
|
if (isLive) return 'master.m3u8'
|
|
|
|
|
|
|
|
return buildUUID() + '-master.m3u8'
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateHlsSha256SegmentsFilename (isLive = false) {
|
|
|
|
if (isLive) return 'segments-sha256.json'
|
|
|
|
|
|
|
|
return buildUUID() + '-segments-sha256.json'
|
|
|
|
}
|
|
|
|
|
2019-11-15 09:06:03 -05:00
|
|
|
// ################## Torrents ##################
|
|
|
|
|
2021-02-16 10:25:53 -05:00
|
|
|
function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, resolution: number) {
|
2019-11-15 09:06:03 -05:00
|
|
|
const extension = '.torrent'
|
2021-07-22 08:28:03 -04:00
|
|
|
const uuid = buildUUID()
|
2021-02-16 10:25:53 -05:00
|
|
|
|
2019-11-15 09:06:03 -05:00
|
|
|
if (isStreamingPlaylist(videoOrPlaylist)) {
|
2021-02-16 10:25:53 -05:00
|
|
|
return `${uuid}-${resolution}-${videoOrPlaylist.getStringType()}${extension}`
|
2019-11-15 09:06:03 -05:00
|
|
|
}
|
|
|
|
|
2021-02-16 10:25:53 -05:00
|
|
|
return uuid + '-' + resolution + extension
|
|
|
|
}
|
|
|
|
|
2021-08-17 02:26:20 -04:00
|
|
|
function getFSTorrentFilePath (videoFile: MVideoFile) {
|
2021-02-16 10:25:53 -05:00
|
|
|
return join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)
|
2019-11-15 09:06:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2021-07-22 08:28:03 -04:00
|
|
|
generateHLSVideoFilename,
|
|
|
|
generateWebTorrentVideoFilename,
|
|
|
|
|
2021-02-16 10:25:53 -05:00
|
|
|
generateTorrentFileName,
|
2021-08-17 02:26:20 -04:00
|
|
|
getFSTorrentFilePath,
|
2019-11-21 06:16:27 -05:00
|
|
|
|
2021-02-16 10:25:53 -05:00
|
|
|
getHLSDirectory,
|
2021-08-17 02:26:20 -04:00
|
|
|
getLiveDirectory,
|
|
|
|
getHLSRedundancyDirectory,
|
|
|
|
|
2021-07-23 05:20:00 -04:00
|
|
|
generateHLSMasterPlaylistFilename,
|
|
|
|
generateHlsSha256SegmentsFilename,
|
2021-08-17 02:26:20 -04:00
|
|
|
getHlsResolutionPlaylistFilename
|
2019-11-15 09:06:03 -05:00
|
|
|
}
|