import { VideoModel } from '../../../models/video/video'
import { downloadWebTorrentVideo } from '../../../helpers/webtorrent'
import { getSecureTorrentName } from '../../../helpers/utils'
-import { remove, rename, stat } from 'fs-extra'
+import { remove, move, stat } from 'fs-extra'
+import { Notifier } from '../../notifier'
type VideoImportYoutubeDLPayload = {
type: 'youtube-dl'
// Move file
videoDestFile = join(CONFIG.STORAGE.VIDEOS_DIR, videoImport.Video.getVideoFilename(videoFile))
- await rename(tempVideoPath, videoDestFile)
+ await move(tempVideoPath, videoDestFile)
tempVideoPath = null // This path is not used anymore
// Process thumbnail
// Update video DB object
video.duration = duration
video.state = CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED
- const videoUpdated = await video.save({ transaction: t })
+ await video.save({ transaction: t })
// Now we can federate the video (reload from database, we need more attributes)
const videoForFederation = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t)
logger.info('Video %s imported.', video.uuid)
- videoImportUpdated.Video = videoUpdated
+ videoImportUpdated.Video = videoForFederation
return videoImportUpdated
})
+ Notifier.Instance.notifyOnFinishedVideoImport(videoImportUpdated, true)
+
+ if (videoImportUpdated.Video.VideoBlacklist) {
+ Notifier.Instance.notifyOnVideoAutoBlacklist(videoImportUpdated.Video)
+ } else {
+ Notifier.Instance.notifyOnNewVideo(videoImportUpdated.Video)
+ }
+
// Create transcoding jobs?
if (videoImportUpdated.Video.state === VideoState.TO_TRANSCODE) {
// Put uuid because we don't have id auto incremented for now
isNewVideo: true
}
- await JobQueue.Instance.createJob({ type: 'video-file', payload: dataInput })
+ await JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput })
}
} catch (err) {
videoImport.state = VideoImportState.FAILED
await videoImport.save()
+ Notifier.Instance.notifyOnFinishedVideoImport(videoImport, false)
+
throw err
}
}