-import { AbstractScheduler } from './abstract-scheduler'
-import { HLS_REDUNDANCY_DIRECTORY, REDUNDANCY, VIDEO_IMPORT_TIMEOUT, WEBSERVER } from '../../initializers/constants'
-import { logger } from '../../helpers/logger'
-import { VideosRedundancyStrategy } from '../../../shared/models/redundancy'
-import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
-import { downloadWebTorrentVideo, generateMagnetUri } from '../../helpers/webtorrent'
-import { join } from 'path'
import { move } from 'fs-extra'
-import { getServerActor } from '../../helpers/utils'
-import { sendCreateCacheFile, sendUpdateCacheFile } from '../activitypub/send'
-import { getVideoCacheFileActivityPubUrl, getVideoCacheStreamingPlaylistActivityPubUrl } from '../activitypub/url'
-import { removeVideoRedundancy } from '../redundancy'
-import { getOrCreateVideoAndAccountAndChannel } from '../activitypub'
-import { downloadPlaylistSegments } from '../hls'
-import { CONFIG } from '../../initializers/config'
+import { join } from 'path'
+import { getServerActor } from '@server/models/application/application'
+import { TrackerModel } from '@server/models/server/tracker'
+import { VideoModel } from '@server/models/video/video'
import {
- MStreamingPlaylist, MStreamingPlaylistFiles,
+ MStreamingPlaylist,
+ MStreamingPlaylistFiles,
MStreamingPlaylistVideo,
MVideoAccountLight,
MVideoFile,
MVideoRedundancyStreamingPlaylistVideo,
MVideoRedundancyVideo,
MVideoWithAllFiles
-} from '@server/typings/models'
-import { getVideoFilename } from '../video-paths'
-import { VideoModel } from '@server/models/video/video'
+} from '@server/types/models'
+import { VideosRedundancyStrategy } from '../../../shared/models/redundancy'
+import { logger } from '../../helpers/logger'
+import { downloadWebTorrentVideo, generateMagnetUri } from '../../helpers/webtorrent'
+import { CONFIG } from '../../initializers/config'
+import { HLS_REDUNDANCY_DIRECTORY, REDUNDANCY, VIDEO_IMPORT_TIMEOUT } from '../../initializers/constants'
+import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
+import { sendCreateCacheFile, sendUpdateCacheFile } from '../activitypub/send'
+import { getLocalVideoCacheFileActivityPubUrl, getLocalVideoCacheStreamingPlaylistActivityPubUrl } from '../activitypub/url'
+import { getOrCreateVideoAndAccountAndChannel } from '../activitypub/videos'
+import { downloadPlaylistSegments } from '../hls'
+import { removeVideoRedundancy } from '../redundancy'
+import { generateHLSRedundancyUrl, generateWebTorrentRedundancyUrl } from '../video-paths'
+import { AbstractScheduler } from './abstract-scheduler'
type CandidateToDuplicate = {
- redundancy: VideosRedundancyStrategy,
- video: MVideoWithAllFiles,
- files: MVideoFile[],
+ redundancy: VideosRedundancyStrategy
+ video: MVideoWithAllFiles
+ files: MVideoFile[]
streamingPlaylists: MStreamingPlaylistFiles[]
}
logger.info('Duplicating %s - %d in videos redundancy with "%s" strategy.', video.url, file.resolution, strategy)
- const { baseUrlHttp, baseUrlWs } = video.getBaseUrls()
- const magnetUri = generateMagnetUri(video, file, baseUrlHttp, baseUrlWs)
+ const trackerUrls = await TrackerModel.listUrlsByVideoId(video.id)
+ const magnetUri = generateMagnetUri(video, file, trackerUrls)
const tmpPath = await downloadWebTorrentVideo({ magnetUri }, VIDEO_IMPORT_TIMEOUT)
- const destPath = join(CONFIG.STORAGE.REDUNDANCY_DIR, getVideoFilename(video, file))
+ const destPath = join(CONFIG.STORAGE.REDUNDANCY_DIR, file.filename)
await move(tmpPath, destPath, { overwrite: true })
const createdModel: MVideoRedundancyFileVideo = await VideoRedundancyModel.create({
expiresOn,
- url: getVideoCacheFileActivityPubUrl(file),
- fileUrl: video.getVideoRedundancyUrl(file, WEBSERVER.URL),
+ url: getLocalVideoCacheFileActivityPubUrl(file),
+ fileUrl: generateWebTorrentRedundancyUrl(file),
strategy,
videoFileId: file.id,
actorId: serverActor.id
const createdModel: MVideoRedundancyStreamingPlaylistVideo = await VideoRedundancyModel.create({
expiresOn,
- url: getVideoCacheStreamingPlaylistActivityPubUrl(video, playlist),
- fileUrl: playlist.getVideoRedundancyUrl(WEBSERVER.URL),
+ url: getLocalVideoCacheStreamingPlaylistActivityPubUrl(video, playlist),
+ fileUrl: generateHLSRedundancyUrl(video, playlistArg),
strategy,
videoStreamingPlaylistId: playlist.id,
actorId: serverActor.id
const toDelete = await VideoRedundancyModel.loadOldestLocalExpired(redundancy.strategy, redundancy.minLifetime)
if (!toDelete) return
- await removeVideoRedundancy(toDelete)
+ const videoId = toDelete.VideoFile
+ ? toDelete.VideoFile.videoId
+ : toDelete.VideoStreamingPlaylist.videoId
+
+ const redundancies = await VideoRedundancyModel.listLocalByVideoId(videoId)
+
+ for (const redundancy of redundancies) {
+ await removeVideoRedundancy(redundancy)
+ }
}
}