diff options
Diffstat (limited to 'server/lib/video-paths.ts')
-rw-r--r-- | server/lib/video-paths.ts | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/server/lib/video-paths.ts b/server/lib/video-paths.ts index 1708c479a..1e4382108 100644 --- a/server/lib/video-paths.ts +++ b/server/lib/video-paths.ts | |||
@@ -3,29 +3,17 @@ import { extractVideo } from '@server/helpers/video' | |||
3 | import { CONFIG } from '@server/initializers/config' | 3 | import { CONFIG } from '@server/initializers/config' |
4 | import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_PATHS, WEBSERVER } from '@server/initializers/constants' | 4 | import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_PATHS, WEBSERVER } from '@server/initializers/constants' |
5 | import { isStreamingPlaylist, MStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/types/models' | 5 | import { isStreamingPlaylist, MStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/types/models' |
6 | import { buildUUID } from '@server/helpers/uuid' | ||
7 | import { removeFragmentedMP4Ext } from '@shared/core-utils' | ||
6 | 8 | ||
7 | // ################## Video file name ################## | 9 | // ################## Video file name ################## |
8 | 10 | ||
9 | function generateVideoFilename (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, isHls: boolean, resolution: number, extname: string) { | 11 | function generateWebTorrentVideoFilename (resolution: number, extname: string) { |
10 | const video = extractVideo(videoOrPlaylist) | 12 | return buildUUID() + '-' + resolution + extname |
11 | |||
12 | // FIXME: use a generated uuid instead, that will break compatibility with PeerTube < 3.1 | ||
13 | // const uuid = uuidv4() | ||
14 | const uuid = video.uuid | ||
15 | |||
16 | if (isHls) { | ||
17 | return generateVideoStreamingPlaylistName(uuid, resolution) | ||
18 | } | ||
19 | |||
20 | return generateWebTorrentVideoName(uuid, resolution, extname) | ||
21 | } | 13 | } |
22 | 14 | ||
23 | function generateVideoStreamingPlaylistName (uuid: string, resolution: number) { | 15 | function generateHLSVideoFilename (resolution: number) { |
24 | return `${uuid}-${resolution}-fragmented.mp4` | 16 | return `${buildUUID()}-${resolution}-fragmented.mp4` |
25 | } | ||
26 | |||
27 | function generateWebTorrentVideoName (uuid: string, resolution: number, extname: string) { | ||
28 | return uuid + '-' + resolution + extname | ||
29 | } | 17 | } |
30 | 18 | ||
31 | function getVideoFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile, isRedundancy = false) { | 19 | function getVideoFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile, isRedundancy = false) { |
@@ -63,15 +51,28 @@ function getHLSDirectory (video: MVideoUUID, isRedundancy = false) { | |||
63 | return join(baseDir, video.uuid) | 51 | return join(baseDir, video.uuid) |
64 | } | 52 | } |
65 | 53 | ||
54 | function getHlsResolutionPlaylistFilename (videoFilename: string) { | ||
55 | // Video file name already contain resolution | ||
56 | return removeFragmentedMP4Ext(videoFilename) + '.m3u8' | ||
57 | } | ||
58 | |||
59 | function generateHLSMasterPlaylistFilename (isLive = false) { | ||
60 | if (isLive) return 'master.m3u8' | ||
61 | |||
62 | return buildUUID() + '-master.m3u8' | ||
63 | } | ||
64 | |||
65 | function generateHlsSha256SegmentsFilename (isLive = false) { | ||
66 | if (isLive) return 'segments-sha256.json' | ||
67 | |||
68 | return buildUUID() + '-segments-sha256.json' | ||
69 | } | ||
70 | |||
66 | // ################## Torrents ################## | 71 | // ################## Torrents ################## |
67 | 72 | ||
68 | function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, resolution: number) { | 73 | function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, resolution: number) { |
69 | const video = extractVideo(videoOrPlaylist) | ||
70 | const extension = '.torrent' | 74 | const extension = '.torrent' |
71 | 75 | const uuid = buildUUID() | |
72 | // FIXME: use a generated uuid instead, that will break compatibility with PeerTube < 3.1 | ||
73 | // const uuid = uuidv4() | ||
74 | const uuid = video.uuid | ||
75 | 76 | ||
76 | if (isStreamingPlaylist(videoOrPlaylist)) { | 77 | if (isStreamingPlaylist(videoOrPlaylist)) { |
77 | return `${uuid}-${resolution}-${videoOrPlaylist.getStringType()}${extension}` | 78 | return `${uuid}-${resolution}-${videoOrPlaylist.getStringType()}${extension}` |
@@ -95,15 +96,18 @@ function getLocalVideoFileMetadataUrl (video: MVideoUUID, videoFile: MVideoFile) | |||
95 | // --------------------------------------------------------------------------- | 96 | // --------------------------------------------------------------------------- |
96 | 97 | ||
97 | export { | 98 | export { |
98 | generateVideoStreamingPlaylistName, | 99 | generateHLSVideoFilename, |
99 | generateWebTorrentVideoName, | 100 | generateWebTorrentVideoFilename, |
100 | generateVideoFilename, | 101 | |
101 | getVideoFilePath, | 102 | getVideoFilePath, |
102 | 103 | ||
103 | generateTorrentFileName, | 104 | generateTorrentFileName, |
104 | getTorrentFilePath, | 105 | getTorrentFilePath, |
105 | 106 | ||
106 | getHLSDirectory, | 107 | getHLSDirectory, |
108 | generateHLSMasterPlaylistFilename, | ||
109 | generateHlsSha256SegmentsFilename, | ||
110 | getHlsResolutionPlaylistFilename, | ||
107 | 111 | ||
108 | getLocalVideoFileMetadataUrl, | 112 | getLocalVideoFileMetadataUrl, |
109 | 113 | ||