aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-05-25 14:54:16 +0200
committerChocobozzz <me@florianbigard.com>2022-05-25 14:54:16 +0200
commit5333788c08ab6152303829d4624774b5d788ff40 (patch)
tree0377ba8504e798f71018a771742ac8d6bdbf6b51 /server/lib/job-queue
parentb34ee7fa5f6558bd6fb870756ace1cd12e40e94c (diff)
downloadPeerTube-5333788c08ab6152303829d4624774b5d788ff40.tar.gz
PeerTube-5333788c08ab6152303829d4624774b5d788ff40.tar.zst
PeerTube-5333788c08ab6152303829d4624774b5d788ff40.zip
Fix saving permanent live replay on quick restream
Diffstat (limited to 'server/lib/job-queue')
-rw-r--r--server/lib/job-queue/handlers/video-live-ending.ts51
1 files changed, 20 insertions, 31 deletions
diff --git a/server/lib/job-queue/handlers/video-live-ending.ts b/server/lib/job-queue/handlers/video-live-ending.ts
index 55fd09344..79aa547ba 100644
--- a/server/lib/job-queue/handlers/video-live-ending.ts
+++ b/server/lib/job-queue/handlers/video-live-ending.ts
@@ -1,10 +1,10 @@
1import { Job } from 'bull' 1import { Job } from 'bull'
2import { pathExists, readdir, remove } from 'fs-extra' 2import { readdir, remove } from 'fs-extra'
3import { join } from 'path' 3import { join } from 'path'
4import { ffprobePromise, getAudioStream, getVideoStreamDimensionsInfo, getVideoStreamDuration } from '@server/helpers/ffmpeg' 4import { ffprobePromise, getAudioStream, getVideoStreamDimensionsInfo, getVideoStreamDuration } from '@server/helpers/ffmpeg'
5import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' 5import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url'
6import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' 6import { federateVideoIfNeeded } from '@server/lib/activitypub/videos'
7import { cleanupLive, LiveSegmentShaStore } from '@server/lib/live' 7import { cleanupNormalLive, cleanupPermanentLive, cleanupTMPLiveFiles, LiveSegmentShaStore } from '@server/lib/live'
8import { 8import {
9 generateHLSMasterPlaylistFilename, 9 generateHLSMasterPlaylistFilename,
10 generateHlsSha256SegmentsFilename, 10 generateHlsSha256SegmentsFilename,
@@ -45,13 +45,13 @@ async function processVideoLiveEnding (job: Job) {
45 LiveSegmentShaStore.Instance.cleanupShaSegments(liveVideo.uuid) 45 LiveSegmentShaStore.Instance.cleanupShaSegments(liveVideo.uuid)
46 46
47 if (live.saveReplay !== true) { 47 if (live.saveReplay !== true) {
48 return cleanupLiveAndFederate({ liveVideo }) 48 return cleanupLiveAndFederate({ live, video: liveVideo })
49 } 49 }
50 50
51 if (live.permanentLive) { 51 if (live.permanentLive) {
52 await saveReplayToExternalVideo({ liveVideo, liveSession, publishedAt: payload.publishedAt, replayDirectory: payload.replayDirectory }) 52 await saveReplayToExternalVideo({ liveVideo, liveSession, publishedAt: payload.publishedAt, replayDirectory: payload.replayDirectory })
53 53
54 return cleanupLiveAndFederate({ liveVideo }) 54 return cleanupLiveAndFederate({ live, video: liveVideo })
55 } 55 }
56 56
57 return replaceLiveByReplay({ liveVideo, live, liveSession, replayDirectory: payload.replayDirectory }) 57 return replaceLiveByReplay({ liveVideo, live, liveSession, replayDirectory: payload.replayDirectory })
@@ -164,7 +164,11 @@ async function replaceLiveByReplay (options: {
164 164
165 await assignReplayFilesToVideo({ video: videoWithFiles, replayDirectory }) 165 await assignReplayFilesToVideo({ video: videoWithFiles, replayDirectory })
166 166
167 await remove(getLiveReplayBaseDirectory(videoWithFiles)) 167 if (live.permanentLive) { // Remove session replay
168 await remove(replayDirectory)
169 } else { // We won't stream again in this live, we can delete the base replay directory
170 await remove(getLiveReplayBaseDirectory(videoWithFiles))
171 }
168 172
169 // Regenerate the thumbnail & preview? 173 // Regenerate the thumbnail & preview?
170 if (videoWithFiles.getMiniature().automaticallyGenerated === true) { 174 if (videoWithFiles.getMiniature().automaticallyGenerated === true) {
@@ -227,34 +231,19 @@ async function assignReplayFilesToVideo (options: {
227} 231}
228 232
229async function cleanupLiveAndFederate (options: { 233async function cleanupLiveAndFederate (options: {
230 liveVideo: MVideo 234 live: MVideoLive
235 video: MVideo
231}) { 236}) {
232 const { liveVideo } = options 237 const { live, video } = options
233
234 const streamingPlaylist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(liveVideo.id)
235 await cleanupLive(liveVideo, streamingPlaylist)
236
237 const fullVideo = await VideoModel.loadAndPopulateAccountAndServerAndTags(liveVideo.id)
238 return federateVideoIfNeeded(fullVideo, false, undefined)
239}
240
241async function cleanupTMPLiveFiles (hlsDirectory: string) {
242 if (!await pathExists(hlsDirectory)) return
243 238
244 const files = await readdir(hlsDirectory) 239 const streamingPlaylist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id)
245 240
246 for (const filename of files) { 241 if (live.permanentLive) {
247 if ( 242 await cleanupPermanentLive(video, streamingPlaylist)
248 filename.endsWith('.ts') || 243 } else {
249 filename.endsWith('.m3u8') || 244 await cleanupNormalLive(video, streamingPlaylist)
250 filename.endsWith('.mpd') ||
251 filename.endsWith('.m4s') ||
252 filename.endsWith('.tmp')
253 ) {
254 const p = join(hlsDirectory, filename)
255
256 remove(p)
257 .catch(err => logger.error('Cannot remove %s.', p, { err }))
258 }
259 } 245 }
246
247 const fullVideo = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.id)
248 return federateVideoIfNeeded(fullVideo, false, undefined)
260} 249}