-
- const video = buildVideo(res.locals.videoChannel.id, body, youtubeDLInfo)
-
- // Process video thumbnail from request.files
- let thumbnailModel = await processThumbnail(req, video)
-
- // Process video thumbnail from url if processing from request.files failed
- if (!thumbnailModel && youtubeDLInfo.thumbnailUrl) {
- thumbnailModel = await processThumbnailFromUrl(youtubeDLInfo.thumbnailUrl, video)
- }
-
- // Process video preview from request.files
- let previewModel = await processPreview(req, video)
-
- // Process video preview from url if processing from request.files failed
- if (!previewModel && youtubeDLInfo.thumbnailUrl) {
- previewModel = await processPreviewFromUrl(youtubeDLInfo.thumbnailUrl, video)
- }
-
- const videoImport = await insertIntoDB({
- video,
- thumbnailModel,
- previewModel,
- videoChannel: res.locals.videoChannel,
- tags: body.tags || youtubeDLInfo.tags,
- user,
- videoImportAttributes: {
- targetUrl,
- state: VideoImportState.PENDING,
- userId: user.id
- }
- })
-
- // Get video subtitles
- await processYoutubeSubtitles(youtubeDL, targetUrl, video.id)
-
- let fileExt = `.${youtubeDLInfo.ext}`
- if (!isVideoFileExtnameValid(fileExt)) fileExt = '.mp4'
-
- // Create job to import the video
- const payload = {
- type: 'youtube-dl' as 'youtube-dl',
- videoImportId: videoImport.id,
- fileExt
- }
- await JobQueue.Instance.createJobWithPromise({ type: 'video-import', payload })
-
- auditLogger.create(getAuditIdFromRes(res), new VideoImportAuditView(videoImport.toFormattedJSON()))
-
- return res.json(videoImport.toFormattedJSON()).end()
-}
-
-function buildVideo (channelId: number, body: VideoImportCreate, importData: YoutubeDLInfo): MVideoThumbnail {
- const videoData = {
- name: body.name || importData.name || 'Unknown name',
- remote: false,
- category: body.category || importData.category,
- licence: body.licence || importData.licence,
- language: body.language || importData.language,
- commentsEnabled: body.commentsEnabled !== false, // If the value is not "false", the default is "true"
- downloadEnabled: body.downloadEnabled !== false,
- waitTranscoding: body.waitTranscoding || false,
- state: VideoState.TO_IMPORT,
- nsfw: body.nsfw || importData.nsfw || false,
- description: body.description || importData.description,
- support: body.support || null,
- privacy: body.privacy || VideoPrivacy.PRIVATE,
- duration: 0, // duration will be set by the import job
- channelId: channelId,
- originallyPublishedAt: body.originallyPublishedAt
- ? new Date(body.originallyPublishedAt)
- : importData.originallyPublishedAt
- }
- const video = new VideoModel(videoData)
- video.url = getLocalVideoActivityPubUrl(video)
-
- return video