aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/hls.ts6
-rw-r--r--server/lib/job-queue/handlers/video-file-import.ts4
-rw-r--r--server/lib/job-queue/handlers/video-import.ts4
-rw-r--r--server/lib/transcoding/video-transcoding.ts12
-rw-r--r--server/lib/video-paths.ts35
5 files changed, 25 insertions, 36 deletions
diff --git a/server/lib/hls.ts b/server/lib/hls.ts
index 05be403f3..212bd095b 100644
--- a/server/lib/hls.ts
+++ b/server/lib/hls.ts
@@ -36,8 +36,10 @@ async function updateMasterHLSPlaylist (video: MVideoWithFile) {
36 const streamingPlaylist = video.getHLSPlaylist() 36 const streamingPlaylist = video.getHLSPlaylist()
37 37
38 for (const file of streamingPlaylist.VideoFiles) { 38 for (const file of streamingPlaylist.VideoFiles) {
39 const playlistFilename = VideoStreamingPlaylistModel.getHlsPlaylistFilename(file.resolution)
40
39 // If we did not generated a playlist for this resolution, skip 41 // If we did not generated a playlist for this resolution, skip
40 const filePlaylistPath = join(directory, VideoStreamingPlaylistModel.getHlsPlaylistFilename(file.resolution)) 42 const filePlaylistPath = join(directory, playlistFilename)
41 if (await pathExists(filePlaylistPath) === false) continue 43 if (await pathExists(filePlaylistPath) === false) continue
42 44
43 const videoFilePath = getVideoFilePath(streamingPlaylist, file) 45 const videoFilePath = getVideoFilePath(streamingPlaylist, file)
@@ -58,7 +60,7 @@ async function updateMasterHLSPlaylist (video: MVideoWithFile) {
58 line += `,CODECS="${codecs.filter(c => !!c).join(',')}"` 60 line += `,CODECS="${codecs.filter(c => !!c).join(',')}"`
59 61
60 masterPlaylists.push(line) 62 masterPlaylists.push(line)
61 masterPlaylists.push(VideoStreamingPlaylistModel.getHlsPlaylistFilename(file.resolution)) 63 masterPlaylists.push(playlistFilename)
62 } 64 }
63 65
64 await writeFile(masterPlaylistPath, masterPlaylists.join('\n') + '\n') 66 await writeFile(masterPlaylistPath, masterPlaylists.join('\n') + '\n')
diff --git a/server/lib/job-queue/handlers/video-file-import.ts b/server/lib/job-queue/handlers/video-file-import.ts
index 187cb652e..1783f206a 100644
--- a/server/lib/job-queue/handlers/video-file-import.ts
+++ b/server/lib/job-queue/handlers/video-file-import.ts
@@ -2,7 +2,7 @@ import * as Bull from 'bull'
2import { copy, stat } from 'fs-extra' 2import { copy, stat } from 'fs-extra'
3import { getLowercaseExtension } from '@server/helpers/core-utils' 3import { getLowercaseExtension } from '@server/helpers/core-utils'
4import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' 4import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
5import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths' 5import { generateWebTorrentVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
6import { UserModel } from '@server/models/user/user' 6import { UserModel } from '@server/models/user/user'
7import { MVideoFullLight } from '@server/types/models' 7import { MVideoFullLight } from '@server/types/models'
8import { VideoFileImportPayload } from '@shared/models' 8import { VideoFileImportPayload } from '@shared/models'
@@ -72,7 +72,7 @@ async function updateVideoFile (video: MVideoFullLight, inputFilePath: string) {
72 const newVideoFile = new VideoFileModel({ 72 const newVideoFile = new VideoFileModel({
73 resolution: videoFileResolution, 73 resolution: videoFileResolution,
74 extname: fileExt, 74 extname: fileExt,
75 filename: generateVideoFilename(video, false, videoFileResolution, fileExt), 75 filename: generateWebTorrentVideoFilename(videoFileResolution, fileExt),
76 size, 76 size,
77 fps, 77 fps,
78 videoId: video.id 78 videoId: video.id
diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts
index 55498003d..6e425d09c 100644
--- a/server/lib/job-queue/handlers/video-import.ts
+++ b/server/lib/job-queue/handlers/video-import.ts
@@ -8,7 +8,7 @@ import { Hooks } from '@server/lib/plugins/hooks'
8import { ServerConfigManager } from '@server/lib/server-config-manager' 8import { ServerConfigManager } from '@server/lib/server-config-manager'
9import { isAbleToUploadVideo } from '@server/lib/user' 9import { isAbleToUploadVideo } from '@server/lib/user'
10import { addOptimizeOrMergeAudioJob } from '@server/lib/video' 10import { addOptimizeOrMergeAudioJob } from '@server/lib/video'
11import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths' 11import { generateWebTorrentVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
12import { ThumbnailModel } from '@server/models/video/thumbnail' 12import { ThumbnailModel } from '@server/models/video/thumbnail'
13import { MVideoImportDefault, MVideoImportDefaultFiles, MVideoImportVideo } from '@server/types/models/video/video-import' 13import { MVideoImportDefault, MVideoImportDefaultFiles, MVideoImportVideo } from '@server/types/models/video/video-import'
14import { 14import {
@@ -124,7 +124,7 @@ async function processFile (downloader: () => Promise<string>, videoImport: MVid
124 extname: fileExt, 124 extname: fileExt,
125 resolution: videoFileResolution, 125 resolution: videoFileResolution,
126 size: stats.size, 126 size: stats.size,
127 filename: generateVideoFilename(videoImport.Video, false, videoFileResolution, fileExt), 127 filename: generateWebTorrentVideoFilename(videoFileResolution, fileExt),
128 fps, 128 fps,
129 videoId: videoImport.videoId 129 videoId: videoImport.videoId
130 } 130 }
diff --git a/server/lib/transcoding/video-transcoding.ts b/server/lib/transcoding/video-transcoding.ts
index 1ad63baf3..d70f7f474 100644
--- a/server/lib/transcoding/video-transcoding.ts
+++ b/server/lib/transcoding/video-transcoding.ts
@@ -14,7 +14,7 @@ import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION, WEBSER
14import { VideoFileModel } from '../../models/video/video-file' 14import { VideoFileModel } from '../../models/video/video-file'
15import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-playlist' 15import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-playlist'
16import { updateMasterHLSPlaylist, updateSha256VODSegments } from '../hls' 16import { updateMasterHLSPlaylist, updateSha256VODSegments } from '../hls'
17import { generateVideoFilename, generateVideoStreamingPlaylistName, getVideoFilePath } from '../video-paths' 17import { generateHLSVideoFilename, generateWebTorrentVideoFilename, getVideoFilePath } from '../video-paths'
18import { VideoTranscodingProfilesManager } from './video-transcoding-profiles' 18import { VideoTranscodingProfilesManager } from './video-transcoding-profiles'
19 19
20/** 20/**
@@ -60,7 +60,7 @@ async function optimizeOriginalVideofile (video: MVideoFullLight, inputVideoFile
60 60
61 // Important to do this before getVideoFilename() to take in account the new filename 61 // Important to do this before getVideoFilename() to take in account the new filename
62 inputVideoFile.extname = newExtname 62 inputVideoFile.extname = newExtname
63 inputVideoFile.filename = generateVideoFilename(video, false, resolution, newExtname) 63 inputVideoFile.filename = generateWebTorrentVideoFilename(resolution, newExtname)
64 64
65 const videoOutputPath = getVideoFilePath(video, inputVideoFile) 65 const videoOutputPath = getVideoFilePath(video, inputVideoFile)
66 66
@@ -86,7 +86,7 @@ async function transcodeNewWebTorrentResolution (video: MVideoFullLight, resolut
86 const newVideoFile = new VideoFileModel({ 86 const newVideoFile = new VideoFileModel({
87 resolution, 87 resolution,
88 extname, 88 extname,
89 filename: generateVideoFilename(video, false, resolution, extname), 89 filename: generateWebTorrentVideoFilename(resolution, extname),
90 size: 0, 90 size: 0,
91 videoId: video.id 91 videoId: video.id
92 }) 92 })
@@ -169,7 +169,7 @@ async function mergeAudioVideofile (video: MVideoFullLight, resolution: VideoRes
169 169
170 // Important to do this before getVideoFilename() to take in account the new file extension 170 // Important to do this before getVideoFilename() to take in account the new file extension
171 inputVideoFile.extname = newExtname 171 inputVideoFile.extname = newExtname
172 inputVideoFile.filename = generateVideoFilename(video, false, inputVideoFile.resolution, newExtname) 172 inputVideoFile.filename = generateWebTorrentVideoFilename(inputVideoFile.resolution, newExtname)
173 173
174 const videoOutputPath = getVideoFilePath(video, inputVideoFile) 174 const videoOutputPath = getVideoFilePath(video, inputVideoFile)
175 // ffmpeg generated a new video file, so update the video duration 175 // ffmpeg generated a new video file, so update the video duration
@@ -271,7 +271,7 @@ async function generateHlsPlaylistCommon (options: {
271 const videoTranscodedBasePath = join(transcodeDirectory, type) 271 const videoTranscodedBasePath = join(transcodeDirectory, type)
272 await ensureDir(videoTranscodedBasePath) 272 await ensureDir(videoTranscodedBasePath)
273 273
274 const videoFilename = generateVideoStreamingPlaylistName(video.uuid, resolution) 274 const videoFilename = generateHLSVideoFilename(resolution)
275 const playlistFilename = VideoStreamingPlaylistModel.getHlsPlaylistFilename(resolution) 275 const playlistFilename = VideoStreamingPlaylistModel.getHlsPlaylistFilename(resolution)
276 const playlistFileTranscodePath = join(videoTranscodedBasePath, playlistFilename) 276 const playlistFileTranscodePath = join(videoTranscodedBasePath, playlistFilename)
277 277
@@ -319,7 +319,7 @@ async function generateHlsPlaylistCommon (options: {
319 resolution, 319 resolution,
320 extname, 320 extname,
321 size: 0, 321 size: 0,
322 filename: generateVideoFilename(video, true, resolution, extname), 322 filename: videoFilename,
323 fps: -1, 323 fps: -1,
324 videoStreamingPlaylistId: videoStreamingPlaylist.id 324 videoStreamingPlaylistId: videoStreamingPlaylist.id
325 }) 325 })
diff --git a/server/lib/video-paths.ts b/server/lib/video-paths.ts
index 1708c479a..b7068190c 100644
--- a/server/lib/video-paths.ts
+++ b/server/lib/video-paths.ts
@@ -3,29 +3,20 @@ import { extractVideo } from '@server/helpers/video'
3import { CONFIG } from '@server/initializers/config' 3import { CONFIG } from '@server/initializers/config'
4import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_PATHS, WEBSERVER } from '@server/initializers/constants' 4import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_PATHS, WEBSERVER } from '@server/initializers/constants'
5import { isStreamingPlaylist, MStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/types/models' 5import { isStreamingPlaylist, MStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/types/models'
6import { buildUUID } from '@server/helpers/uuid'
6 7
7// ################## Video file name ################## 8// ################## Video file name ##################
8 9
9function generateVideoFilename (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, isHls: boolean, resolution: number, extname: string) { 10function generateWebTorrentVideoFilename (resolution: number, extname: string) {
10 const video = extractVideo(videoOrPlaylist) 11 const uuid = buildUUID()
11 12
12 // FIXME: use a generated uuid instead, that will break compatibility with PeerTube < 3.1 13 return uuid + '-' + resolution + extname
13 // const uuid = uuidv4()
14 const uuid = video.uuid
15
16 if (isHls) {
17 return generateVideoStreamingPlaylistName(uuid, resolution)
18 }
19
20 return generateWebTorrentVideoName(uuid, resolution, extname)
21} 14}
22 15
23function generateVideoStreamingPlaylistName (uuid: string, resolution: number) { 16function generateHLSVideoFilename (resolution: number) {
24 return `${uuid}-${resolution}-fragmented.mp4` 17 const uuid = buildUUID()
25}
26 18
27function generateWebTorrentVideoName (uuid: string, resolution: number, extname: string) { 19 return `${uuid}-${resolution}-fragmented.mp4`
28 return uuid + '-' + resolution + extname
29} 20}
30 21
31function getVideoFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile, isRedundancy = false) { 22function getVideoFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile, isRedundancy = false) {
@@ -66,12 +57,8 @@ function getHLSDirectory (video: MVideoUUID, isRedundancy = false) {
66// ################## Torrents ################## 57// ################## Torrents ##################
67 58
68function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, resolution: number) { 59function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, resolution: number) {
69 const video = extractVideo(videoOrPlaylist)
70 const extension = '.torrent' 60 const extension = '.torrent'
71 61 const uuid = buildUUID()
72 // FIXME: use a generated uuid instead, that will break compatibility with PeerTube < 3.1
73 // const uuid = uuidv4()
74 const uuid = video.uuid
75 62
76 if (isStreamingPlaylist(videoOrPlaylist)) { 63 if (isStreamingPlaylist(videoOrPlaylist)) {
77 return `${uuid}-${resolution}-${videoOrPlaylist.getStringType()}${extension}` 64 return `${uuid}-${resolution}-${videoOrPlaylist.getStringType()}${extension}`
@@ -95,9 +82,9 @@ function getLocalVideoFileMetadataUrl (video: MVideoUUID, videoFile: MVideoFile)
95// --------------------------------------------------------------------------- 82// ---------------------------------------------------------------------------
96 83
97export { 84export {
98 generateVideoStreamingPlaylistName, 85 generateHLSVideoFilename,
99 generateWebTorrentVideoName, 86 generateWebTorrentVideoFilename,
100 generateVideoFilename, 87
101 getVideoFilePath, 88 getVideoFilePath,
102 89
103 generateTorrentFileName, 90 generateTorrentFileName,