X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fjob-queue%2Fhandlers%2Fvideo-import.ts;h=50e159245f0362f055eb045b0c4a0e5abbf5b1b8;hb=b91bc1d1f3591c35ab4426f6ab594b4bd9f1ef62;hp=8e8aa15970039aa3b01e60ea84c46036ad4d70df;hpb=74dc3bca2b14f5fd3fe80c394dfc34177a46db77;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts index 8e8aa1597..50e159245 100644 --- a/server/lib/job-queue/handlers/video-import.ts +++ b/server/lib/job-queue/handlers/video-import.ts @@ -6,8 +6,7 @@ import { VideoImportState } from '../../../../shared/models/videos' import { getDurationFromVideoFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' import { extname, join } from 'path' import { VideoFileModel } from '../../../models/video/video-file' -import { PREVIEWS_SIZE, THUMBNAILS_SIZE, VIDEO_IMPORT_TIMEOUT } from '../../../initializers/constants' -import { downloadImage } from '../../../helpers/requests' +import { VIDEO_IMPORT_TIMEOUT } from '../../../initializers/constants' import { VideoState } from '../../../../shared' import { JobQueue } from '../index' import { federateVideoIfNeeded } from '../../activitypub' @@ -18,6 +17,9 @@ import { move, remove, stat } from 'fs-extra' import { Notifier } from '../../notifier' import { CONFIG } from '../../../initializers/config' import { sequelizeTypescript } from '../../../initializers/database' +import { ThumbnailModel } from '../../../models/video/thumbnail' +import { createVideoMiniatureFromUrl, generateVideoMiniature } from '../../thumbnail' +import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' type VideoImportYoutubeDLPayload = { type: 'youtube-dl' @@ -146,25 +148,19 @@ async function processFile (downloader: () => Promise, videoImport: Vide tempVideoPath = null // This path is not used anymore // Process thumbnail - if (options.downloadThumbnail) { - if (options.thumbnailUrl) { - await downloadImage(options.thumbnailUrl, CONFIG.STORAGE.THUMBNAILS_DIR, videoImport.Video.getThumbnailName(), THUMBNAILS_SIZE) - } else { - await videoImport.Video.createThumbnail(videoFile) - } - } else if (options.generateThumbnail) { - await videoImport.Video.createThumbnail(videoFile) + let thumbnailModel: ThumbnailModel + if (options.downloadThumbnail && options.thumbnailUrl) { + thumbnailModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImport.Video, ThumbnailType.MINIATURE) + } else if (options.generateThumbnail || options.downloadThumbnail) { + thumbnailModel = await generateVideoMiniature(videoImport.Video, videoFile, ThumbnailType.MINIATURE) } // Process preview - if (options.downloadPreview) { - if (options.thumbnailUrl) { - await downloadImage(options.thumbnailUrl, CONFIG.STORAGE.PREVIEWS_DIR, videoImport.Video.getPreviewName(), PREVIEWS_SIZE) - } else { - await videoImport.Video.createPreview(videoFile) - } - } else if (options.generatePreview) { - await videoImport.Video.createPreview(videoFile) + let previewModel: ThumbnailModel + if (options.downloadPreview && options.thumbnailUrl) { + previewModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImport.Video, ThumbnailType.PREVIEW) + } else if (options.generatePreview || options.downloadPreview) { + previewModel = await generateVideoMiniature(videoImport.Video, videoFile, ThumbnailType.PREVIEW) } // Create torrent @@ -184,6 +180,9 @@ async function processFile (downloader: () => Promise, videoImport: Vide video.state = CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED await video.save({ transaction: t }) + if (thumbnailModel) await video.addAndSaveThumbnail(thumbnailModel, t) + if (previewModel) await video.addAndSaveThumbnail(previewModel, t) + // Now we can federate the video (reload from database, we need more attributes) const videoForFederation = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t) await federateVideoIfNeeded(videoForFederation, true, t) @@ -210,6 +209,7 @@ async function processFile (downloader: () => Promise, videoImport: Vide if (videoImportUpdated.Video.state === VideoState.TO_TRANSCODE) { // Put uuid because we don't have id auto incremented for now const dataInput = { + type: 'optimize' as 'optimize', videoUUID: videoImportUpdated.Video.uuid, isNewVideo: true }