2019-11-15 08:06:03 -06:00
|
|
|
import { join } from 'path'
|
2023-07-31 07:34:36 -05:00
|
|
|
import { CONFIG } from '@server/initializers/config.js'
|
|
|
|
import { DIRECTORIES, VIDEO_LIVE } from '@server/initializers/constants.js'
|
2024-02-12 03:47:52 -06:00
|
|
|
import {
|
|
|
|
isStreamingPlaylist,
|
|
|
|
MStreamingPlaylistVideo,
|
|
|
|
MUserExport,
|
|
|
|
MUserImport,
|
|
|
|
MVideo,
|
|
|
|
MVideoFile,
|
|
|
|
MVideoUUID
|
|
|
|
} from '@server/types/models/index.js'
|
2023-07-31 07:34:36 -05:00
|
|
|
import { removeFragmentedMP4Ext } from '@peertube/peertube-core-utils'
|
|
|
|
import { buildUUID } from '@peertube/peertube-node-utils'
|
|
|
|
import { isVideoInPrivateDirectory } from './video-privacy.js'
|
2019-11-15 08:06:03 -06:00
|
|
|
|
|
|
|
// ################## Video file name ##################
|
|
|
|
|
2024-02-12 03:47:52 -06:00
|
|
|
export function generateWebVideoFilename (resolution: number, extname: string) {
|
2021-07-23 04:20:00 -05:00
|
|
|
return buildUUID() + '-' + resolution + extname
|
2019-11-15 08:06:03 -06:00
|
|
|
}
|
|
|
|
|
2024-02-12 03:47:52 -06:00
|
|
|
export function generateHLSVideoFilename (resolution: number) {
|
2021-07-23 04:20:00 -05:00
|
|
|
return `${buildUUID()}-${resolution}-fragmented.mp4`
|
2019-11-15 08:06:03 -06:00
|
|
|
}
|
|
|
|
|
2021-08-17 01:26:20 -05:00
|
|
|
// ################## Streaming playlist ##################
|
2021-02-16 09:25:53 -06:00
|
|
|
|
2024-02-12 03:47:52 -06:00
|
|
|
export function getLiveDirectory (video: MVideo) {
|
2021-08-17 01:26:20 -05:00
|
|
|
return getHLSDirectory(video)
|
2021-02-16 09:25:53 -06:00
|
|
|
}
|
|
|
|
|
2024-02-12 03:47:52 -06:00
|
|
|
export function getLiveReplayBaseDirectory (video: MVideo) {
|
2022-04-21 02:06:52 -05:00
|
|
|
return join(getLiveDirectory(video), VIDEO_LIVE.REPLAY_DIRECTORY)
|
|
|
|
}
|
|
|
|
|
2024-02-12 03:47:52 -06:00
|
|
|
export function getHLSDirectory (video: MVideo) {
|
2022-10-12 09:09:02 -05:00
|
|
|
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 08:06:03 -06:00
|
|
|
}
|
|
|
|
|
2024-02-12 03:47:52 -06:00
|
|
|
export function getHLSRedundancyDirectory (video: MVideoUUID) {
|
2022-10-12 09:09:02 -05:00
|
|
|
return join(DIRECTORIES.HLS_REDUNDANCY, video.uuid)
|
2019-11-21 05:16:27 -06:00
|
|
|
}
|
|
|
|
|
2024-02-12 03:47:52 -06:00
|
|
|
export function getHlsResolutionPlaylistFilename (videoFilename: string) {
|
2021-07-23 04:20:00 -05:00
|
|
|
// Video file name already contain resolution
|
|
|
|
return removeFragmentedMP4Ext(videoFilename) + '.m3u8'
|
|
|
|
}
|
|
|
|
|
2024-02-12 03:47:52 -06:00
|
|
|
export function generateHLSMasterPlaylistFilename (isLive = false) {
|
2021-07-23 04:20:00 -05:00
|
|
|
if (isLive) return 'master.m3u8'
|
|
|
|
|
|
|
|
return buildUUID() + '-master.m3u8'
|
|
|
|
}
|
|
|
|
|
2024-02-12 03:47:52 -06:00
|
|
|
export function generateHlsSha256SegmentsFilename (isLive = false) {
|
2021-07-23 04:20:00 -05:00
|
|
|
if (isLive) return 'segments-sha256.json'
|
|
|
|
|
|
|
|
return buildUUID() + '-segments-sha256.json'
|
|
|
|
}
|
|
|
|
|
2019-11-15 08:06:03 -06:00
|
|
|
// ################## Torrents ##################
|
|
|
|
|
2024-02-12 03:47:52 -06:00
|
|
|
export function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, resolution: number) {
|
2019-11-15 08:06:03 -06:00
|
|
|
const extension = '.torrent'
|
2021-07-22 07:28:03 -05:00
|
|
|
const uuid = buildUUID()
|
2021-02-16 09:25:53 -06:00
|
|
|
|
2019-11-15 08:06:03 -06:00
|
|
|
if (isStreamingPlaylist(videoOrPlaylist)) {
|
2021-02-16 09:25:53 -06:00
|
|
|
return `${uuid}-${resolution}-${videoOrPlaylist.getStringType()}${extension}`
|
2019-11-15 08:06:03 -06:00
|
|
|
}
|
|
|
|
|
2021-02-16 09:25:53 -06:00
|
|
|
return uuid + '-' + resolution + extension
|
|
|
|
}
|
|
|
|
|
2024-02-12 03:47:52 -06:00
|
|
|
export function getFSTorrentFilePath (videoFile: MVideoFile) {
|
2021-02-16 09:25:53 -06:00
|
|
|
return join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)
|
2019-11-15 08:06:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2024-02-12 03:47:52 -06:00
|
|
|
export function getFSUserExportFilePath (userExport: MUserExport) {
|
|
|
|
return join(CONFIG.STORAGE.TMP_PERSISTENT_DIR, userExport.filename)
|
|
|
|
}
|
2021-08-17 01:26:20 -05:00
|
|
|
|
2024-02-12 03:47:52 -06:00
|
|
|
export function getFSUserImportFilePath (userImport: MUserImport) {
|
|
|
|
return join(CONFIG.STORAGE.TMP_PERSISTENT_DIR, userImport.filename)
|
2019-11-15 08:06:03 -06:00
|
|
|
}
|