diff options
Diffstat (limited to 'shared/utils/videos')
-rw-r--r-- | shared/utils/videos/video-blacklist.ts | 11 | ||||
-rw-r--r-- | shared/utils/videos/video-playlists.ts | 51 | ||||
-rw-r--r-- | shared/utils/videos/videos.ts | 19 |
3 files changed, 77 insertions, 4 deletions
diff --git a/shared/utils/videos/video-blacklist.ts b/shared/utils/videos/video-blacklist.ts index 2c176fde0..f2ae0ed26 100644 --- a/shared/utils/videos/video-blacklist.ts +++ b/shared/utils/videos/video-blacklist.ts | |||
@@ -1,11 +1,18 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | 2 | ||
3 | function addVideoToBlacklist (url: string, token: string, videoId: number | string, reason?: string, specialStatus = 204) { | 3 | function addVideoToBlacklist ( |
4 | url: string, | ||
5 | token: string, | ||
6 | videoId: number | string, | ||
7 | reason?: string, | ||
8 | unfederate?: boolean, | ||
9 | specialStatus = 204 | ||
10 | ) { | ||
4 | const path = '/api/v1/videos/' + videoId + '/blacklist' | 11 | const path = '/api/v1/videos/' + videoId + '/blacklist' |
5 | 12 | ||
6 | return request(url) | 13 | return request(url) |
7 | .post(path) | 14 | .post(path) |
8 | .send({ reason }) | 15 | .send({ reason, unfederate }) |
9 | .set('Accept', 'application/json') | 16 | .set('Accept', 'application/json') |
10 | .set('Authorization', 'Bearer ' + token) | 17 | .set('Authorization', 'Bearer ' + token) |
11 | .expect(specialStatus) | 18 | .expect(specialStatus) |
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 @@ | |||
1 | import { makeRawRequest } from '../requests/requests' | ||
2 | import { sha256 } from '../../../server/helpers/core-utils' | ||
3 | import { VideoStreamingPlaylist } from '../../models/videos/video-streaming-playlist.model' | ||
4 | import { expect } from 'chai' | ||
5 | |||
6 | function getPlaylist (url: string, statusCodeExpected = 200) { | ||
7 | return makeRawRequest(url, statusCodeExpected) | ||
8 | } | ||
9 | |||
10 | function getSegment (url: string, statusCodeExpected = 200, range?: string) { | ||
11 | return makeRawRequest(url, statusCodeExpected, range) | ||
12 | } | ||
13 | |||
14 | function getSegmentSha256 (url: string, statusCodeExpected = 200) { | ||
15 | return makeRawRequest(url, statusCodeExpected) | ||
16 | } | ||
17 | |||
18 | async 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 | |||
46 | export { | ||
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..39c808d1f 100644 --- a/shared/utils/videos/videos.ts +++ b/shared/utils/videos/videos.ts | |||
@@ -28,6 +28,7 @@ type VideoAttributes = { | |||
28 | language?: string | 28 | language?: string |
29 | nsfw?: boolean | 29 | nsfw?: boolean |
30 | commentsEnabled?: boolean | 30 | commentsEnabled?: boolean |
31 | downloadEnabled?: boolean | ||
31 | waitTranscoding?: boolean | 32 | waitTranscoding?: boolean |
32 | description?: string | 33 | description?: string |
33 | tags?: string[] | 34 | tags?: string[] |
@@ -271,7 +272,16 @@ function removeVideo (url: string, token: string, id: number | string, expectedS | |||
271 | async function checkVideoFilesWereRemoved ( | 272 | async function checkVideoFilesWereRemoved ( |
272 | videoUUID: string, | 273 | videoUUID: string, |
273 | serverNumber: number, | 274 | serverNumber: number, |
274 | directories = [ 'redundancy', 'videos', 'thumbnails', 'torrents', 'previews', 'captions' ] | 275 | directories = [ |
276 | 'redundancy', | ||
277 | 'videos', | ||
278 | 'thumbnails', | ||
279 | 'torrents', | ||
280 | 'previews', | ||
281 | 'captions', | ||
282 | join('playlists', 'hls'), | ||
283 | join('redundancy', 'hls') | ||
284 | ] | ||
275 | ) { | 285 | ) { |
276 | const testDirectory = 'test' + serverNumber | 286 | const testDirectory = 'test' + serverNumber |
277 | 287 | ||
@@ -279,7 +289,7 @@ async function checkVideoFilesWereRemoved ( | |||
279 | const directoryPath = join(root(), testDirectory, directory) | 289 | const directoryPath = join(root(), testDirectory, directory) |
280 | 290 | ||
281 | const directoryExists = existsSync(directoryPath) | 291 | const directoryExists = existsSync(directoryPath) |
282 | expect(directoryExists).to.be.true | 292 | if (!directoryExists) continue |
283 | 293 | ||
284 | const files = await readdir(directoryPath) | 294 | const files = await readdir(directoryPath) |
285 | for (const file of files) { | 295 | for (const file of files) { |
@@ -311,6 +321,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg | |||
311 | tags: [ 'tag' ], | 321 | tags: [ 'tag' ], |
312 | privacy: VideoPrivacy.PUBLIC, | 322 | privacy: VideoPrivacy.PUBLIC, |
313 | commentsEnabled: true, | 323 | commentsEnabled: true, |
324 | downloadEnabled: true, | ||
314 | fixture: 'video_short.webm' | 325 | fixture: 'video_short.webm' |
315 | }, videoAttributesArg) | 326 | }, videoAttributesArg) |
316 | 327 | ||
@@ -321,6 +332,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg | |||
321 | .field('name', attributes.name) | 332 | .field('name', attributes.name) |
322 | .field('nsfw', JSON.stringify(attributes.nsfw)) | 333 | .field('nsfw', JSON.stringify(attributes.nsfw)) |
323 | .field('commentsEnabled', JSON.stringify(attributes.commentsEnabled)) | 334 | .field('commentsEnabled', JSON.stringify(attributes.commentsEnabled)) |
335 | .field('downloadEnabled', JSON.stringify(attributes.downloadEnabled)) | ||
324 | .field('waitTranscoding', JSON.stringify(attributes.waitTranscoding)) | 336 | .field('waitTranscoding', JSON.stringify(attributes.waitTranscoding)) |
325 | .field('privacy', attributes.privacy.toString()) | 337 | .field('privacy', attributes.privacy.toString()) |
326 | .field('channelId', attributes.channelId) | 338 | .field('channelId', attributes.channelId) |
@@ -371,6 +383,7 @@ function updateVideo (url: string, accessToken: string, id: number | string, att | |||
371 | if (attributes.language) body['language'] = attributes.language | 383 | if (attributes.language) body['language'] = attributes.language |
372 | if (attributes.nsfw !== undefined) body['nsfw'] = JSON.stringify(attributes.nsfw) | 384 | if (attributes.nsfw !== undefined) body['nsfw'] = JSON.stringify(attributes.nsfw) |
373 | if (attributes.commentsEnabled !== undefined) body['commentsEnabled'] = JSON.stringify(attributes.commentsEnabled) | 385 | if (attributes.commentsEnabled !== undefined) body['commentsEnabled'] = JSON.stringify(attributes.commentsEnabled) |
386 | if (attributes.downloadEnabled !== undefined) body['downloadEnabled'] = JSON.stringify(attributes.downloadEnabled) | ||
374 | if (attributes.description) body['description'] = attributes.description | 387 | if (attributes.description) body['description'] = attributes.description |
375 | if (attributes.tags) body['tags'] = attributes.tags | 388 | if (attributes.tags) body['tags'] = attributes.tags |
376 | if (attributes.privacy) body['privacy'] = attributes.privacy | 389 | if (attributes.privacy) body['privacy'] = attributes.privacy |
@@ -436,6 +449,7 @@ async function completeVideoCheck ( | |||
436 | language: string | 449 | language: string |
437 | nsfw: boolean | 450 | nsfw: boolean |
438 | commentsEnabled: boolean | 451 | commentsEnabled: boolean |
452 | downloadEnabled: boolean | ||
439 | description: string | 453 | description: string |
440 | publishedAt?: string | 454 | publishedAt?: string |
441 | support: string | 455 | support: string |
@@ -510,6 +524,7 @@ async function completeVideoCheck ( | |||
510 | expect(dateIsValid(videoDetails.channel.createdAt.toString())).to.be.true | 524 | expect(dateIsValid(videoDetails.channel.createdAt.toString())).to.be.true |
511 | expect(dateIsValid(videoDetails.channel.updatedAt.toString())).to.be.true | 525 | expect(dateIsValid(videoDetails.channel.updatedAt.toString())).to.be.true |
512 | expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled) | 526 | expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled) |
527 | expect(videoDetails.downloadEnabled).to.equal(attributes.downloadEnabled) | ||
513 | 528 | ||
514 | for (const attributeFile of attributes.files) { | 529 | for (const attributeFile of attributes.files) { |
515 | const file = videoDetails.files.find(f => f.resolution.id === attributeFile.resolution) | 530 | const file = videoDetails.files.find(f => f.resolution.id === attributeFile.resolution) |