]>
Commit | Line | Data |
---|---|---|
1 | import { join } from 'path' | |
2 | import { CONFIG } from '@server/initializers/config' | |
3 | import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants' | |
4 | import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/types/models' | |
5 | import { buildUUID, removeFragmentedMP4Ext } from '@shared/core-utils' | |
6 | ||
7 | // ################## Video file name ################## | |
8 | ||
9 | function generateWebTorrentVideoFilename (resolution: number, extname: string) { | |
10 | return buildUUID() + '-' + resolution + extname | |
11 | } | |
12 | ||
13 | function generateHLSVideoFilename (resolution: number) { | |
14 | return `${buildUUID()}-${resolution}-fragmented.mp4` | |
15 | } | |
16 | ||
17 | // ################## Streaming playlist ################## | |
18 | ||
19 | function getLiveDirectory (video: MVideoUUID) { | |
20 | return getHLSDirectory(video) | |
21 | } | |
22 | ||
23 | function getHLSDirectory (video: MVideoUUID) { | |
24 | return join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid) | |
25 | } | |
26 | ||
27 | function getHLSRedundancyDirectory (video: MVideoUUID) { | |
28 | return join(HLS_REDUNDANCY_DIRECTORY, video.uuid) | |
29 | } | |
30 | ||
31 | function getHlsResolutionPlaylistFilename (videoFilename: string) { | |
32 | // Video file name already contain resolution | |
33 | return removeFragmentedMP4Ext(videoFilename) + '.m3u8' | |
34 | } | |
35 | ||
36 | function generateHLSMasterPlaylistFilename (isLive = false) { | |
37 | if (isLive) return 'master.m3u8' | |
38 | ||
39 | return buildUUID() + '-master.m3u8' | |
40 | } | |
41 | ||
42 | function generateHlsSha256SegmentsFilename (isLive = false) { | |
43 | if (isLive) return 'segments-sha256.json' | |
44 | ||
45 | return buildUUID() + '-segments-sha256.json' | |
46 | } | |
47 | ||
48 | // ################## Torrents ################## | |
49 | ||
50 | function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, resolution: number) { | |
51 | const extension = '.torrent' | |
52 | const uuid = buildUUID() | |
53 | ||
54 | if (isStreamingPlaylist(videoOrPlaylist)) { | |
55 | return `${uuid}-${resolution}-${videoOrPlaylist.getStringType()}${extension}` | |
56 | } | |
57 | ||
58 | return uuid + '-' + resolution + extension | |
59 | } | |
60 | ||
61 | function getFSTorrentFilePath (videoFile: MVideoFile) { | |
62 | return join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename) | |
63 | } | |
64 | ||
65 | // --------------------------------------------------------------------------- | |
66 | ||
67 | export { | |
68 | generateHLSVideoFilename, | |
69 | generateWebTorrentVideoFilename, | |
70 | ||
71 | generateTorrentFileName, | |
72 | getFSTorrentFilePath, | |
73 | ||
74 | getHLSDirectory, | |
75 | getLiveDirectory, | |
76 | getHLSRedundancyDirectory, | |
77 | ||
78 | generateHLSMasterPlaylistFilename, | |
79 | generateHlsSha256SegmentsFilename, | |
80 | getHlsResolutionPlaylistFilename | |
81 | } |