]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix live saving after a server restart
authorChocobozzz <me@florianbigard.com>
Mon, 30 Nov 2020 16:03:13 +0000 (17:03 +0100)
committerChocobozzz <me@florianbigard.com>
Mon, 30 Nov 2020 16:03:13 +0000 (17:03 +0100)
server/lib/job-queue/handlers/video-live-ending.ts
server/lib/live-manager.ts

index 0d2bcaa28150f65a7808d6e51728276b60ed0966..6e1076d8f2340767a2d73f31779f38e98ca663cb 100644 (file)
@@ -1,8 +1,9 @@
 import * as Bull from 'bull'
-import { move, readdir, remove } from 'fs-extra'
+import { copy, readdir, remove } from 'fs-extra'
 import { join } from 'path'
 import { hlsPlaylistToFragmentedMP4 } from '@server/helpers/ffmpeg-utils'
 import { getDurationFromVideoFile, getVideoFileResolution } from '@server/helpers/ffprobe-utils'
+import { VIDEO_LIVE } from '@server/initializers/constants'
 import { generateVideoMiniature } from '@server/lib/thumbnail'
 import { publishAndFederateIfNeeded } from '@server/lib/video'
 import { getHLSDirectory } from '@server/lib/video-paths'
@@ -14,7 +15,6 @@ import { VideoStreamingPlaylistModel } from '@server/models/video/video-streamin
 import { MStreamingPlaylist, MVideo, MVideoLive } from '@server/types/models'
 import { ThumbnailType, VideoLiveEndingPayload, VideoState } from '@shared/models'
 import { logger } from '../../../helpers/logger'
-import { VIDEO_LIVE } from '@server/initializers/constants'
 
 async function processVideoLiveEnding (job: Bull.Job) {
   const payload = job.data as VideoLiveEndingPayload
@@ -61,11 +61,12 @@ async function saveLive (video: MVideo, live: MVideoLive) {
   const playlistFiles: string[] = []
 
   for (const file of rootFiles) {
-    if (file.endsWith('.m3u8') !== true) continue
-
-    await move(join(hlsDirectory, file), join(replayDirectory, file))
+    // Move remaining files in the replay directory
+    if (file.endsWith('.ts') || file.endsWith('.m3u8')) {
+      await copy(join(hlsDirectory, file), join(replayDirectory, file))
+    }
 
-    if (file !== 'master.m3u8') {
+    if (file.endsWith('.m3u8') && file !== 'master.m3u8') {
       playlistFiles.push(file)
     }
   }
index 690e2ce55214ccd07478dacdeb02587177b49aa5..4f45ce530004081dc96ac69f2a6d12363892548c 100644 (file)
@@ -378,13 +378,13 @@ class LiveManager {
         // Wait latest segments generation, and close watchers
 
         Promise.all([ tsWatcher.close(), masterWatcher.close() ])
-        .then(() => {
-          // Process remaining segments hash
-          for (const key of Object.keys(segmentsToProcessPerPlaylist)) {
-            processSegments(segmentsToProcessPerPlaylist[key])
-          }
-        })
-        .catch(err => logger.error('Cannot close watchers of %s or process remaining hash segments.', outPath, { err }))
+          .then(() => {
+            // Process remaining segments hash
+            for (const key of Object.keys(segmentsToProcessPerPlaylist)) {
+              processSegments(segmentsToProcessPerPlaylist[key])
+            }
+          })
+          .catch(err => logger.error('Cannot close watchers of %s or process remaining hash segments.', outPath, { err }))
 
         this.onEndTransmuxing(videoLive.Video.id)
           .catch(err => logger.error('Error in closed transmuxing.', { err }))