From 5b77537ce54832f47931ba47dc513be2a9197f92 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Jul 2019 12:04:15 +0200 Subject: Correctly notify on auto blacklist --- scripts/optimize-old-videos.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/optimize-old-videos.ts b/scripts/optimize-old-videos.ts index a1d5345a1..2c80f16bc 100644 --- a/scripts/optimize-old-videos.ts +++ b/scripts/optimize-old-videos.ts @@ -32,6 +32,7 @@ async function run () { for (const video of localVideos) { currentVideoId = video.id + for (const file of video.VideoFiles) { currentFile = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(file)) @@ -44,22 +45,29 @@ async function run () { const maxBitrate = getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS) const isMaxBitrateExceeded = videoBitrate > maxBitrate if (isMaxBitrateExceeded) { - console.log('Optimizing video file %s with bitrate %s kbps (max: %s kbps)', - basename(currentFile), videoBitrate / 1000, maxBitrate / 1000) + console.log( + 'Optimizing video file %s with bitrate %s kbps (max: %s kbps)', + basename(currentFile), videoBitrate / 1000, maxBitrate / 1000 + ) + const backupFile = `${currentFile}_backup` await copy(currentFile, backupFile) + await optimizeVideofile(video, file) + const originalDuration = await getDurationFromVideoFile(backupFile) const newDuration = await getDurationFromVideoFile(currentFile) + if (originalDuration === newDuration) { console.log('Finished optimizing %s', basename(currentFile)) await remove(backupFile) - } else { - console.log('Failed to optimize %s, restoring original', basename(currentFile)) - move(backupFile, currentFile, { overwrite: true }) - await video.createTorrentAndSetInfoHash(file) - await file.save() + return } + + console.log('Failed to optimize %s, restoring original', basename(currentFile)) + await move(backupFile, currentFile, { overwrite: true }) + await video.createTorrentAndSetInfoHash(file) + await file.save() } } } -- cgit v1.2.3