diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-23 12:04:15 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | 5b77537ce54832f47931ba47dc513be2a9197f92 (patch) | |
tree | 4f968168f1346faa82ac6c9663778e1cca65b02a /scripts/optimize-old-videos.ts | |
parent | d8e9a42c4b048b2669ab6a61704682ce23fbcf99 (diff) | |
download | PeerTube-5b77537ce54832f47931ba47dc513be2a9197f92.tar.gz PeerTube-5b77537ce54832f47931ba47dc513be2a9197f92.tar.zst PeerTube-5b77537ce54832f47931ba47dc513be2a9197f92.zip |
Correctly notify on auto blacklist
Diffstat (limited to 'scripts/optimize-old-videos.ts')
-rw-r--r-- | scripts/optimize-old-videos.ts | 22 |
1 files changed, 15 insertions, 7 deletions
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 () { | |||
32 | 32 | ||
33 | for (const video of localVideos) { | 33 | for (const video of localVideos) { |
34 | currentVideoId = video.id | 34 | currentVideoId = video.id |
35 | |||
35 | for (const file of video.VideoFiles) { | 36 | for (const file of video.VideoFiles) { |
36 | currentFile = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(file)) | 37 | currentFile = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(file)) |
37 | 38 | ||
@@ -44,22 +45,29 @@ async function run () { | |||
44 | const maxBitrate = getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS) | 45 | const maxBitrate = getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS) |
45 | const isMaxBitrateExceeded = videoBitrate > maxBitrate | 46 | const isMaxBitrateExceeded = videoBitrate > maxBitrate |
46 | if (isMaxBitrateExceeded) { | 47 | if (isMaxBitrateExceeded) { |
47 | console.log('Optimizing video file %s with bitrate %s kbps (max: %s kbps)', | 48 | console.log( |
48 | basename(currentFile), videoBitrate / 1000, maxBitrate / 1000) | 49 | 'Optimizing video file %s with bitrate %s kbps (max: %s kbps)', |
50 | basename(currentFile), videoBitrate / 1000, maxBitrate / 1000 | ||
51 | ) | ||
52 | |||
49 | const backupFile = `${currentFile}_backup` | 53 | const backupFile = `${currentFile}_backup` |
50 | await copy(currentFile, backupFile) | 54 | await copy(currentFile, backupFile) |
55 | |||
51 | await optimizeVideofile(video, file) | 56 | await optimizeVideofile(video, file) |
57 | |||
52 | const originalDuration = await getDurationFromVideoFile(backupFile) | 58 | const originalDuration = await getDurationFromVideoFile(backupFile) |
53 | const newDuration = await getDurationFromVideoFile(currentFile) | 59 | const newDuration = await getDurationFromVideoFile(currentFile) |
60 | |||
54 | if (originalDuration === newDuration) { | 61 | if (originalDuration === newDuration) { |
55 | console.log('Finished optimizing %s', basename(currentFile)) | 62 | console.log('Finished optimizing %s', basename(currentFile)) |
56 | await remove(backupFile) | 63 | await remove(backupFile) |
57 | } else { | 64 | return |
58 | console.log('Failed to optimize %s, restoring original', basename(currentFile)) | ||
59 | move(backupFile, currentFile, { overwrite: true }) | ||
60 | await video.createTorrentAndSetInfoHash(file) | ||
61 | await file.save() | ||
62 | } | 65 | } |
66 | |||
67 | console.log('Failed to optimize %s, restoring original', basename(currentFile)) | ||
68 | await move(backupFile, currentFile, { overwrite: true }) | ||
69 | await video.createTorrentAndSetInfoHash(file) | ||
70 | await file.save() | ||
63 | } | 71 | } |
64 | } | 72 | } |
65 | } | 73 | } |