aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/optimize-old-videos.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-11-15 15:06:03 +0100
committerChocobozzz <me@florianbigard.com>2019-11-25 10:59:43 +0100
commitd7a25329f9e607894d29ab342b9cb66638b56dc0 (patch)
tree6cd6bc4f2689f78944238b313c93427423a932ac /scripts/optimize-old-videos.ts
parent14981d7331da3f63fe6cfaf020ccb7c910006eaf (diff)
downloadPeerTube-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.ts17
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 @@
1import { registerTSPaths } from '../server/helpers/register-ts-paths' 1import { registerTSPaths } from '../server/helpers/register-ts-paths'
2registerTSPaths()
3
4import { VIDEO_TRANSCODING_FPS } from '../server/initializers/constants' 2import { VIDEO_TRANSCODING_FPS } from '../server/initializers/constants'
5import { getDurationFromVideoFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffmpeg-utils' 3import { getDurationFromVideoFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffmpeg-utils'
6import { getMaxBitrate } from '../shared/models/videos' 4import { getMaxBitrate } from '../shared/models/videos'
7import { VideoModel } from '../server/models/video/video' 5import { VideoModel } from '../server/models/video/video'
8import { optimizeVideofile } from '../server/lib/video-transcoding' 6import { optimizeOriginalVideofile } from '../server/lib/video-transcoding'
9import { initDatabaseModels } from '../server/initializers' 7import { initDatabaseModels } from '../server/initializers'
10import { basename, dirname, join } from 'path' 8import { basename, dirname } from 'path'
11import { copy, move, remove } from 'fs-extra' 9import { copy, move, remove } from 'fs-extra'
12import { CONFIG } from '../server/initializers/config' 10import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
11import { getVideoFilePath } from '@server/lib/video-paths'
12
13registerTSPaths()
13 14
14run() 15run()
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 }