+ const internalTags = tags || []
+ const tagInstances = await TagModel.findOrCreateTags(internalTags, transaction)
+
+ await video.$set('Tags', tagInstances, { transaction })
+ video.Tags = tagInstances
+}
+
+async function publishAndFederateIfNeeded (video: MVideoUUID, wasLive = false) {
+ const result = 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
+ // Live videos are always federated, so it's not a new video
+ await federateVideoIfNeeded(videoDatabase, !wasLive && videoPublished, t)
+
+ return { videoDatabase, videoPublished }
+ })
+
+ if (result?.videoPublished) {
+ Notifier.Instance.notifyOnNewVideoIfNeeded(result.videoDatabase)
+ Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(result.videoDatabase)
+ }
+}
+
+async function addOptimizeOrMergeAudioJob (video: MVideoUUID, videoFile: MVideoFile, user: MUserId) {
+ let dataInput: VideoTranscodingPayload
+
+ if (videoFile.isAudio()) {
+ dataInput = {
+ type: 'merge-audio-to-webtorrent',
+ resolution: DEFAULT_AUDIO_RESOLUTION,
+ videoUUID: video.uuid,
+ isNewVideo: true
+ }