aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers/video-live-ending.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-03 15:33:30 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-11-09 15:33:04 +0100
commit97969c4edf51b37eee691adba43368bb0fbb729b (patch)
treec1089f898fb936d75651630afcf406995eeb9fba /server/lib/job-queue/handlers/video-live-ending.ts
parentaf4ae64f6faf38f8179f2e07d3cd4ad60006be92 (diff)
downloadPeerTube-97969c4edf51b37eee691adba43368bb0fbb729b.tar.gz
PeerTube-97969c4edf51b37eee691adba43368bb0fbb729b.tar.zst
PeerTube-97969c4edf51b37eee691adba43368bb0fbb729b.zip
Add check constraints live tests
Diffstat (limited to 'server/lib/job-queue/handlers/video-live-ending.ts')
-rw-r--r--server/lib/job-queue/handlers/video-live-ending.ts19
1 files changed, 14 insertions, 5 deletions
diff --git a/server/lib/job-queue/handlers/video-live-ending.ts b/server/lib/job-queue/handlers/video-live-ending.ts
index 32eeff4d1..1e964726e 100644
--- a/server/lib/job-queue/handlers/video-live-ending.ts
+++ b/server/lib/job-queue/handlers/video-live-ending.ts
@@ -8,9 +8,10 @@ import { generateHlsPlaylist } from '@server/lib/video-transcoding'
8import { VideoModel } from '@server/models/video/video' 8import { VideoModel } from '@server/models/video/video'
9import { VideoLiveModel } from '@server/models/video/video-live' 9import { VideoLiveModel } from '@server/models/video/video-live'
10import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' 10import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist'
11import { MStreamingPlaylist, MVideo, MVideoLive } from '@server/types/models' 11import { MStreamingPlaylist, MVideo, MVideoLive, MVideoWithFile } from '@server/types/models'
12import { VideoLiveEndingPayload, VideoState } from '@shared/models' 12import { VideoLiveEndingPayload, VideoState } from '@shared/models'
13import { logger } from '../../../helpers/logger' 13import { logger } from '../../../helpers/logger'
14import { VideoFileModel } from '@server/models/video/video-file'
14 15
15async function processVideoLiveEnding (job: Bull.Job) { 16async function processVideoLiveEnding (job: Bull.Job) {
16 const payload = job.data as VideoLiveEndingPayload 17 const payload = job.data as VideoLiveEndingPayload
@@ -60,6 +61,10 @@ async function saveLive (video: MVideo, live: MVideoLive) {
60 const segmentFiles = files.filter(f => f.startsWith(shouldStartWith) && f.endsWith('.ts')) 61 const segmentFiles = files.filter(f => f.startsWith(shouldStartWith) && f.endsWith('.ts'))
61 await hlsPlaylistToFragmentedMP4(hlsDirectory, segmentFiles, mp4TmpName) 62 await hlsPlaylistToFragmentedMP4(hlsDirectory, segmentFiles, mp4TmpName)
62 63
64 for (const file of segmentFiles) {
65 await remove(join(hlsDirectory, file))
66 }
67
63 if (!duration) { 68 if (!duration) {
64 duration = await getDurationFromVideoFile(mp4TmpName) 69 duration = await getDurationFromVideoFile(mp4TmpName)
65 } 70 }
@@ -77,8 +82,13 @@ async function saveLive (video: MVideo, live: MVideoLive) {
77 82
78 await video.save() 83 await video.save()
79 84
85 // Remove old HLS playlist video files
80 const videoWithFiles = await VideoModel.loadWithFiles(video.id) 86 const videoWithFiles = await VideoModel.loadWithFiles(video.id)
81 87
88 const hlsPlaylist = videoWithFiles.getHLSPlaylist()
89 await VideoFileModel.removeHLSFilesOfVideoId(hlsPlaylist.id)
90 hlsPlaylist.VideoFiles = []
91
82 for (const resolution of resolutions) { 92 for (const resolution of resolutions) {
83 const videoInputPath = buildMP4TmpName(resolution) 93 const videoInputPath = buildMP4TmpName(resolution)
84 const { isPortraitMode } = await getVideoFileResolution(videoInputPath) 94 const { isPortraitMode } = await getVideoFileResolution(videoInputPath)
@@ -90,12 +100,11 @@ async function saveLive (video: MVideo, live: MVideoLive) {
90 copyCodecs: true, 100 copyCodecs: true,
91 isPortraitMode 101 isPortraitMode
92 }) 102 })
93 }
94 103
95 video.state = VideoState.PUBLISHED 104 await remove(join(hlsDirectory, videoInputPath))
96 await video.save() 105 }
97 106
98 await publishAndFederateIfNeeded(video) 107 await publishAndFederateIfNeeded(video, true)
99} 108}
100 109
101async function cleanupLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) { 110async function cleanupLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) {