From d7a25329f9e607894d29ab342b9cb66638b56dc0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 15 Nov 2019 15:06:03 +0100 Subject: Add ability to disable webtorrent In favour of HLS --- server/lib/video-paths.ts | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 server/lib/video-paths.ts (limited to 'server/lib/video-paths.ts') 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 @@ +import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile } from '@server/typings/models' +import { extractVideo } from './videos' +import { join } from 'path' +import { CONFIG } from '@server/initializers/config' +import { HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants' + +// ################## Video file name ################## + +function getVideoFilename (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { + const video = extractVideo(videoOrPlaylist) + + if (isStreamingPlaylist(videoOrPlaylist)) { + return generateVideoStreamingPlaylistName(video.uuid, videoFile.resolution) + } + + return generateWebTorrentVideoName(video.uuid, videoFile.resolution, videoFile.extname) +} + +function generateVideoStreamingPlaylistName (uuid: string, resolution: number) { + return `${uuid}-${resolution}-fragmented.mp4` +} + +function generateWebTorrentVideoName (uuid: string, resolution: number, extname: string) { + return uuid + '-' + resolution + extname +} + +function getVideoFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile, isRedundancy = false) { + if (isStreamingPlaylist(videoOrPlaylist)) { + const video = extractVideo(videoOrPlaylist) + return join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid, getVideoFilename(videoOrPlaylist, videoFile)) + } + + const baseDir = isRedundancy ? CONFIG.STORAGE.REDUNDANCY_DIR : CONFIG.STORAGE.VIDEOS_DIR + return join(baseDir, getVideoFilename(videoOrPlaylist, videoFile)) +} + +// ################## Torrents ################## + +function getTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { + const video = extractVideo(videoOrPlaylist) + const extension = '.torrent' + + if (isStreamingPlaylist(videoOrPlaylist)) { + return `${video.uuid}-${videoFile.resolution}-${videoOrPlaylist.getStringType()}${extension}` + } + + return video.uuid + '-' + videoFile.resolution + extension +} + +function getTorrentFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { + return join(CONFIG.STORAGE.TORRENTS_DIR, getTorrentFileName(videoOrPlaylist, videoFile)) +} + +// --------------------------------------------------------------------------- + +export { + generateVideoStreamingPlaylistName, + generateWebTorrentVideoName, + getVideoFilename, + getVideoFilePath, + + getTorrentFileName, + getTorrentFilePath +} -- cgit v1.2.3