1 import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile } from '@server/typings/models'
2 import { extractVideo } from './videos'
3 import { join } from 'path'
4 import { CONFIG } from '@server/initializers/config'
5 import { HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants'
7 // ################## Video file name ##################
9 function getVideoFilename (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
10 const video = extractVideo(videoOrPlaylist)
12 if (isStreamingPlaylist(videoOrPlaylist)) {
13 return generateVideoStreamingPlaylistName(video.uuid, videoFile.resolution)
16 return generateWebTorrentVideoName(video.uuid, videoFile.resolution, videoFile.extname)
19 function generateVideoStreamingPlaylistName (uuid: string, resolution: number) {
20 return `${uuid}-${resolution}-fragmented.mp4`
23 function generateWebTorrentVideoName (uuid: string, resolution: number, extname: string) {
24 return uuid + '-' + resolution + extname
27 function getVideoFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile, isRedundancy = false) {
28 if (isStreamingPlaylist(videoOrPlaylist)) {
29 const video = extractVideo(videoOrPlaylist)
30 return join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid, getVideoFilename(videoOrPlaylist, videoFile))
33 const baseDir = isRedundancy ? CONFIG.STORAGE.REDUNDANCY_DIR : CONFIG.STORAGE.VIDEOS_DIR
34 return join(baseDir, getVideoFilename(videoOrPlaylist, videoFile))
37 // ################## Torrents ##################
39 function getTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
40 const video = extractVideo(videoOrPlaylist)
41 const extension = '.torrent'
43 if (isStreamingPlaylist(videoOrPlaylist)) {
44 return `${video.uuid}-${videoFile.resolution}-${videoOrPlaylist.getStringType()}${extension}`
47 return video.uuid + '-' + videoFile.resolution + extension
50 function getTorrentFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
51 return join(CONFIG.STORAGE.TORRENTS_DIR, getTorrentFileName(videoOrPlaylist, videoFile))
54 // ---------------------------------------------------------------------------
57 generateVideoStreamingPlaylistName,
58 generateWebTorrentVideoName,