+ await this.createVideoFileRedundancy(data.redundancy, video, file)
+ }
+
+ for (const streamingPlaylist of data.streamingPlaylists) {
+ const existingRedundancy = await VideoRedundancyModel.loadLocalByStreamingPlaylistId(streamingPlaylist.id)
+ if (existingRedundancy) {
+ await this.extendsRedundancy(existingRedundancy)
+
+ continue
+ }
+
+ await this.createStreamingPlaylistRedundancy(data.redundancy, video, streamingPlaylist)
+ }
+ }
+
+ private async createVideoFileRedundancy (redundancy: VideosRedundancy, video: MVideoAccountLight, fileArg: MVideoFile) {
+ const file = fileArg as MVideoFileVideo
+ file.Video = video
+
+ const serverActor = await getServerActor()
+
+ logger.info('Duplicating %s - %d in videos redundancy with "%s" strategy.', video.url, file.resolution, redundancy.strategy)
+
+ const { baseUrlHttp, baseUrlWs } = video.getBaseUrls()
+ const magnetUri = generateMagnetUri(video, file, baseUrlHttp, baseUrlWs)
+
+ const tmpPath = await downloadWebTorrentVideo({ magnetUri }, VIDEO_IMPORT_TIMEOUT)
+
+ const destPath = join(CONFIG.STORAGE.REDUNDANCY_DIR, getVideoFilename(video, file))
+ await move(tmpPath, destPath, { overwrite: true })
+
+ const createdModel: MVideoRedundancyFileVideo = await VideoRedundancyModel.create({
+ expiresOn: this.buildNewExpiration(redundancy.minLifetime),
+ url: getVideoCacheFileActivityPubUrl(file),
+ fileUrl: video.getVideoRedundancyUrl(file, WEBSERVER.URL),
+ strategy: redundancy.strategy,
+ videoFileId: file.id,
+ actorId: serverActor.id
+ })