From d7a25329f9e607894d29ab342b9cb66638b56dc0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 15 Nov 2019 15:06:03 +0100 Subject: Add ability to disable webtorrent In favour of HLS --- scripts/optimize-old-videos.ts | 17 +++++++++-------- scripts/prune-storage.ts | 4 ++-- scripts/update-host.ts | 7 ++++--- 3 files changed, 15 insertions(+), 13 deletions(-) (limited to 'scripts') 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 @@ import { registerTSPaths } from '../server/helpers/register-ts-paths' -registerTSPaths() - import { VIDEO_TRANSCODING_FPS } from '../server/initializers/constants' import { getDurationFromVideoFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffmpeg-utils' import { getMaxBitrate } from '../shared/models/videos' import { VideoModel } from '../server/models/video/video' -import { optimizeVideofile } from '../server/lib/video-transcoding' +import { optimizeOriginalVideofile } from '../server/lib/video-transcoding' import { initDatabaseModels } from '../server/initializers' -import { basename, dirname, join } from 'path' +import { basename, dirname } from 'path' import { copy, move, remove } from 'fs-extra' -import { CONFIG } from '../server/initializers/config' +import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' +import { getVideoFilePath } from '@server/lib/video-paths' + +registerTSPaths() run() .then(() => process.exit(0)) @@ -37,7 +38,7 @@ async function run () { currentVideoId = video.id for (const file of video.VideoFiles) { - currentFile = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(file)) + currentFile = getVideoFilePath(video, file) const [ videoBitrate, fps, resolution ] = await Promise.all([ getVideoFileBitrate(currentFile), @@ -56,7 +57,7 @@ async function run () { const backupFile = `${currentFile}_backup` await copy(currentFile, backupFile) - await optimizeVideofile(video, file) + await optimizeOriginalVideofile(video, file) const originalDuration = await getDurationFromVideoFile(backupFile) const newDuration = await getDurationFromVideoFile(currentFile) @@ -69,7 +70,7 @@ async function run () { console.log('Failed to optimize %s, restoring original', basename(currentFile)) await move(backupFile, currentFile, { overwrite: true }) - await video.createTorrentAndSetInfoHash(file) + await createTorrentAndSetInfoHash(video, file) await file.save() } } diff --git a/scripts/prune-storage.ts b/scripts/prune-storage.ts index c8968013b..fa3d81744 100755 --- a/scripts/prune-storage.ts +++ b/scripts/prune-storage.ts @@ -134,9 +134,9 @@ async function doesRedundancyExist (file: string) { return true } - const videoFile = video.getFile(resolution) + const videoFile = video.getWebTorrentFile(resolution) if (!videoFile) { - console.error('Cannot find file of video %s - %d', video.url, resolution) + console.error('Cannot find webtorrent file of video %s - %d', video.url, resolution) return true } diff --git a/scripts/update-host.ts b/scripts/update-host.ts index a946d2e42..d9192d554 100755 --- a/scripts/update-host.ts +++ b/scripts/update-host.ts @@ -1,6 +1,4 @@ import { registerTSPaths } from '../server/helpers/register-ts-paths' -registerTSPaths() - import { WEBSERVER } from '../server/initializers/constants' import { ActorFollowModel } from '../server/models/activitypub/actor-follow' import { VideoModel } from '../server/models/video/video' @@ -19,6 +17,9 @@ import { AccountModel } from '../server/models/account/account' import { VideoChannelModel } from '../server/models/video/video-channel' import { VideoStreamingPlaylistModel } from '../server/models/video/video-streaming-playlist' import { initDatabaseModels } from '../server/initializers' +import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' + +registerTSPaths() run() .then(() => process.exit(0)) @@ -124,7 +125,7 @@ async function run () { for (const file of video.VideoFiles) { console.log('Updating torrent file %s of video %s.', file.resolution, video.uuid) - await video.createTorrentAndSetInfoHash(file) + await createTorrentAndSetInfoHash(video, file) } for (const playlist of video.VideoStreamingPlaylists) { -- cgit v1.2.3