1
0
Fork 0
peertube/server/tests/cli/optimize-old-videos.ts

118 lines
3.5 KiB
TypeScript
Raw Normal View History

2020-01-31 10:56:52 -05:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2018-10-18 10:53:52 -04:00
import 'mocha'
import * as chai from 'chai'
2020-11-20 11:16:55 -05:00
import { join } from 'path'
2018-10-18 10:53:52 -04:00
import {
2020-11-24 09:22:56 -05:00
buildServerDirectory,
2019-04-24 09:10:37 -04:00
cleanupTests,
2018-10-18 10:53:52 -04:00
doubleFollow,
execCLI,
flushAndRunMultipleServers,
generateHighBitrateVideo,
2018-10-18 10:53:52 -04:00
getEnvCli,
getVideo,
getVideosList,
ServerInfo,
setAccessTokensToServers,
uploadVideo,
viewVideo,
wait
} from '../../../shared/extra-utils'
import { waitJobs } from '../../../shared/extra-utils/server/jobs'
2020-11-20 11:16:55 -05:00
import { getMaxBitrate, Video, VideoDetails, VideoResolution } from '../../../shared/models/videos'
import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../helpers/ffprobe-utils'
import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants'
2018-10-18 10:53:52 -04:00
const expect = chai.expect
describe('Test optimize old videos', function () {
let servers: ServerInfo[] = []
before(async function () {
this.timeout(200000)
// Run server 2 to have transcoding enabled
servers = await flushAndRunMultipleServers(2)
await setAccessTokensToServers(servers)
await doubleFollow(servers[0], servers[1])
let tempFixturePath: string
{
tempFixturePath = await generateHighBitrateVideo()
const bitrate = await getVideoFileBitrate(tempFixturePath)
2019-12-06 03:55:36 -05:00
expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS))
2018-10-18 10:53:52 -04:00
}
// Upload two videos for our needs
2020-06-17 04:55:40 -04:00
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1', fixture: tempFixturePath })
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2', fixture: tempFixturePath })
2018-10-18 10:53:52 -04:00
await waitJobs(servers)
})
it('Should have two video files on each server', async function () {
this.timeout(30000)
for (const server of servers) {
const res = await getVideosList(server.url)
const videos = res.body.data
expect(videos).to.have.lengthOf(2)
for (const video of videos) {
const res2 = await getVideo(server.url, video.uuid)
const videoDetail: VideoDetails = res2.body
expect(videoDetail.files).to.have.lengthOf(1)
}
}
})
it('Should run optimize script', async function () {
2019-07-23 06:04:15 -04:00
this.timeout(200000)
2018-10-18 10:53:52 -04:00
const env = getEnvCli(servers[0])
await execCLI(`${env} npm run optimize-old-videos`)
await waitJobs(servers)
for (const server of servers) {
const res = await getVideosList(server.url)
const videos: Video[] = res.body.data
expect(videos).to.have.lengthOf(2)
for (const video of videos) {
await viewVideo(server.url, video.uuid)
// Refresh video
await waitJobs(servers)
await wait(5000)
await waitJobs(servers)
const res2 = await getVideo(server.url, video.uuid)
const videosDetails: VideoDetails = res2.body
expect(videosDetails.files).to.have.lengthOf(1)
const file = videosDetails.files[0]
2019-12-06 03:55:36 -05:00
expect(file.size).to.be.below(8000000)
2018-10-18 10:53:52 -04:00
2020-11-24 09:22:56 -05:00
const path = buildServerDirectory(servers[0], join('videos', video.uuid + '-' + file.resolution.id + '.mp4'))
2018-10-18 10:53:52 -04:00
const bitrate = await getVideoFileBitrate(path)
const fps = await getVideoFileFPS(path)
const resolution = await getVideoFileResolution(path)
expect(resolution.videoFileResolution).to.equal(file.resolution.id)
expect(bitrate).to.be.below(getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS))
}
}
})
2019-04-24 09:10:37 -04:00
after(async function () {
await cleanupTests(servers)
2018-10-18 10:53:52 -04:00
})
})