diff options
author | Chocobozzz <me@florianbigard.com> | 2022-05-25 14:54:16 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-05-25 14:54:16 +0200 |
commit | 5333788c08ab6152303829d4624774b5d788ff40 (patch) | |
tree | 0377ba8504e798f71018a771742ac8d6bdbf6b51 /server/lib/live | |
parent | b34ee7fa5f6558bd6fb870756ace1cd12e40e94c (diff) | |
download | PeerTube-5333788c08ab6152303829d4624774b5d788ff40.tar.gz PeerTube-5333788c08ab6152303829d4624774b5d788ff40.tar.zst PeerTube-5333788c08ab6152303829d4624774b5d788ff40.zip |
Fix saving permanent live replay on quick restream
Diffstat (limited to 'server/lib/live')
-rw-r--r-- | server/lib/live/live-manager.ts | 6 | ||||
-rw-r--r-- | server/lib/live/live-utils.ts | 40 |
2 files changed, 40 insertions, 6 deletions
diff --git a/server/lib/live/live-manager.ts b/server/lib/live/live-manager.ts index e04ae9fef..0f14a6851 100644 --- a/server/lib/live/live-manager.ts +++ b/server/lib/live/live-manager.ts | |||
@@ -28,7 +28,7 @@ import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, g | |||
28 | import { PeerTubeSocket } from '../peertube-socket' | 28 | import { PeerTubeSocket } from '../peertube-socket' |
29 | import { LiveQuotaStore } from './live-quota-store' | 29 | import { LiveQuotaStore } from './live-quota-store' |
30 | import { LiveSegmentShaStore } from './live-segment-sha-store' | 30 | import { LiveSegmentShaStore } from './live-segment-sha-store' |
31 | import { cleanupLive } from './live-utils' | 31 | import { cleanupPermanentLive } from './live-utils' |
32 | import { MuxingSession } from './shared' | 32 | import { MuxingSession } from './shared' |
33 | 33 | ||
34 | const NodeRtmpSession = require('node-media-server/src/node_rtmp_session') | 34 | const NodeRtmpSession = require('node-media-server/src/node_rtmp_session') |
@@ -224,7 +224,9 @@ class LiveManager { | |||
224 | 224 | ||
225 | const oldStreamingPlaylist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id) | 225 | const oldStreamingPlaylist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id) |
226 | if (oldStreamingPlaylist) { | 226 | if (oldStreamingPlaylist) { |
227 | await cleanupLive(video, oldStreamingPlaylist) | 227 | if (!videoLive.permanentLive) throw new Error('Found previous session in a non permanent live: ' + video.uuid) |
228 | |||
229 | await cleanupPermanentLive(video, oldStreamingPlaylist) | ||
228 | } | 230 | } |
229 | 231 | ||
230 | this.videoSessions.set(video.id, sessionId) | 232 | this.videoSessions.set(video.id, sessionId) |
diff --git a/server/lib/live/live-utils.ts b/server/lib/live/live-utils.ts index 46c7fd2f8..6365e23db 100644 --- a/server/lib/live/live-utils.ts +++ b/server/lib/live/live-utils.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { remove } from 'fs-extra' | 1 | import { pathExists, readdir, remove } from 'fs-extra' |
2 | import { basename } from 'path' | 2 | import { basename, join } from 'path' |
3 | import { logger } from '@server/helpers/logger' | ||
3 | import { MStreamingPlaylist, MVideo } from '@server/types/models' | 4 | import { MStreamingPlaylist, MVideo } from '@server/types/models' |
4 | import { getLiveDirectory } from '../paths' | 5 | import { getLiveDirectory } from '../paths' |
5 | 6 | ||
@@ -9,7 +10,15 @@ function buildConcatenatedName (segmentOrPlaylistPath: string) { | |||
9 | return 'concat-' + num[1] + '.ts' | 10 | return 'concat-' + num[1] + '.ts' |
10 | } | 11 | } |
11 | 12 | ||
12 | async function cleanupLive (video: MVideo, streamingPlaylist?: MStreamingPlaylist) { | 13 | async function cleanupPermanentLive (video: MVideo, streamingPlaylist?: MStreamingPlaylist) { |
14 | const hlsDirectory = getLiveDirectory(video) | ||
15 | |||
16 | await cleanupTMPLiveFiles(hlsDirectory) | ||
17 | |||
18 | if (streamingPlaylist) await streamingPlaylist.destroy() | ||
19 | } | ||
20 | |||
21 | async function cleanupNormalLive (video: MVideo, streamingPlaylist?: MStreamingPlaylist) { | ||
13 | const hlsDirectory = getLiveDirectory(video) | 22 | const hlsDirectory = getLiveDirectory(video) |
14 | 23 | ||
15 | await remove(hlsDirectory) | 24 | await remove(hlsDirectory) |
@@ -17,7 +26,30 @@ async function cleanupLive (video: MVideo, streamingPlaylist?: MStreamingPlaylis | |||
17 | if (streamingPlaylist) await streamingPlaylist.destroy() | 26 | if (streamingPlaylist) await streamingPlaylist.destroy() |
18 | } | 27 | } |
19 | 28 | ||
29 | async function cleanupTMPLiveFiles (hlsDirectory: string) { | ||
30 | if (!await pathExists(hlsDirectory)) return | ||
31 | |||
32 | const files = await readdir(hlsDirectory) | ||
33 | |||
34 | for (const filename of files) { | ||
35 | if ( | ||
36 | filename.endsWith('.ts') || | ||
37 | filename.endsWith('.m3u8') || | ||
38 | filename.endsWith('.mpd') || | ||
39 | filename.endsWith('.m4s') || | ||
40 | filename.endsWith('.tmp') | ||
41 | ) { | ||
42 | const p = join(hlsDirectory, filename) | ||
43 | |||
44 | remove(p) | ||
45 | .catch(err => logger.error('Cannot remove %s.', p, { err })) | ||
46 | } | ||
47 | } | ||
48 | } | ||
49 | |||
20 | export { | 50 | export { |
21 | cleanupLive, | 51 | cleanupPermanentLive, |
52 | cleanupNormalLive, | ||
53 | cleanupTMPLiveFiles, | ||
22 | buildConcatenatedName | 54 | buildConcatenatedName |
23 | } | 55 | } |