diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-23 11:20:00 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-07-26 11:29:31 +0200 |
commit | 764b1a14fc494f2cfd7ea590d2f07b01df65c7ad (patch) | |
tree | 198ca5f242c63a205a05fa4cfd6d063277c541fd /server/lib/video-paths.ts | |
parent | 83903cb65d531a6b6b91715387493ba8312b264d (diff) | |
download | PeerTube-764b1a14fc494f2cfd7ea590d2f07b01df65c7ad.tar.gz PeerTube-764b1a14fc494f2cfd7ea590d2f07b01df65c7ad.tar.zst PeerTube-764b1a14fc494f2cfd7ea590d2f07b01df65c7ad.zip |
Use random names for VOD HLS playlists
Diffstat (limited to 'server/lib/video-paths.ts')
-rw-r--r-- | server/lib/video-paths.ts | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/server/lib/video-paths.ts b/server/lib/video-paths.ts index b7068190c..1e4382108 100644 --- a/server/lib/video-paths.ts +++ b/server/lib/video-paths.ts | |||
@@ -4,19 +4,16 @@ 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' | 6 | import { buildUUID } from '@server/helpers/uuid' |
7 | import { removeFragmentedMP4Ext } from '@shared/core-utils' | ||
7 | 8 | ||
8 | // ################## Video file name ################## | 9 | // ################## Video file name ################## |
9 | 10 | ||
10 | function generateWebTorrentVideoFilename (resolution: number, extname: string) { | 11 | function generateWebTorrentVideoFilename (resolution: number, extname: string) { |
11 | const uuid = buildUUID() | 12 | return buildUUID() + '-' + resolution + extname |
12 | |||
13 | return uuid + '-' + resolution + extname | ||
14 | } | 13 | } |
15 | 14 | ||
16 | function generateHLSVideoFilename (resolution: number) { | 15 | function generateHLSVideoFilename (resolution: number) { |
17 | const uuid = buildUUID() | 16 | return `${buildUUID()}-${resolution}-fragmented.mp4` |
18 | |||
19 | return `${uuid}-${resolution}-fragmented.mp4` | ||
20 | } | 17 | } |
21 | 18 | ||
22 | function getVideoFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile, isRedundancy = false) { | 19 | function getVideoFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile, isRedundancy = false) { |
@@ -54,6 +51,23 @@ function getHLSDirectory (video: MVideoUUID, isRedundancy = false) { | |||
54 | return join(baseDir, video.uuid) | 51 | return join(baseDir, video.uuid) |
55 | } | 52 | } |
56 | 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 | |||
57 | // ################## Torrents ################## | 71 | // ################## Torrents ################## |
58 | 72 | ||
59 | function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, resolution: number) { | 73 | function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, resolution: number) { |
@@ -91,6 +105,9 @@ export { | |||
91 | getTorrentFilePath, | 105 | getTorrentFilePath, |
92 | 106 | ||
93 | getHLSDirectory, | 107 | getHLSDirectory, |
108 | generateHLSMasterPlaylistFilename, | ||
109 | generateHlsSha256SegmentsFilename, | ||
110 | getHlsResolutionPlaylistFilename, | ||
94 | 111 | ||
95 | getLocalVideoFileMetadataUrl, | 112 | getLocalVideoFileMetadataUrl, |
96 | 113 | ||