]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/paths.ts
Update translations
[github/Chocobozzz/PeerTube.git] / server / lib / paths.ts
CommitLineData
d7a25329 1import { join } from 'path'
0305db28 2import { CONFIG } from '@server/initializers/config'
3545e72c 3import { DIRECTORIES, VIDEO_LIVE } from '@server/initializers/constants'
0305db28 4import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/types/models'
0628157f
C
5import { removeFragmentedMP4Ext } from '@shared/core-utils'
6import { buildUUID } from '@shared/extra-utils'
3545e72c 7import { isVideoInPrivateDirectory } from './video-privacy'
d7a25329
C
8
9// ################## Video file name ##################
10
83903cb6 11function generateWebTorrentVideoFilename (resolution: number, extname: string) {
764b1a14 12 return buildUUID() + '-' + resolution + extname
d7a25329
C
13}
14
83903cb6 15function generateHLSVideoFilename (resolution: number) {
764b1a14 16 return `${buildUUID()}-${resolution}-fragmented.mp4`
d7a25329
C
17}
18
0305db28 19// ################## Streaming playlist ##################
90a8bd30 20
3545e72c 21function getLiveDirectory (video: MVideo) {
0305db28 22 return getHLSDirectory(video)
90a8bd30
C
23}
24
3545e72c 25function getLiveReplayBaseDirectory (video: MVideo) {
4ec52d04
C
26 return join(getLiveDirectory(video), VIDEO_LIVE.REPLAY_DIRECTORY)
27}
28
3545e72c
C
29function getHLSDirectory (video: MVideo) {
30 if (isVideoInPrivateDirectory(video.privacy)) {
31 return join(DIRECTORIES.HLS_STREAMING_PLAYLIST.PRIVATE, video.uuid)
32 }
33
34 return join(DIRECTORIES.HLS_STREAMING_PLAYLIST.PUBLIC, video.uuid)
d7a25329
C
35}
36
0305db28 37function getHLSRedundancyDirectory (video: MVideoUUID) {
3545e72c 38 return join(DIRECTORIES.HLS_REDUNDANCY, video.uuid)
66fb2aa3
C
39}
40
764b1a14
C
41function getHlsResolutionPlaylistFilename (videoFilename: string) {
42 // Video file name already contain resolution
43 return removeFragmentedMP4Ext(videoFilename) + '.m3u8'
44}
45
46function generateHLSMasterPlaylistFilename (isLive = false) {
47 if (isLive) return 'master.m3u8'
48
49 return buildUUID() + '-master.m3u8'
50}
51
52function generateHlsSha256SegmentsFilename (isLive = false) {
53 if (isLive) return 'segments-sha256.json'
54
55 return buildUUID() + '-segments-sha256.json'
56}
57
d7a25329
C
58// ################## Torrents ##################
59
90a8bd30 60function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, resolution: number) {
d7a25329 61 const extension = '.torrent'
83903cb6 62 const uuid = buildUUID()
90a8bd30 63
d7a25329 64 if (isStreamingPlaylist(videoOrPlaylist)) {
90a8bd30 65 return `${uuid}-${resolution}-${videoOrPlaylist.getStringType()}${extension}`
d7a25329
C
66 }
67
90a8bd30
C
68 return uuid + '-' + resolution + extension
69}
70
0305db28 71function getFSTorrentFilePath (videoFile: MVideoFile) {
90a8bd30 72 return join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)
d7a25329
C
73}
74
d7a25329
C
75// ---------------------------------------------------------------------------
76
77export {
83903cb6
C
78 generateHLSVideoFilename,
79 generateWebTorrentVideoFilename,
80
90a8bd30 81 generateTorrentFileName,
0305db28 82 getFSTorrentFilePath,
66fb2aa3 83
90a8bd30 84 getHLSDirectory,
0305db28 85 getLiveDirectory,
4ec52d04 86 getLiveReplayBaseDirectory,
0305db28
JB
87 getHLSRedundancyDirectory,
88
764b1a14
C
89 generateHLSMasterPlaylistFilename,
90 generateHlsSha256SegmentsFilename,
0305db28 91 getHlsResolutionPlaylistFilename
d7a25329 92}