X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fjob-queue%2Fhandlers%2Fvideo-import.ts;h=50e159245f0362f055eb045b0c4a0e5abbf5b1b8;hb=b91bc1d1f3591c35ab4426f6ab594b4bd9f1ef62;hp=12004dcd7ef5fb7af316bb2c23da7163f92343df;hpb=dc13348070d808d0ba3feb56a435b835c2e7e791;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 12004dcd7..50e159245 100644 --- a/server/lib/job-queue/handlers/video-import.ts +++ b/server/lib/job-queue/handlers/video-import.ts @@ -6,16 +6,20 @@ 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 { CONFIG, PREVIEWS_SIZE, sequelizeTypescript, THUMBNAILS_SIZE, VIDEO_IMPORT_TIMEOUT } from '../../../initializers' -import { downloadImage } from '../../../helpers/requests' +import { VIDEO_IMPORT_TIMEOUT } from '../../../initializers/constants' import { VideoState } from '../../../../shared' import { JobQueue } from '../index' import { federateVideoIfNeeded } from '../../activitypub' import { VideoModel } from '../../../models/video/video' import { downloadWebTorrentVideo } from '../../../helpers/webtorrent' import { getSecureTorrentName } from '../../../helpers/utils' -import { remove, move, stat } from 'fs-extra' +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' @@ -144,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 @@ -182,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) @@ -196,18 +197,24 @@ async function processFile (downloader: () => Promise, videoImport: Vide return videoImportUpdated }) - Notifier.Instance.notifyOnNewVideo(videoImportUpdated.Video) 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 const dataInput = { + type: 'optimize' as 'optimize', videoUUID: videoImportUpdated.Video.uuid, isNewVideo: true } - await JobQueue.Instance.createJob({ type: 'video-file', payload: dataInput }) + await JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput }) } } catch (err) {