]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/video-paths.ts
Allow to specify transcoding and import jobs concurrency
[github/Chocobozzz/PeerTube.git] / server / lib / video-paths.ts
index 63011cdb2a12987b31f873284154e6a7cdd3e6e5..53fc8e81d5fcf6f82cb7016c0747701eb647c9ab 100644 (file)
@@ -1,15 +1,15 @@
-import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile } from '@server/typings/models'
-import { extractVideo } from './videos'
+import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/types/models'
 import { join } from 'path'
 import { CONFIG } from '@server/initializers/config'
-import { HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants'
+import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants'
+import { extractVideo } from '@server/helpers/video'
 
 // ################## Video file name ##################
 
 function getVideoFilename (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
   const video = extractVideo(videoOrPlaylist)
 
-  if (isStreamingPlaylist(videoOrPlaylist)) {
+  if (videoFile.isHLS()) {
     return generateVideoStreamingPlaylistName(video.uuid, videoFile.resolution)
   }
 
@@ -25,15 +25,24 @@ function generateWebTorrentVideoName (uuid: string, resolution: number, extname:
 }
 
 function getVideoFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile, isRedundancy = false) {
-  if (isStreamingPlaylist(videoOrPlaylist)) {
+  if (videoFile.isHLS()) {
     const video = extractVideo(videoOrPlaylist)
-    return join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid, getVideoFilename(videoOrPlaylist, videoFile))
+
+    return join(getHLSDirectory(video), getVideoFilename(videoOrPlaylist, videoFile))
   }
 
   const baseDir = isRedundancy ? CONFIG.STORAGE.REDUNDANCY_DIR : CONFIG.STORAGE.VIDEOS_DIR
   return join(baseDir, getVideoFilename(videoOrPlaylist, videoFile))
 }
 
+// ################## Streaming playlist ##################
+
+function getHLSDirectory (video: MVideoUUID, isRedundancy = false) {
+  const baseDir = isRedundancy ? HLS_REDUNDANCY_DIRECTORY : HLS_STREAMING_PLAYLIST_DIRECTORY
+
+  return join(baseDir, video.uuid)
+}
+
 // ################## Torrents ##################
 
 function getTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
@@ -60,5 +69,7 @@ export {
   getVideoFilePath,
 
   getTorrentFileName,
-  getTorrentFilePath
+  getTorrentFilePath,
+
+  getHLSDirectory
 }