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'
import { downloadPlaylistSegments } from '../hls'
import { CONFIG } from '../../initializers/config'
import {
- MStreamingPlaylist,
+ MStreamingPlaylist, MStreamingPlaylistFiles,
MStreamingPlaylistVideo,
MVideoAccountLight,
MVideoFile,
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 (
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({
}
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
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) {