]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/video-paths.ts
Allow to specify transcoding and import jobs concurrency
[github/Chocobozzz/PeerTube.git] / server / lib / video-paths.ts
CommitLineData
26d6bf65 1import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/types/models'
d7a25329
C
2import { join } from 'path'
3import { CONFIG } from '@server/initializers/config'
66fb2aa3 4import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants'
8dc8a34e 5import { extractVideo } from '@server/helpers/video'
d7a25329
C
6
7// ################## Video file name ##################
8
9function getVideoFilename (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
10 const video = extractVideo(videoOrPlaylist)
11
053aed43 12 if (videoFile.isHLS()) {
d7a25329
C
13 return generateVideoStreamingPlaylistName(video.uuid, videoFile.resolution)
14 }
15
16 return generateWebTorrentVideoName(video.uuid, videoFile.resolution, videoFile.extname)
17}
18
19function generateVideoStreamingPlaylistName (uuid: string, resolution: number) {
20 return `${uuid}-${resolution}-fragmented.mp4`
21}
22
23function generateWebTorrentVideoName (uuid: string, resolution: number, extname: string) {
24 return uuid + '-' + resolution + extname
25}
26
27function getVideoFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile, isRedundancy = false) {
053aed43 28 if (videoFile.isHLS()) {
d7a25329 29 const video = extractVideo(videoOrPlaylist)
c6c0fa6c
C
30
31 return join(getHLSDirectory(video), getVideoFilename(videoOrPlaylist, videoFile))
d7a25329
C
32 }
33
34 const baseDir = isRedundancy ? CONFIG.STORAGE.REDUNDANCY_DIR : CONFIG.STORAGE.VIDEOS_DIR
35 return join(baseDir, getVideoFilename(videoOrPlaylist, videoFile))
36}
37
66fb2aa3
C
38// ################## Streaming playlist ##################
39
40function getHLSDirectory (video: MVideoUUID, isRedundancy = false) {
41 const baseDir = isRedundancy ? HLS_REDUNDANCY_DIRECTORY : HLS_STREAMING_PLAYLIST_DIRECTORY
42
43 return join(baseDir, video.uuid)
44}
45
d7a25329
C
46// ################## Torrents ##################
47
48function getTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
49 const video = extractVideo(videoOrPlaylist)
50 const extension = '.torrent'
51
52 if (isStreamingPlaylist(videoOrPlaylist)) {
53 return `${video.uuid}-${videoFile.resolution}-${videoOrPlaylist.getStringType()}${extension}`
54 }
55
56 return video.uuid + '-' + videoFile.resolution + extension
57}
58
59function getTorrentFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
60 return join(CONFIG.STORAGE.TORRENTS_DIR, getTorrentFileName(videoOrPlaylist, videoFile))
61}
62
63// ---------------------------------------------------------------------------
64
65export {
66 generateVideoStreamingPlaylistName,
67 generateWebTorrentVideoName,
68 getVideoFilename,
69 getVideoFilePath,
70
71 getTorrentFileName,
66fb2aa3
C
72 getTorrentFilePath,
73
74 getHLSDirectory
d7a25329 75}