-async function saveLive (video: MVideo, live: MVideoLive) {
- const hlsDirectory = getHLSDirectory(video, false)
- const files = await readdir(hlsDirectory)
-
- 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)
- const { videoFileResolution } = await getVideoFileResolution(playlistPath)
+async function saveReplayToExternalVideo (options: {
+ liveVideo: MVideo
+ liveSession: MVideoLiveSession
+ publishedAt: string
+ replayDirectory: string
+}) {
+ const { liveVideo, liveSession, publishedAt, replayDirectory } = options
+
+ const replayVideo = new VideoModel({
+ name: `${liveVideo.name} - ${new Date(publishedAt).toLocaleString()}`,
+ isLive: false,
+ state: VideoState.TO_TRANSCODE,
+ duration: 0,
+
+ remote: liveVideo.remote,
+ category: liveVideo.category,
+ licence: liveVideo.licence,
+ language: liveVideo.language,
+ commentsEnabled: liveVideo.commentsEnabled,
+ downloadEnabled: liveVideo.downloadEnabled,
+ waitTranscoding: true,
+ nsfw: liveVideo.nsfw,
+ description: liveVideo.description,
+ support: liveVideo.support,
+ privacy: liveVideo.privacy,
+ channelId: liveVideo.channelId
+ }) as MVideoWithAllFiles
+
+ replayVideo.Thumbnails = []
+ replayVideo.VideoFiles = []
+ replayVideo.VideoStreamingPlaylists = []
+
+ replayVideo.url = getLocalVideoActivityPubUrl(replayVideo)
+
+ await replayVideo.save()
+
+ liveSession.replayVideoId = replayVideo.id
+ await liveSession.save()
+
+ // If live is blacklisted, also blacklist the replay
+ const blacklist = await VideoBlacklistModel.loadByVideoId(liveVideo.id)
+ if (blacklist) {
+ await VideoBlacklistModel.create({
+ videoId: replayVideo.id,
+ unfederated: blacklist.unfederated,
+ reason: blacklist.reason,
+ type: blacklist.type
+ })
+ }