1
0
Fork 0

Guess if we need to generate the thumbnail for imports

This commit is contained in:
Chocobozzz 2021-02-12 09:37:01 +01:00
parent 06bee93748
commit e3b4c084cd
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 6 additions and 19 deletions

View File

@ -218,8 +218,6 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response)
const payload = { const payload = {
type: 'youtube-dl' as 'youtube-dl', type: 'youtube-dl' as 'youtube-dl',
videoImportId: videoImport.id, videoImportId: videoImport.id,
generateThumbnail: !thumbnailModel,
generatePreview: !previewModel,
fileExt: `.${youtubeDLInfo.ext || 'mp4'}` fileExt: `.${youtubeDLInfo.ext || 'mp4'}`
} }
await JobQueue.Instance.createJobWithPromise({ type: 'video-import', payload }) await JobQueue.Instance.createJobWithPromise({ type: 'video-import', payload })

View File

@ -57,10 +57,7 @@ async function processTorrentImport (job: Bull.Job, payload: VideoImportTorrentP
const options = { const options = {
type: payload.type, type: payload.type,
videoImportId: payload.videoImportId, videoImportId: payload.videoImportId
generateThumbnail: true,
generatePreview: true
} }
const target = { const target = {
torrentName: videoImport.torrentName ? getSecureTorrentName(videoImport.torrentName) : undefined, torrentName: videoImport.torrentName ? getSecureTorrentName(videoImport.torrentName) : undefined,
@ -75,10 +72,7 @@ async function processYoutubeDLImport (job: Bull.Job, payload: VideoImportYoutub
const videoImport = await getVideoImportOrDie(payload.videoImportId) const videoImport = await getVideoImportOrDie(payload.videoImportId)
const options = { const options = {
type: payload.type, type: payload.type,
videoImportId: videoImport.id, videoImportId: videoImport.id
generateThumbnail: payload.generateThumbnail,
generatePreview: payload.generatePreview
} }
return processFile( return processFile(
@ -100,9 +94,6 @@ async function getVideoImportOrDie (videoImportId: number) {
type ProcessFileOptions = { type ProcessFileOptions = {
type: VideoImportYoutubeDLPayloadType | VideoImportTorrentPayloadType type: VideoImportYoutubeDLPayloadType | VideoImportTorrentPayloadType
videoImportId: number videoImportId: number
generateThumbnail: boolean
generatePreview: boolean
} }
async function processFile (downloader: () => Promise<string>, videoImport: MVideoImportDefault, options: ProcessFileOptions) { async function processFile (downloader: () => Promise<string>, videoImport: MVideoImportDefault, options: ProcessFileOptions) {
let tempVideoPath: string let tempVideoPath: string
@ -167,18 +158,18 @@ async function processFile (downloader: () => Promise<string>, videoImport: MVid
await move(tempVideoPath, videoDestFile) await move(tempVideoPath, videoDestFile)
tempVideoPath = null // This path is not used anymore tempVideoPath = null // This path is not used anymore
// Process thumbnail // Generate miniature if the import did not created it
let thumbnailModel: MThumbnail let thumbnailModel: MThumbnail
let thumbnailSave: object let thumbnailSave: object
if (options.generateThumbnail) { if (!videoImportWithFiles.Video.getMiniature()) {
thumbnailModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.MINIATURE) thumbnailModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.MINIATURE)
thumbnailSave = thumbnailModel.toJSON() thumbnailSave = thumbnailModel.toJSON()
} }
// Process preview // Generate preview if the import did not created it
let previewModel: MThumbnail let previewModel: MThumbnail
let previewSave: object let previewSave: object
if (options.generatePreview) { if (!videoImportWithFiles.Video.getPreview()) {
previewModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.PREVIEW) previewModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.PREVIEW)
previewSave = previewModel.toJSON() previewSave = previewModel.toJSON()
} }

View File

@ -80,8 +80,6 @@ export type VideoImportYoutubeDLPayload = {
type: VideoImportYoutubeDLPayloadType type: VideoImportYoutubeDLPayloadType
videoImportId: number videoImportId: number
generateThumbnail: boolean
generatePreview: boolean
fileExt?: string fileExt?: string
} }
export type VideoImportTorrentPayload = { export type VideoImportTorrentPayload = {