diff options
author | Chocobozzz <me@florianbigard.com> | 2019-11-15 15:06:03 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-11-25 10:59:43 +0100 |
commit | d7a25329f9e607894d29ab342b9cb66638b56dc0 (patch) | |
tree | 6cd6bc4f2689f78944238b313c93427423a932ac /scripts/optimize-old-videos.ts | |
parent | 14981d7331da3f63fe6cfaf020ccb7c910006eaf (diff) | |
download | PeerTube-d7a25329f9e607894d29ab342b9cb66638b56dc0.tar.gz PeerTube-d7a25329f9e607894d29ab342b9cb66638b56dc0.tar.zst PeerTube-d7a25329f9e607894d29ab342b9cb66638b56dc0.zip |
Add ability to disable webtorrent
In favour of HLS
Diffstat (limited to 'scripts/optimize-old-videos.ts')
-rw-r--r-- | scripts/optimize-old-videos.ts | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/scripts/optimize-old-videos.ts b/scripts/optimize-old-videos.ts index eb61ec43c..107483c50 100644 --- a/scripts/optimize-old-videos.ts +++ b/scripts/optimize-old-videos.ts | |||
@@ -1,15 +1,16 @@ | |||
1 | import { registerTSPaths } from '../server/helpers/register-ts-paths' | 1 | import { registerTSPaths } from '../server/helpers/register-ts-paths' |
2 | registerTSPaths() | ||
3 | |||
4 | import { VIDEO_TRANSCODING_FPS } from '../server/initializers/constants' | 2 | import { VIDEO_TRANSCODING_FPS } from '../server/initializers/constants' |
5 | import { getDurationFromVideoFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffmpeg-utils' | 3 | import { getDurationFromVideoFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffmpeg-utils' |
6 | import { getMaxBitrate } from '../shared/models/videos' | 4 | import { getMaxBitrate } from '../shared/models/videos' |
7 | import { VideoModel } from '../server/models/video/video' | 5 | import { VideoModel } from '../server/models/video/video' |
8 | import { optimizeVideofile } from '../server/lib/video-transcoding' | 6 | import { optimizeOriginalVideofile } from '../server/lib/video-transcoding' |
9 | import { initDatabaseModels } from '../server/initializers' | 7 | import { initDatabaseModels } from '../server/initializers' |
10 | import { basename, dirname, join } from 'path' | 8 | import { basename, dirname } from 'path' |
11 | import { copy, move, remove } from 'fs-extra' | 9 | import { copy, move, remove } from 'fs-extra' |
12 | import { CONFIG } from '../server/initializers/config' | 10 | import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' |
11 | import { getVideoFilePath } from '@server/lib/video-paths' | ||
12 | |||
13 | registerTSPaths() | ||
13 | 14 | ||
14 | run() | 15 | run() |
15 | .then(() => process.exit(0)) | 16 | .then(() => process.exit(0)) |
@@ -37,7 +38,7 @@ async function run () { | |||
37 | currentVideoId = video.id | 38 | currentVideoId = video.id |
38 | 39 | ||
39 | for (const file of video.VideoFiles) { | 40 | for (const file of video.VideoFiles) { |
40 | currentFile = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(file)) | 41 | currentFile = getVideoFilePath(video, file) |
41 | 42 | ||
42 | const [ videoBitrate, fps, resolution ] = await Promise.all([ | 43 | const [ videoBitrate, fps, resolution ] = await Promise.all([ |
43 | getVideoFileBitrate(currentFile), | 44 | getVideoFileBitrate(currentFile), |
@@ -56,7 +57,7 @@ async function run () { | |||
56 | const backupFile = `${currentFile}_backup` | 57 | const backupFile = `${currentFile}_backup` |
57 | await copy(currentFile, backupFile) | 58 | await copy(currentFile, backupFile) |
58 | 59 | ||
59 | await optimizeVideofile(video, file) | 60 | await optimizeOriginalVideofile(video, file) |
60 | 61 | ||
61 | const originalDuration = await getDurationFromVideoFile(backupFile) | 62 | const originalDuration = await getDurationFromVideoFile(backupFile) |
62 | const newDuration = await getDurationFromVideoFile(currentFile) | 63 | const newDuration = await getDurationFromVideoFile(currentFile) |
@@ -69,7 +70,7 @@ async function run () { | |||
69 | 70 | ||
70 | console.log('Failed to optimize %s, restoring original', basename(currentFile)) | 71 | console.log('Failed to optimize %s, restoring original', basename(currentFile)) |
71 | await move(backupFile, currentFile, { overwrite: true }) | 72 | await move(backupFile, currentFile, { overwrite: true }) |
72 | await video.createTorrentAndSetInfoHash(file) | 73 | await createTorrentAndSetInfoHash(video, file) |
73 | await file.save() | 74 | await file.save() |
74 | } | 75 | } |
75 | } | 76 | } |