]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/video-paths.ts
Fix peertube interface i18n
[github/Chocobozzz/PeerTube.git] / server / lib / video-paths.ts
CommitLineData
66fb2aa3 1import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/typings/models'
d7a25329
C
2import { extractVideo } from './videos'
3import { join } from 'path'
4import { CONFIG } from '@server/initializers/config'
66fb2aa3 5import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants'
d7a25329
C
6
7// ################## Video file name ##################
8
9function getVideoFilename (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
10 const video = extractVideo(videoOrPlaylist)
11
12 if (isStreamingPlaylist(videoOrPlaylist)) {
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) {
28 if (isStreamingPlaylist(videoOrPlaylist)) {
29 const video = extractVideo(videoOrPlaylist)
30 return join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid, getVideoFilename(videoOrPlaylist, videoFile))
31 }
32
33 const baseDir = isRedundancy ? CONFIG.STORAGE.REDUNDANCY_DIR : CONFIG.STORAGE.VIDEOS_DIR
34 return join(baseDir, getVideoFilename(videoOrPlaylist, videoFile))
35}
36
66fb2aa3
C
37// ################## Streaming playlist ##################
38
39function getHLSDirectory (video: MVideoUUID, isRedundancy = false) {
40 const baseDir = isRedundancy ? HLS_REDUNDANCY_DIRECTORY : HLS_STREAMING_PLAYLIST_DIRECTORY
41
42 return join(baseDir, video.uuid)
43}
44
d7a25329
C
45// ################## Torrents ##################
46
47function getTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
48 const video = extractVideo(videoOrPlaylist)
49 const extension = '.torrent'
50
51 if (isStreamingPlaylist(videoOrPlaylist)) {
52 return `${video.uuid}-${videoFile.resolution}-${videoOrPlaylist.getStringType()}${extension}`
53 }
54
55 return video.uuid + '-' + videoFile.resolution + extension
56}
57
58function getTorrentFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
59 return join(CONFIG.STORAGE.TORRENTS_DIR, getTorrentFileName(videoOrPlaylist, videoFile))
60}
61
62// ---------------------------------------------------------------------------
63
64export {
65 generateVideoStreamingPlaylistName,
66 generateWebTorrentVideoName,
67 getVideoFilename,
68 getVideoFilePath,
69
70 getTorrentFileName,
66fb2aa3
C
71 getTorrentFilePath,
72
73 getHLSDirectory
d7a25329 74}