]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/cli/optimize-old-videos.ts
Add missing hotkeys to the watch page
[github/Chocobozzz/PeerTube.git] / server / tests / cli / optimize-old-videos.ts
CommitLineData
74cd011b
C
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4import * as chai from 'chai'
5import { getMaxBitrate, Video, VideoDetails, VideoResolution } from '../../../shared/models/videos'
6import {
7c3b7976 7 cleanupTests,
74cd011b
C
8 doubleFollow,
9 execCLI,
10 flushAndRunMultipleServers,
7243f84d 11 generateHighBitrateVideo,
74cd011b
C
12 getEnvCli,
13 getVideo,
14 getVideosList,
7243f84d 15 root,
74cd011b
C
16 ServerInfo,
17 setAccessTokensToServers,
7243f84d
C
18 uploadVideo,
19 viewVideo,
20 wait
94565d52
C
21} from '../../../shared/extra-utils'
22import { waitJobs } from '../../../shared/extra-utils/server/jobs'
74cd011b 23import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../helpers/ffmpeg-utils'
74dc3bca 24import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants'
74cd011b
C
25import { join } from 'path'
26
27const expect = chai.expect
28
29describe('Test optimize old videos', function () {
30 let servers: ServerInfo[] = []
31 let video1UUID: string
32 let video2UUID: string
33
34 before(async function () {
35 this.timeout(200000)
36
74cd011b
C
37 // Run server 2 to have transcoding enabled
38 servers = await flushAndRunMultipleServers(2)
39 await setAccessTokensToServers(servers)
40
41 await doubleFollow(servers[0], servers[1])
42
43 let tempFixturePath: string
44
45 {
46 tempFixturePath = await generateHighBitrateVideo()
47
48 const bitrate = await getVideoFileBitrate(tempFixturePath)
941c5eac 49 expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS))
74cd011b
C
50 }
51
52 // Upload two videos for our needs
53 const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1', fixture: tempFixturePath })
54 video1UUID = res1.body.video.uuid
55 const res2 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2', fixture: tempFixturePath })
56 video2UUID = res2.body.video.uuid
57
58 await waitJobs(servers)
59 })
60
61 it('Should have two video files on each server', async function () {
62 this.timeout(30000)
63
64 for (const server of servers) {
65 const res = await getVideosList(server.url)
66 const videos = res.body.data
67 expect(videos).to.have.lengthOf(2)
68
69 for (const video of videos) {
70 const res2 = await getVideo(server.url, video.uuid)
71 const videoDetail: VideoDetails = res2.body
72 expect(videoDetail.files).to.have.lengthOf(1)
73 }
74 }
75 })
76
77 it('Should run optimize script', async function () {
5b77537c 78 this.timeout(200000)
74cd011b
C
79
80 const env = getEnvCli(servers[0])
81 await execCLI(`${env} npm run optimize-old-videos`)
82
83 await waitJobs(servers)
84
85 for (const server of servers) {
86 const res = await getVideosList(server.url)
87 const videos: Video[] = res.body.data
88
89 expect(videos).to.have.lengthOf(2)
90
91 for (const video of videos) {
92 await viewVideo(server.url, video.uuid)
93
94 // Refresh video
95 await waitJobs(servers)
96 await wait(5000)
97 await waitJobs(servers)
98
99 const res2 = await getVideo(server.url, video.uuid)
100 const videosDetails: VideoDetails = res2.body
101
102 expect(videosDetails.files).to.have.lengthOf(1)
103 const file = videosDetails.files[0]
104
941c5eac 105 expect(file.size).to.be.below(8000000)
74cd011b 106
7243f84d 107 const path = join(root(), 'test' + servers[0].internalServerNumber, 'videos', video.uuid + '-' + file.resolution.id + '.mp4')
74cd011b
C
108 const bitrate = await getVideoFileBitrate(path)
109 const fps = await getVideoFileFPS(path)
110 const resolution = await getVideoFileResolution(path)
111
112 expect(resolution.videoFileResolution).to.equal(file.resolution.id)
113 expect(bitrate).to.be.below(getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS))
114 }
115 }
116 })
117
7c3b7976
C
118 after(async function () {
119 await cleanupTests(servers)
74cd011b
C
120 })
121})