aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/utils/videos
diff options
context:
space:
mode:
Diffstat (limited to 'shared/utils/videos')
-rw-r--r--shared/utils/videos/video-playlists.ts51
-rw-r--r--shared/utils/videos/videos.ts13
2 files changed, 62 insertions, 2 deletions
diff --git a/shared/utils/videos/video-playlists.ts b/shared/utils/videos/video-playlists.ts
new file mode 100644
index 000000000..eb25011cb
--- /dev/null
+++ b/shared/utils/videos/video-playlists.ts
@@ -0,0 +1,51 @@
1import { makeRawRequest } from '../requests/requests'
2import { sha256 } from '../../../server/helpers/core-utils'
3import { VideoStreamingPlaylist } from '../../models/videos/video-streaming-playlist.model'
4import { expect } from 'chai'
5
6function getPlaylist (url: string, statusCodeExpected = 200) {
7 return makeRawRequest(url, statusCodeExpected)
8}
9
10function getSegment (url: string, statusCodeExpected = 200, range?: string) {
11 return makeRawRequest(url, statusCodeExpected, range)
12}
13
14function getSegmentSha256 (url: string, statusCodeExpected = 200) {
15 return makeRawRequest(url, statusCodeExpected)
16}
17
18async function checkSegmentHash (
19 baseUrlPlaylist: string,
20 baseUrlSegment: string,
21 videoUUID: string,
22 resolution: number,
23 hlsPlaylist: VideoStreamingPlaylist
24) {
25 const res = await getPlaylist(`${baseUrlPlaylist}/${videoUUID}/${resolution}.m3u8`)
26 const playlist = res.text
27
28 const videoName = `${videoUUID}-${resolution}-fragmented.mp4`
29
30 const matches = /#EXT-X-BYTERANGE:(\d+)@(\d+)/.exec(playlist)
31
32 const length = parseInt(matches[1], 10)
33 const offset = parseInt(matches[2], 10)
34 const range = `${offset}-${offset + length - 1}`
35
36 const res2 = await getSegment(`${baseUrlSegment}/${videoUUID}/${videoName}`, 206, `bytes=${range}`)
37
38 const resSha = await getSegmentSha256(hlsPlaylist.segmentsSha256Url)
39
40 const sha256Server = resSha.body[ videoName ][range]
41 expect(sha256(res2.body)).to.equal(sha256Server)
42}
43
44// ---------------------------------------------------------------------------
45
46export {
47 getPlaylist,
48 getSegment,
49 getSegmentSha256,
50 checkSegmentHash
51}
diff --git a/shared/utils/videos/videos.ts b/shared/utils/videos/videos.ts
index 0cf6e7c4f..b5b33e038 100644
--- a/shared/utils/videos/videos.ts
+++ b/shared/utils/videos/videos.ts
@@ -271,7 +271,16 @@ function removeVideo (url: string, token: string, id: number | string, expectedS
271async function checkVideoFilesWereRemoved ( 271async function checkVideoFilesWereRemoved (
272 videoUUID: string, 272 videoUUID: string,
273 serverNumber: number, 273 serverNumber: number,
274 directories = [ 'redundancy', 'videos', 'thumbnails', 'torrents', 'previews', 'captions' ] 274 directories = [
275 'redundancy',
276 'videos',
277 'thumbnails',
278 'torrents',
279 'previews',
280 'captions',
281 join('playlists', 'hls'),
282 join('redundancy', 'hls')
283 ]
275) { 284) {
276 const testDirectory = 'test' + serverNumber 285 const testDirectory = 'test' + serverNumber
277 286
@@ -279,7 +288,7 @@ async function checkVideoFilesWereRemoved (
279 const directoryPath = join(root(), testDirectory, directory) 288 const directoryPath = join(root(), testDirectory, directory)
280 289
281 const directoryExists = existsSync(directoryPath) 290 const directoryExists = existsSync(directoryPath)
282 expect(directoryExists).to.be.true 291 if (!directoryExists) continue
283 292
284 const files = await readdir(directoryPath) 293 const files = await readdir(directoryPath)
285 for (const file of files) { 294 for (const file of files) {