X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fschedulers%2Fvideos-redundancy-scheduler.ts;h=c1c91b6563d9488ca1b37d8ea2cce68fc544d119;hb=66fb2aa39b6f8e4677f80128c27fbafd3a8fe2e7;hp=21fe51156e995d782be6d370d97c4188ff18e930;hpb=001ed2d40c8d2c8f494f5dc7f91ed62d56df10fd;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/schedulers/videos-redundancy-scheduler.ts b/server/lib/schedulers/videos-redundancy-scheduler.ts index 21fe51156..c1c91b656 100644 --- a/server/lib/schedulers/videos-redundancy-scheduler.ts +++ b/server/lib/schedulers/videos-redundancy-scheduler.ts @@ -3,7 +3,7 @@ import { HLS_REDUNDANCY_DIRECTORY, REDUNDANCY, VIDEO_IMPORT_TIMEOUT, WEBSERVER } import { logger } from '../../helpers/logger' import { VideosRedundancy } from '../../../shared/models/redundancy' import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' -import { downloadWebTorrentVideo } from '../../helpers/webtorrent' +import { downloadWebTorrentVideo, generateMagnetUri } from '../../helpers/webtorrent' import { join } from 'path' import { move } from 'fs-extra' import { getServerActor } from '../../helpers/utils' @@ -14,7 +14,7 @@ import { getOrCreateVideoAndAccountAndChannel } from '../activitypub' import { downloadPlaylistSegments } from '../hls' import { CONFIG } from '../../initializers/config' import { - MStreamingPlaylist, + MStreamingPlaylist, MStreamingPlaylistFiles, MStreamingPlaylistVideo, MVideoAccountLight, MVideoFile, @@ -24,12 +24,13 @@ import { MVideoRedundancyVideo, MVideoWithAllFiles } from '@server/typings/models' +import { getVideoFilename } from '../video-paths' type CandidateToDuplicate = { redundancy: VideosRedundancy, video: MVideoWithAllFiles, files: MVideoFile[], - streamingPlaylists: MStreamingPlaylist[] + streamingPlaylists: MStreamingPlaylistFiles[] } function isMVideoRedundancyFileVideo ( @@ -195,11 +196,11 @@ export class VideosRedundancyScheduler extends AbstractScheduler { logger.info('Duplicating %s - %d in videos redundancy with "%s" strategy.', video.url, file.resolution, redundancy.strategy) const { baseUrlHttp, baseUrlWs } = video.getBaseUrls() - const magnetUri = video.generateMagnetUri(file, baseUrlHttp, baseUrlWs) + const magnetUri = generateMagnetUri(video, file, baseUrlHttp, baseUrlWs) const tmpPath = await downloadWebTorrentVideo({ magnetUri }, VIDEO_IMPORT_TIMEOUT) - const destPath = join(CONFIG.STORAGE.REDUNDANCY_DIR, video.getVideoFilename(file)) + const destPath = join(CONFIG.STORAGE.REDUNDANCY_DIR, getVideoFilename(video, file)) await move(tmpPath, destPath, { overwrite: true }) const createdModel: MVideoRedundancyFileVideo = await VideoRedundancyModel.create({ @@ -261,7 +262,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler { } private async purgeCacheIfNeeded (candidateToDuplicate: CandidateToDuplicate) { - while (this.isTooHeavy(candidateToDuplicate)) { + while (await this.isTooHeavy(candidateToDuplicate)) { const redundancy = candidateToDuplicate.redundancy const toDelete = await VideoRedundancyModel.loadOldestLocalExpired(redundancy.strategy, redundancy.minLifetime) if (!toDelete) return @@ -289,13 +290,15 @@ export class VideosRedundancyScheduler extends AbstractScheduler { return `${object.VideoStreamingPlaylist.playlistUrl}` } - private getTotalFileSizes (files: MVideoFile[], playlists: MStreamingPlaylist[]) { + private getTotalFileSizes (files: MVideoFile[], playlists: MStreamingPlaylistFiles[]) { const fileReducer = (previous: number, current: MVideoFile) => previous + current.size - const totalSize = files.reduce(fileReducer, 0) - if (playlists.length === 0) return totalSize + let allFiles = files + for (const p of playlists) { + allFiles = allFiles.concat(p.VideoFiles) + } - return totalSize * playlists.length + return allFiles.reduce(fileReducer, 0) } private async loadAndRefreshVideo (videoUrl: string) {