diff options
author | Chocobozzz <me@florianbigard.com> | 2022-05-25 15:22:28 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-05-25 15:22:28 +0200 |
commit | ab623c0e0b4815bd69a94887241a69aaa857ed26 (patch) | |
tree | 9140675d0aa501d9ddbbcf14bbdb5c28b6ef0712 /server/lib/job-queue/handlers/video-live-ending.ts | |
parent | c501cdef27e6769b7d2a13ac7b6deeb2e61eee46 (diff) | |
parent | c8fdfab0e36cc7324c61710009bf334e836485d9 (diff) | |
download | PeerTube-ab623c0e0b4815bd69a94887241a69aaa857ed26.tar.gz PeerTube-ab623c0e0b4815bd69a94887241a69aaa857ed26.tar.zst PeerTube-ab623c0e0b4815bd69a94887241a69aaa857ed26.zip |
Merge branch 'release/4.2.0' into develop
Diffstat (limited to 'server/lib/job-queue/handlers/video-live-ending.ts')
-rw-r--r-- | server/lib/job-queue/handlers/video-live-ending.ts | 53 |
1 files changed, 23 insertions, 30 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..7607267f8 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 @@ | |||
1 | import { Job } from 'bull' | 1 | import { Job } from 'bull' |
2 | import { pathExists, readdir, remove } from 'fs-extra' | 2 | import { readdir, remove } from 'fs-extra' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { ffprobePromise, getAudioStream, getVideoStreamDimensionsInfo, getVideoStreamDuration } from '@server/helpers/ffmpeg' | 4 | import { ffprobePromise, getAudioStream, getVideoStreamDimensionsInfo, getVideoStreamDuration } from '@server/helpers/ffmpeg' |
5 | import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' | 5 | import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' |
6 | import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' | 6 | import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' |
7 | import { cleanupLive, LiveSegmentShaStore } from '@server/lib/live' | 7 | import { cleanupNormalLive, cleanupPermanentLive, cleanupTMPLiveFiles, LiveSegmentShaStore } from '@server/lib/live' |
8 | import { | 8 | import { |
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,23 @@ async function assignReplayFilesToVideo (options: { | |||
227 | } | 231 | } |
228 | 232 | ||
229 | async function cleanupLiveAndFederate (options: { | 233 | async 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 | 238 | ||
237 | const fullVideo = await VideoModel.loadAndPopulateAccountAndServerAndTags(liveVideo.id) | 239 | const streamingPlaylist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id) |
238 | return federateVideoIfNeeded(fullVideo, false, undefined) | ||
239 | } | ||
240 | 240 | ||
241 | async function cleanupTMPLiveFiles (hlsDirectory: string) { | 241 | if (live.permanentLive) { |
242 | if (!await pathExists(hlsDirectory)) return | 242 | await cleanupPermanentLive(video, streamingPlaylist) |
243 | 243 | } else { | |
244 | const files = await readdir(hlsDirectory) | 244 | await cleanupNormalLive(video, streamingPlaylist) |
245 | 245 | } | |
246 | for (const filename of files) { | ||
247 | if ( | ||
248 | filename.endsWith('.ts') || | ||
249 | filename.endsWith('.m3u8') || | ||
250 | filename.endsWith('.mpd') || | ||
251 | filename.endsWith('.m4s') || | ||
252 | filename.endsWith('.tmp') | ||
253 | ) { | ||
254 | const p = join(hlsDirectory, filename) | ||
255 | 246 | ||
256 | remove(p) | 247 | try { |
257 | .catch(err => logger.error('Cannot remove %s.', p, { err })) | 248 | const fullVideo = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.id) |
258 | } | 249 | return federateVideoIfNeeded(fullVideo, false, undefined) |
250 | } catch (err) { | ||
251 | logger.warn('Cannot federate live after cleanup', { videoId: video.id, err }) | ||
259 | } | 252 | } |
260 | } | 253 | } |