From d846d99c6c81028bb7bd3cb20abd433cbf396a22 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 28 Oct 2020 10:49:20 +0100 Subject: Add modal to display live information --- server/lib/job-queue/handlers/video-live-ending.ts | 12 ++++++++++- server/lib/job-queue/handlers/video-transcoding.ts | 23 +--------------------- 2 files changed, 12 insertions(+), 23 deletions(-) (limited to 'server/lib/job-queue') diff --git a/server/lib/job-queue/handlers/video-live-ending.ts b/server/lib/job-queue/handlers/video-live-ending.ts index cd5bb1d1c..32eeff4d1 100644 --- a/server/lib/job-queue/handlers/video-live-ending.ts +++ b/server/lib/job-queue/handlers/video-live-ending.ts @@ -1,7 +1,8 @@ import * as Bull from 'bull' import { readdir, remove } from 'fs-extra' import { join } from 'path' -import { getVideoFileResolution, hlsPlaylistToFragmentedMP4 } from '@server/helpers/ffmpeg-utils' +import { getDurationFromVideoFile, getVideoFileResolution, hlsPlaylistToFragmentedMP4 } from '@server/helpers/ffmpeg-utils' +import { publishAndFederateIfNeeded } from '@server/lib/video' import { getHLSDirectory } from '@server/lib/video-paths' import { generateHlsPlaylist } from '@server/lib/video-transcoding' import { VideoModel } from '@server/models/video/video' @@ -44,6 +45,7 @@ async function saveLive (video: MVideo, live: MVideoLive) { const playlistFiles = files.filter(f => f.endsWith('.m3u8') && f !== 'master.m3u8') const resolutions: number[] = [] + let duration: number for (const playlistFile of playlistFiles) { const playlistPath = join(hlsDirectory, playlistFile) @@ -58,6 +60,10 @@ async function saveLive (video: MVideo, live: MVideoLive) { const segmentFiles = files.filter(f => f.startsWith(shouldStartWith) && f.endsWith('.ts')) await hlsPlaylistToFragmentedMP4(hlsDirectory, segmentFiles, mp4TmpName) + if (!duration) { + duration = await getDurationFromVideoFile(mp4TmpName) + } + resolutions.push(videoFileResolution) } @@ -67,6 +73,8 @@ async function saveLive (video: MVideo, live: MVideoLive) { video.isLive = false video.state = VideoState.TO_TRANSCODE + video.duration = duration + await video.save() const videoWithFiles = await VideoModel.loadWithFiles(video.id) @@ -86,6 +94,8 @@ async function saveLive (video: MVideo, live: MVideoLive) { video.state = VideoState.PUBLISHED await video.save() + + await publishAndFederateIfNeeded(video) } async function cleanupLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) { diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts index 2aebc29f7..843a9f1b5 100644 --- a/server/lib/job-queue/handlers/video-transcoding.ts +++ b/server/lib/job-queue/handlers/video-transcoding.ts @@ -1,4 +1,5 @@ import * as Bull from 'bull' +import { publishAndFederateIfNeeded } from '@server/lib/video' import { getVideoFilePath } from '@server/lib/video-paths' import { MVideoFullLight, MVideoUUID, MVideoWithFile } from '@server/types/models' import { @@ -174,25 +175,3 @@ function createHlsJobIfEnabled (payload?: { videoUUID: string, resolution: numbe return JobQueue.Instance.createJob({ type: 'video-transcoding', payload: hlsTranscodingPayload }) } } - -async function publishAndFederateIfNeeded (video: MVideoUUID) { - const { videoDatabase, videoPublished } = await sequelizeTypescript.transaction(async t => { - // Maybe the video changed in database, refresh it - const videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t) - // Video does not exist anymore - if (!videoDatabase) return undefined - - // We transcoded the video file in another format, now we can publish it - const videoPublished = await videoDatabase.publishIfNeededAndSave(t) - - // If the video was not published, we consider it is a new one for other instances - await federateVideoIfNeeded(videoDatabase, videoPublished, t) - - return { videoDatabase, videoPublished } - }) - - if (videoPublished) { - Notifier.Instance.notifyOnNewVideoIfNeeded(videoDatabase) - Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(videoDatabase) - } -} -- cgit v1.2.3