-async function processThumbnailFromUrl (url: string, video: MVideoThumbnail) {
- try {
- return createVideoMiniatureFromUrl({ downloadUrl: url, video, type: ThumbnailType.MINIATURE })
- } catch (err) {
- logger.warn('Cannot generate video thumbnail %s for %s.', url, video.url, { err })
- return undefined
- }
-}
-
-async function processPreviewFromUrl (url: string, video: MVideoThumbnail) {
- try {
- return createVideoMiniatureFromUrl({ downloadUrl: url, video, type: ThumbnailType.PREVIEW })
- } catch (err) {
- logger.warn('Cannot generate video preview %s for %s.', url, video.url, { err })
- return undefined
- }
-}
-
-async function insertIntoDB (parameters: {
- video: MVideoThumbnail
- thumbnailModel: MThumbnail
- previewModel: MThumbnail
- videoChannel: MChannelAccountDefault
- tags: string[]
- videoImportAttributes: FilteredModelAttributes<VideoImportModel>
- user: MUser
-}): Promise<MVideoImportFormattable> {
- const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters
-
- const videoImport = await sequelizeTypescript.transaction(async t => {
- const sequelizeOptions = { transaction: t }
-
- // Save video object in database
- const videoCreated = await video.save(sequelizeOptions) as (MVideoAccountDefault & MVideoWithBlacklistLight & MVideoTag)
- videoCreated.VideoChannel = videoChannel
-
- if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
- if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t)
-
- await autoBlacklistVideoIfNeeded({
- video: videoCreated,
- user,
- notify: false,
- isRemote: false,
- isNew: true,
- transaction: t
- })
-
- await setVideoTags({ video: videoCreated, tags, transaction: t })
-
- // Create video import object in database
- const videoImport = await VideoImportModel.create(
- Object.assign({ videoId: videoCreated.id }, videoImportAttributes),
- sequelizeOptions
- ) as MVideoImportFormattable
- videoImport.Video = videoCreated
-
- return videoImport
- })
-
- return videoImport
-}
-