X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fthumbnail.ts;h=02b867a91e6b9fd833514aa82093595925520aba;hb=5a05c14573ca3c0d16b77bef78d845f96c8c6497;hp=c085239880ded8dfbce700b10ce5b2b706ef0c98;hpb=91f8f8db97ffb83701c30f9cdb1e804670434eb0;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts index c08523988..02b867a91 100644 --- a/server/lib/thumbnail.ts +++ b/server/lib/thumbnail.ts @@ -1,16 +1,15 @@ import { join } from 'path' - -import { ThumbnailType } from '../../shared/models/videos/thumbnail.type' -import { generateImageFromVideoFile } from '../helpers/ffmpeg-utils' -import { generateImageFilename, processImage } from '../helpers/image-utils' -import { downloadImage } from '../helpers/requests' +import { ThumbnailType } from '@shared/models' +import { generateImageFilename, generateImageFromVideoFile } from '../helpers/image-utils' import { CONFIG } from '../initializers/config' import { ASSETS_PATH, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '../initializers/constants' import { ThumbnailModel } from '../models/video/thumbnail' import { MVideoFile, MVideoThumbnail, MVideoUUID } from '../types/models' import { MThumbnail } from '../types/models/video/thumbnail' import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist' -import { getVideoFilePath } from './video-paths' +import { downloadImageFromWorker } from './local-actor' +import { VideoPathManager } from './video-path-manager' +import { processImageFromWorker } from './worker/parent-process' type ImageSize = { height?: number, width?: number } @@ -25,7 +24,10 @@ function updatePlaylistMiniatureFromExisting (options: { const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size) const type = ThumbnailType.MINIATURE - const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal) + const thumbnailCreator = () => { + return processImageFromWorker({ path: inputPath, destination: outputPath, newSize: { width, height }, keepOriginal }) + } + return updateThumbnailFromFunction({ thumbnailCreator, filename, @@ -51,7 +53,10 @@ function updatePlaylistMiniatureFromUrl (options: { ? null : downloadUrl - const thumbnailCreator = () => downloadImage(downloadUrl, basePath, filename, { width, height }) + const thumbnailCreator = () => { + return downloadImageFromWorker({ url: downloadUrl, destDir: basePath, destName: filename, size: { width, height } }) + } + return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) } @@ -77,7 +82,9 @@ function updateVideoMiniatureFromUrl (options: { : existingThumbnail.filename const thumbnailCreator = () => { - if (thumbnailUrlChanged) return downloadImage(downloadUrl, basePath, filename, { width, height }) + if (thumbnailUrlChanged) { + return downloadImageFromWorker({ url: downloadUrl, destDir: basePath, destName: filename, size: { width, height } }) + } return Promise.resolve() } @@ -96,7 +103,10 @@ function updateVideoMiniatureFromExisting (options: { const { inputPath, video, type, automaticallyGenerated, size, keepOriginal = false } = options const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) - const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal) + + const thumbnailCreator = () => { + return processImageFromWorker({ path: inputPath, destination: outputPath, newSize: { width, height }, keepOriginal }) + } return updateThumbnailFromFunction({ thumbnailCreator, @@ -116,21 +126,32 @@ function generateVideoMiniature (options: { }) { const { video, videoFile, type } = options - const input = getVideoFilePath(video, videoFile) - - const { filename, basePath, height, width, existingThumbnail, outputPath } = buildMetadataFromVideo(video, type) - const thumbnailCreator = videoFile.isAudio() - ? () => processImage(ASSETS_PATH.DEFAULT_AUDIO_BACKGROUND, outputPath, { width, height }, true) - : () => generateImageFromVideoFile(input, basePath, filename, { height, width }) - - return updateThumbnailFromFunction({ - thumbnailCreator, - filename, - height, - width, - type, - automaticallyGenerated: true, - existingThumbnail + return VideoPathManager.Instance.makeAvailableVideoFile(videoFile.withVideoOrPlaylist(video), input => { + const { filename, basePath, height, width, existingThumbnail, outputPath } = buildMetadataFromVideo(video, type) + + const thumbnailCreator = videoFile.isAudio() + ? () => processImageFromWorker({ + path: ASSETS_PATH.DEFAULT_AUDIO_BACKGROUND, + destination: outputPath, + newSize: { width, height }, + keepOriginal: true + }) + : () => generateImageFromVideoFile({ + fromPath: input, + folder: basePath, + imageName: filename, + size: { height, width } + }) + + return updateThumbnailFromFunction({ + thumbnailCreator, + filename, + height, + width, + type, + automaticallyGenerated: true, + existingThumbnail + }) }) }