2020-06-18 10:45:25 +02:00
|
|
|
import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/types/models'
|
2019-11-15 15:06:03 +01:00
|
|
|
import { join } from 'path'
|
|
|
|
import { CONFIG } from '@server/initializers/config'
|
2019-11-21 12:16:27 +01:00
|
|
|
import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants'
|
2020-04-23 09:32:53 +02:00
|
|
|
import { extractVideo } from '@server/helpers/video'
|
2019-11-15 15:06:03 +01:00
|
|
|
|
|
|
|
// ################## Video file name ##################
|
|
|
|
|
|
|
|
function getVideoFilename (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
|
|
|
|
const video = extractVideo(videoOrPlaylist)
|
|
|
|
|
2020-11-06 10:57:40 +01:00
|
|
|
if (videoFile.isHLS()) {
|
2019-11-15 15:06:03 +01:00
|
|
|
return generateVideoStreamingPlaylistName(video.uuid, videoFile.resolution)
|
|
|
|
}
|
|
|
|
|
|
|
|
return generateWebTorrentVideoName(video.uuid, videoFile.resolution, videoFile.extname)
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateVideoStreamingPlaylistName (uuid: string, resolution: number) {
|
|
|
|
return `${uuid}-${resolution}-fragmented.mp4`
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateWebTorrentVideoName (uuid: string, resolution: number, extname: string) {
|
|
|
|
return uuid + '-' + resolution + extname
|
|
|
|
}
|
|
|
|
|
|
|
|
function getVideoFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile, isRedundancy = false) {
|
2020-11-06 10:57:40 +01:00
|
|
|
if (videoFile.isHLS()) {
|
2019-11-15 15:06:03 +01:00
|
|
|
const video = extractVideo(videoOrPlaylist)
|
2020-09-17 09:20:52 +02:00
|
|
|
|
|
|
|
return join(getHLSDirectory(video), getVideoFilename(videoOrPlaylist, videoFile))
|
2019-11-15 15:06:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const baseDir = isRedundancy ? CONFIG.STORAGE.REDUNDANCY_DIR : CONFIG.STORAGE.VIDEOS_DIR
|
|
|
|
return join(baseDir, getVideoFilename(videoOrPlaylist, videoFile))
|
|
|
|
}
|
|
|
|
|
2019-11-21 12:16:27 +01:00
|
|
|
// ################## Streaming playlist ##################
|
|
|
|
|
|
|
|
function getHLSDirectory (video: MVideoUUID, isRedundancy = false) {
|
|
|
|
const baseDir = isRedundancy ? HLS_REDUNDANCY_DIRECTORY : HLS_STREAMING_PLAYLIST_DIRECTORY
|
|
|
|
|
|
|
|
return join(baseDir, video.uuid)
|
|
|
|
}
|
|
|
|
|
2019-11-15 15:06:03 +01:00
|
|
|
// ################## Torrents ##################
|
|
|
|
|
|
|
|
function getTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
|
|
|
|
const video = extractVideo(videoOrPlaylist)
|
|
|
|
const extension = '.torrent'
|
|
|
|
|
|
|
|
if (isStreamingPlaylist(videoOrPlaylist)) {
|
|
|
|
return `${video.uuid}-${videoFile.resolution}-${videoOrPlaylist.getStringType()}${extension}`
|
|
|
|
}
|
|
|
|
|
|
|
|
return video.uuid + '-' + videoFile.resolution + extension
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTorrentFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
|
|
|
|
return join(CONFIG.STORAGE.TORRENTS_DIR, getTorrentFileName(videoOrPlaylist, videoFile))
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
generateVideoStreamingPlaylistName,
|
|
|
|
generateWebTorrentVideoName,
|
|
|
|
getVideoFilename,
|
|
|
|
getVideoFilePath,
|
|
|
|
|
|
|
|
getTorrentFileName,
|
2019-11-21 12:16:27 +01:00
|
|
|
getTorrentFilePath,
|
|
|
|
|
|
|
|
getHLSDirectory
|
2019-11-15 15:06:03 +01:00
|
|
|
}
|