diff options
Diffstat (limited to 'server/lib/video-paths.ts')
-rw-r--r-- | server/lib/video-paths.ts | 116 |
1 files changed, 0 insertions, 116 deletions
diff --git a/server/lib/video-paths.ts b/server/lib/video-paths.ts deleted file mode 100644 index 1e4382108..000000000 --- a/server/lib/video-paths.ts +++ /dev/null | |||
@@ -1,116 +0,0 @@ | |||
1 | import { join } from 'path' | ||
2 | import { extractVideo } from '@server/helpers/video' | ||
3 | import { CONFIG } from '@server/initializers/config' | ||
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' | ||
6 | import { buildUUID } from '@server/helpers/uuid' | ||
7 | import { removeFragmentedMP4Ext } from '@shared/core-utils' | ||
8 | |||
9 | // ################## Video file name ################## | ||
10 | |||
11 | function generateWebTorrentVideoFilename (resolution: number, extname: string) { | ||
12 | return buildUUID() + '-' + resolution + extname | ||
13 | } | ||
14 | |||
15 | function generateHLSVideoFilename (resolution: number) { | ||
16 | return `${buildUUID()}-${resolution}-fragmented.mp4` | ||
17 | } | ||
18 | |||
19 | function getVideoFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile, isRedundancy = false) { | ||
20 | if (videoFile.isHLS()) { | ||
21 | const video = extractVideo(videoOrPlaylist) | ||
22 | |||
23 | return join(getHLSDirectory(video), videoFile.filename) | ||
24 | } | ||
25 | |||
26 | const baseDir = isRedundancy | ||
27 | ? CONFIG.STORAGE.REDUNDANCY_DIR | ||
28 | : CONFIG.STORAGE.VIDEOS_DIR | ||
29 | |||
30 | return join(baseDir, videoFile.filename) | ||
31 | } | ||
32 | |||
33 | // ################## Redundancy ################## | ||
34 | |||
35 | function generateHLSRedundancyUrl (video: MVideo, playlist: MStreamingPlaylist) { | ||
36 | // Base URL used by our HLS player | ||
37 | return WEBSERVER.URL + STATIC_PATHS.REDUNDANCY + playlist.getStringType() + '/' + video.uuid | ||
38 | } | ||
39 | |||
40 | function generateWebTorrentRedundancyUrl (file: MVideoFile) { | ||
41 | return WEBSERVER.URL + STATIC_PATHS.REDUNDANCY + file.filename | ||
42 | } | ||
43 | |||
44 | // ################## Streaming playlist ################## | ||
45 | |||
46 | function getHLSDirectory (video: MVideoUUID, isRedundancy = false) { | ||
47 | const baseDir = isRedundancy | ||
48 | ? HLS_REDUNDANCY_DIRECTORY | ||
49 | : HLS_STREAMING_PLAYLIST_DIRECTORY | ||
50 | |||
51 | return join(baseDir, video.uuid) | ||
52 | } | ||
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 | |||
71 | // ################## Torrents ################## | ||
72 | |||
73 | function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, resolution: number) { | ||
74 | const extension = '.torrent' | ||
75 | const uuid = buildUUID() | ||
76 | |||
77 | if (isStreamingPlaylist(videoOrPlaylist)) { | ||
78 | return `${uuid}-${resolution}-${videoOrPlaylist.getStringType()}${extension}` | ||
79 | } | ||
80 | |||
81 | return uuid + '-' + resolution + extension | ||
82 | } | ||
83 | |||
84 | function getTorrentFilePath (videoFile: MVideoFile) { | ||
85 | return join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename) | ||
86 | } | ||
87 | |||
88 | // ################## Meta data ################## | ||
89 | |||
90 | function getLocalVideoFileMetadataUrl (video: MVideoUUID, videoFile: MVideoFile) { | ||
91 | const path = '/api/v1/videos/' | ||
92 | |||
93 | return WEBSERVER.URL + path + video.uuid + '/metadata/' + videoFile.id | ||
94 | } | ||
95 | |||
96 | // --------------------------------------------------------------------------- | ||
97 | |||
98 | export { | ||
99 | generateHLSVideoFilename, | ||
100 | generateWebTorrentVideoFilename, | ||
101 | |||
102 | getVideoFilePath, | ||
103 | |||
104 | generateTorrentFileName, | ||
105 | getTorrentFilePath, | ||
106 | |||
107 | getHLSDirectory, | ||
108 | generateHLSMasterPlaylistFilename, | ||
109 | generateHlsSha256SegmentsFilename, | ||
110 | getHlsResolutionPlaylistFilename, | ||
111 | |||
112 | getLocalVideoFileMetadataUrl, | ||
113 | |||
114 | generateWebTorrentRedundancyUrl, | ||
115 | generateHLSRedundancyUrl | ||
116 | } | ||