2019-11-15 15:06:03 +01:00
|
|
|
import { join } from 'path'
|
2021-08-17 08:26:20 +02:00
|
|
|
import { CONFIG } from '@server/initializers/config'
|
2022-10-12 16:09:02 +02:00
|
|
|
import { DIRECTORIES, VIDEO_LIVE } from '@server/initializers/constants'
|
2021-08-17 08:26:20 +02:00
|
|
|
import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/types/models'
|
2021-12-29 14:44:58 +01:00
|
|
|
import { removeFragmentedMP4Ext } from '@shared/core-utils'
|
|
|
|
import { buildUUID } from '@shared/extra-utils'
|
2022-10-12 16:09:02 +02:00
|
|
|
import { isVideoInPrivateDirectory } from './video-privacy'
|
2019-11-15 15:06:03 +01:00
|
|
|
|
|
|
|
// ################## Video file name ##################
|
|
|
|
|
2023-07-11 09:21:13 +02:00
|
|
|
function generateWebVideoFilename (resolution: number, extname: string) {
|
2021-07-23 11:20:00 +02:00
|
|
|
return buildUUID() + '-' + resolution + extname
|
2019-11-15 15:06:03 +01:00
|
|
|
}
|
|
|
|
|
2021-07-22 14:28:03 +02:00
|
|
|
function generateHLSVideoFilename (resolution: number) {
|
2021-07-23 11:20:00 +02:00
|
|
|
return `${buildUUID()}-${resolution}-fragmented.mp4`
|
2019-11-15 15:06:03 +01:00
|
|
|
}
|
|
|
|
|
2021-08-17 08:26:20 +02:00
|
|
|
// ################## Streaming playlist ##################
|
2021-02-16 16:25:53 +01:00
|
|
|
|
2022-10-12 16:09:02 +02:00
|
|
|
function getLiveDirectory (video: MVideo) {
|
2021-08-17 08:26:20 +02:00
|
|
|
return getHLSDirectory(video)
|
2021-02-16 16:25:53 +01:00
|
|
|
}
|
|
|
|
|
2022-10-12 16:09:02 +02:00
|
|
|
function getLiveReplayBaseDirectory (video: MVideo) {
|
2022-04-21 09:06:52 +02:00
|
|
|
return join(getLiveDirectory(video), VIDEO_LIVE.REPLAY_DIRECTORY)
|
|
|
|
}
|
|
|
|
|
2022-10-12 16:09:02 +02:00
|
|
|
function getHLSDirectory (video: MVideo) {
|
|
|
|
if (isVideoInPrivateDirectory(video.privacy)) {
|
|
|
|
return join(DIRECTORIES.HLS_STREAMING_PLAYLIST.PRIVATE, video.uuid)
|
|
|
|
}
|
|
|
|
|
|
|
|
return join(DIRECTORIES.HLS_STREAMING_PLAYLIST.PUBLIC, video.uuid)
|
2019-11-15 15:06:03 +01:00
|
|
|
}
|
|
|
|
|
2021-08-17 08:26:20 +02:00
|
|
|
function getHLSRedundancyDirectory (video: MVideoUUID) {
|
2022-10-12 16:09:02 +02:00
|
|
|
return join(DIRECTORIES.HLS_REDUNDANCY, video.uuid)
|
2019-11-21 12:16:27 +01:00
|
|
|
}
|
|
|
|
|
2021-07-23 11:20:00 +02: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 15:06:03 +01:00
|
|
|
// ################## Torrents ##################
|
|
|
|
|
2021-02-16 16:25:53 +01:00
|
|
|
function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, resolution: number) {
|
2019-11-15 15:06:03 +01:00
|
|
|
const extension = '.torrent'
|
2021-07-22 14:28:03 +02:00
|
|
|
const uuid = buildUUID()
|
2021-02-16 16:25:53 +01:00
|
|
|
|
2019-11-15 15:06:03 +01:00
|
|
|
if (isStreamingPlaylist(videoOrPlaylist)) {
|
2021-02-16 16:25:53 +01:00
|
|
|
return `${uuid}-${resolution}-${videoOrPlaylist.getStringType()}${extension}`
|
2019-11-15 15:06:03 +01:00
|
|
|
}
|
|
|
|
|
2021-02-16 16:25:53 +01:00
|
|
|
return uuid + '-' + resolution + extension
|
|
|
|
}
|
|
|
|
|
2021-08-17 08:26:20 +02:00
|
|
|
function getFSTorrentFilePath (videoFile: MVideoFile) {
|
2021-02-16 16:25:53 +01:00
|
|
|
return join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)
|
2019-11-15 15:06:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2021-07-22 14:28:03 +02:00
|
|
|
generateHLSVideoFilename,
|
2023-07-11 09:21:13 +02:00
|
|
|
generateWebVideoFilename,
|
2021-07-22 14:28:03 +02:00
|
|
|
|
2021-02-16 16:25:53 +01:00
|
|
|
generateTorrentFileName,
|
2021-08-17 08:26:20 +02:00
|
|
|
getFSTorrentFilePath,
|
2019-11-21 12:16:27 +01:00
|
|
|
|
2021-02-16 16:25:53 +01:00
|
|
|
getHLSDirectory,
|
2021-08-17 08:26:20 +02:00
|
|
|
getLiveDirectory,
|
2022-04-21 09:06:52 +02:00
|
|
|
getLiveReplayBaseDirectory,
|
2021-08-17 08:26:20 +02:00
|
|
|
getHLSRedundancyDirectory,
|
|
|
|
|
2021-07-23 11:20:00 +02:00
|
|
|
generateHLSMasterPlaylistFilename,
|
|
|
|
generateHlsSha256SegmentsFilename,
|
2021-08-17 08:26:20 +02:00
|
|
|
getHlsResolutionPlaylistFilename
|
2019-11-15 15:06:03 +01:00
|
|
|
}
|