From 4bc45da342597fb49593fc14c40f8dc5a97bb64e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Mar 2021 11:54:08 +0100 Subject: Add hooks support for video download --- server/lib/files-cache/videos-torrent-cache.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'server/lib') diff --git a/server/lib/files-cache/videos-torrent-cache.ts b/server/lib/files-cache/videos-torrent-cache.ts index 881fa9ced..23217f140 100644 --- a/server/lib/files-cache/videos-torrent-cache.ts +++ b/server/lib/files-cache/videos-torrent-cache.ts @@ -5,6 +5,7 @@ import { CONFIG } from '../../initializers/config' import { FILES_CACHE } from '../../initializers/constants' import { VideoModel } from '../../models/video/video' import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache' +import { MVideo, MVideoFile } from '@server/types/models' class VideosTorrentCache extends AbstractVideoStaticFileCache { @@ -22,7 +23,11 @@ class VideosTorrentCache extends AbstractVideoStaticFileCache { const file = await VideoFileModel.loadWithVideoOrPlaylistByTorrentFilename(filename) if (!file) return undefined - if (file.getVideo().isOwned()) return { isOwned: true, path: join(CONFIG.STORAGE.TORRENTS_DIR, file.torrentFilename) } + if (file.getVideo().isOwned()) { + const downloadName = this.buildDownloadName(file.getVideo(), file) + + return { isOwned: true, path: join(CONFIG.STORAGE.TORRENTS_DIR, file.torrentFilename), downloadName } + } return this.loadRemoteFile(filename) } @@ -43,10 +48,14 @@ class VideosTorrentCache extends AbstractVideoStaticFileCache { await doRequestAndSaveToFile(remoteUrl, destPath) - const downloadName = `${video.name}-${file.resolution}p.torrent` + const downloadName = this.buildDownloadName(video, file) return { isOwned: false, path: destPath, downloadName } } + + private buildDownloadName (video: MVideo, file: MVideoFile) { + return `${video.name}-${file.resolution}p.torrent` + } } export { -- cgit v1.2.3