diff options
author | Chocobozzz <me@florianbigard.com> | 2019-11-15 15:06:03 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-11-25 10:59:43 +0100 |
commit | d7a25329f9e607894d29ab342b9cb66638b56dc0 (patch) | |
tree | 6cd6bc4f2689f78944238b313c93427423a932ac /server/lib/video-paths.ts | |
parent | 14981d7331da3f63fe6cfaf020ccb7c910006eaf (diff) | |
download | PeerTube-d7a25329f9e607894d29ab342b9cb66638b56dc0.tar.gz PeerTube-d7a25329f9e607894d29ab342b9cb66638b56dc0.tar.zst PeerTube-d7a25329f9e607894d29ab342b9cb66638b56dc0.zip |
Add ability to disable webtorrent
In favour of HLS
Diffstat (limited to 'server/lib/video-paths.ts')
-rw-r--r-- | server/lib/video-paths.ts | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/server/lib/video-paths.ts b/server/lib/video-paths.ts new file mode 100644 index 000000000..63011cdb2 --- /dev/null +++ b/server/lib/video-paths.ts | |||
@@ -0,0 +1,64 @@ | |||
1 | import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile } from '@server/typings/models' | ||
2 | import { extractVideo } from './videos' | ||
3 | import { join } from 'path' | ||
4 | import { CONFIG } from '@server/initializers/config' | ||
5 | import { HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants' | ||
6 | |||
7 | // ################## Video file name ################## | ||
8 | |||
9 | function 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 | |||
19 | function generateVideoStreamingPlaylistName (uuid: string, resolution: number) { | ||
20 | return `${uuid}-${resolution}-fragmented.mp4` | ||
21 | } | ||
22 | |||
23 | function generateWebTorrentVideoName (uuid: string, resolution: number, extname: string) { | ||
24 | return uuid + '-' + resolution + extname | ||
25 | } | ||
26 | |||
27 | function 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 | |||
37 | // ################## Torrents ################## | ||
38 | |||
39 | function getTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { | ||
40 | const video = extractVideo(videoOrPlaylist) | ||
41 | const extension = '.torrent' | ||
42 | |||
43 | if (isStreamingPlaylist(videoOrPlaylist)) { | ||
44 | return `${video.uuid}-${videoFile.resolution}-${videoOrPlaylist.getStringType()}${extension}` | ||
45 | } | ||
46 | |||
47 | return video.uuid + '-' + videoFile.resolution + extension | ||
48 | } | ||
49 | |||
50 | function getTorrentFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { | ||
51 | return join(CONFIG.STORAGE.TORRENTS_DIR, getTorrentFileName(videoOrPlaylist, videoFile)) | ||
52 | } | ||
53 | |||
54 | // --------------------------------------------------------------------------- | ||
55 | |||
56 | export { | ||
57 | generateVideoStreamingPlaylistName, | ||
58 | generateWebTorrentVideoName, | ||
59 | getVideoFilename, | ||
60 | getVideoFilePath, | ||
61 | |||
62 | getTorrentFileName, | ||
63 | getTorrentFilePath | ||
64 | } | ||