]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { | |
6 | cleanupTests, | |
7 | createMultipleServers, | |
8 | doubleFollow, | |
9 | generateHighBitrateVideo, | |
10 | PeerTubeServer, | |
11 | setAccessTokensToServers, | |
12 | wait, | |
13 | waitJobs | |
14 | } from '@shared/extra-utils' | |
15 | import { getMaxBitrate, VideoResolution } from '@shared/models' | |
16 | import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../helpers/ffprobe-utils' | |
17 | import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants' | |
18 | ||
19 | const expect = chai.expect | |
20 | ||
21 | describe('Test optimize old videos', function () { | |
22 | let servers: PeerTubeServer[] = [] | |
23 | ||
24 | before(async function () { | |
25 | this.timeout(200000) | |
26 | ||
27 | // Run server 2 to have transcoding enabled | |
28 | servers = await createMultipleServers(2) | |
29 | await setAccessTokensToServers(servers) | |
30 | ||
31 | await doubleFollow(servers[0], servers[1]) | |
32 | ||
33 | let tempFixturePath: string | |
34 | ||
35 | { | |
36 | tempFixturePath = await generateHighBitrateVideo() | |
37 | ||
38 | const bitrate = await getVideoFileBitrate(tempFixturePath) | |
39 | expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS)) | |
40 | } | |
41 | ||
42 | // Upload two videos for our needs | |
43 | await servers[0].videos.upload({ attributes: { name: 'video1', fixture: tempFixturePath } }) | |
44 | await servers[0].videos.upload({ attributes: { name: 'video2', fixture: tempFixturePath } }) | |
45 | ||
46 | await waitJobs(servers) | |
47 | }) | |
48 | ||
49 | it('Should have two video files on each server', async function () { | |
50 | this.timeout(30000) | |
51 | ||
52 | for (const server of servers) { | |
53 | const { data } = await server.videos.list() | |
54 | expect(data).to.have.lengthOf(2) | |
55 | ||
56 | for (const video of data) { | |
57 | const videoDetails = await server.videos.get({ id: video.uuid }) | |
58 | expect(videoDetails.files).to.have.lengthOf(1) | |
59 | } | |
60 | } | |
61 | }) | |
62 | ||
63 | it('Should run optimize script', async function () { | |
64 | this.timeout(200000) | |
65 | ||
66 | await servers[0].cli.execWithEnv('npm run optimize-old-videos') | |
67 | await waitJobs(servers) | |
68 | ||
69 | for (const server of servers) { | |
70 | const { data } = await server.videos.list() | |
71 | expect(data).to.have.lengthOf(2) | |
72 | ||
73 | for (const video of data) { | |
74 | await server.videos.view({ id: video.uuid }) | |
75 | ||
76 | // Refresh video | |
77 | await waitJobs(servers) | |
78 | await wait(5000) | |
79 | await waitJobs(servers) | |
80 | ||
81 | const videoDetails = await server.videos.get({ id: video.uuid }) | |
82 | ||
83 | expect(videoDetails.files).to.have.lengthOf(1) | |
84 | const file = videoDetails.files[0] | |
85 | ||
86 | expect(file.size).to.be.below(8000000) | |
87 | ||
88 | const path = servers[0].servers.buildWebTorrentFilePath(file.fileUrl) | |
89 | const bitrate = await getVideoFileBitrate(path) | |
90 | const fps = await getVideoFileFPS(path) | |
91 | const resolution = await getVideoFileResolution(path) | |
92 | ||
93 | expect(resolution.videoFileResolution).to.equal(file.resolution.id) | |
94 | expect(bitrate).to.be.below(getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)) | |
95 | } | |
96 | } | |
97 | }) | |
98 | ||
99 | after(async function () { | |
100 | await cleanupTests(servers) | |
101 | }) | |
102 | }) |