- return res.send(json).end()
-}
-
-async function downloadTorrent (req: express.Request, res: express.Response, next: express.NextFunction) {
- const { video, videoFile } = getVideoAndFile(req, res)
- if (!videoFile) return res.status(404).end()
-
- return res.download(video.getTorrentFilePath(videoFile), `${video.name}-${videoFile.resolution}p.torrent`)
-}
-
-async function downloadVideoFile (req: express.Request, res: express.Response, next: express.NextFunction) {
- const { video, videoFile } = getVideoAndFile(req, res)
- if (!videoFile) return res.status(404).end()
-
- return res.download(video.getVideoFilePath(videoFile), `${video.name}-${videoFile.resolution}p${videoFile.extname}`)
-}
-
-function getVideoAndFile (req: express.Request, res: express.Response) {
- const resolution = parseInt(req.params.resolution, 10)
- const video: VideoModel = res.locals.video
-
- const videoFile = video.VideoFiles.find(f => f.resolution === resolution)
+ // Inject token in playlist so players that cannot alter the HTTP request can still watch the video
+ const transformedContent = doReinjectVideoFileToken(req)
+ ? injectQueryToPlaylistUrls(playlistContent, buildReinjectVideoFileTokenQuery(req))
+ : playlistContent