diff options
Diffstat (limited to 'server/tests/api/videos')
-rw-r--r-- | server/tests/api/videos/multiple-servers.ts | 16 | ||||
-rw-r--r-- | server/tests/api/videos/video-imports.ts | 161 | ||||
-rw-r--r-- | server/tests/api/videos/video-transcoder.ts | 188 |
3 files changed, 311 insertions, 54 deletions
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index cb18898ce..516dc5aba 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts | |||
@@ -209,19 +209,19 @@ describe('Test multiple servers', function () { | |||
209 | files: [ | 209 | files: [ |
210 | { | 210 | { |
211 | resolution: 240, | 211 | resolution: 240, |
212 | size: 190000 | 212 | size: 280000 |
213 | }, | 213 | }, |
214 | { | 214 | { |
215 | resolution: 360, | 215 | resolution: 360, |
216 | size: 280000 | 216 | size: 370000 |
217 | }, | 217 | }, |
218 | { | 218 | { |
219 | resolution: 480, | 219 | resolution: 480, |
220 | size: 390000 | 220 | size: 470000 |
221 | }, | 221 | }, |
222 | { | 222 | { |
223 | resolution: 720, | 223 | resolution: 720, |
224 | size: 710000 | 224 | size: 740000 |
225 | } | 225 | } |
226 | ], | 226 | ], |
227 | thumbnailfile: 'thumbnail', | 227 | thumbnailfile: 'thumbnail', |
@@ -975,19 +975,19 @@ describe('Test multiple servers', function () { | |||
975 | files: [ | 975 | files: [ |
976 | { | 976 | { |
977 | resolution: 720, | 977 | resolution: 720, |
978 | size: 40315 | 978 | size: 36000 |
979 | }, | 979 | }, |
980 | { | 980 | { |
981 | resolution: 480, | 981 | resolution: 480, |
982 | size: 22808 | 982 | size: 21000 |
983 | }, | 983 | }, |
984 | { | 984 | { |
985 | resolution: 360, | 985 | resolution: 360, |
986 | size: 18617 | 986 | size: 17000 |
987 | }, | 987 | }, |
988 | { | 988 | { |
989 | resolution: 240, | 989 | resolution: 240, |
990 | size: 15217 | 990 | size: 13000 |
991 | } | 991 | } |
992 | ] | 992 | ] |
993 | } | 993 | } |
diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts new file mode 100644 index 000000000..f21ade5c3 --- /dev/null +++ b/server/tests/api/videos/video-imports.ts | |||
@@ -0,0 +1,161 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' | ||
6 | import { | ||
7 | doubleFollow, | ||
8 | flushAndRunMultipleServers, | ||
9 | getMyUserInformation, | ||
10 | getMyVideos, | ||
11 | getVideo, | ||
12 | getVideosList, | ||
13 | killallServers, | ||
14 | ServerInfo, | ||
15 | setAccessTokensToServers | ||
16 | } from '../../utils' | ||
17 | import { waitJobs } from '../../utils/server/jobs' | ||
18 | import { getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../utils/videos/video-imports' | ||
19 | |||
20 | const expect = chai.expect | ||
21 | |||
22 | describe('Test video imports', function () { | ||
23 | let servers: ServerInfo[] = [] | ||
24 | let channelIdServer1: number | ||
25 | let channelIdServer2: number | ||
26 | |||
27 | async function checkVideoServer1 (url: string, id: number | string) { | ||
28 | const res = await getVideo(url, id) | ||
29 | const video: VideoDetails = res.body | ||
30 | |||
31 | expect(video.name).to.equal('small video - youtube') | ||
32 | expect(video.category.label).to.equal('News') | ||
33 | expect(video.licence.label).to.equal('Attribution') | ||
34 | expect(video.language.label).to.equal('Unknown') | ||
35 | expect(video.nsfw).to.be.false | ||
36 | expect(video.description).to.equal('this is a super description') | ||
37 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2' ]) | ||
38 | |||
39 | expect(video.files).to.have.lengthOf(1) | ||
40 | } | ||
41 | |||
42 | async function checkVideoServer2 (url: string, id: number | string) { | ||
43 | const res = await getVideo(url, id) | ||
44 | const video = res.body | ||
45 | |||
46 | expect(video.name).to.equal('my super name') | ||
47 | expect(video.category.label).to.equal('Entertainment') | ||
48 | expect(video.licence.label).to.equal('Public Domain Dedication') | ||
49 | expect(video.language.label).to.equal('English') | ||
50 | expect(video.nsfw).to.be.false | ||
51 | expect(video.description).to.equal('my super description') | ||
52 | expect(video.tags).to.deep.equal([ 'supertag1', 'supertag2' ]) | ||
53 | |||
54 | expect(video.files).to.have.lengthOf(1) | ||
55 | } | ||
56 | |||
57 | before(async function () { | ||
58 | this.timeout(30000) | ||
59 | |||
60 | // Run servers | ||
61 | servers = await flushAndRunMultipleServers(2) | ||
62 | |||
63 | await setAccessTokensToServers(servers) | ||
64 | |||
65 | { | ||
66 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | ||
67 | channelIdServer1 = res.body.videoChannels[ 0 ].id | ||
68 | } | ||
69 | |||
70 | { | ||
71 | const res = await getMyUserInformation(servers[1].url, servers[1].accessToken) | ||
72 | channelIdServer2 = res.body.videoChannels[ 0 ].id | ||
73 | } | ||
74 | |||
75 | await doubleFollow(servers[0], servers[1]) | ||
76 | }) | ||
77 | |||
78 | it('Should import a video on server 1', async function () { | ||
79 | this.timeout(60000) | ||
80 | |||
81 | const attributes = { | ||
82 | targetUrl: getYoutubeVideoUrl(), | ||
83 | channelId: channelIdServer1, | ||
84 | privacy: VideoPrivacy.PUBLIC | ||
85 | } | ||
86 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | ||
87 | expect(res.body.video.name).to.equal('small video - youtube') | ||
88 | }) | ||
89 | |||
90 | it('Should list the video to import in my videos on server 1', async function () { | ||
91 | const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) | ||
92 | |||
93 | expect(res.body.total).to.equal(1) | ||
94 | |||
95 | const videos = res.body.data | ||
96 | expect(videos).to.have.lengthOf(1) | ||
97 | expect(videos[0].name).to.equal('small video - youtube') | ||
98 | }) | ||
99 | |||
100 | it('Should list the video to import in my imports on server 1', async function () { | ||
101 | const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) | ||
102 | |||
103 | expect(res.body.total).to.equal(1) | ||
104 | const videoImports = res.body.data | ||
105 | expect(videoImports).to.have.lengthOf(1) | ||
106 | |||
107 | expect(videoImports[0].targetUrl).to.equal(getYoutubeVideoUrl()) | ||
108 | expect(videoImports[0].video.name).to.equal('small video - youtube') | ||
109 | }) | ||
110 | |||
111 | it('Should have the video listed on the two instances1', async function () { | ||
112 | this.timeout(120000) | ||
113 | |||
114 | await waitJobs(servers) | ||
115 | |||
116 | for (const server of servers) { | ||
117 | const res = await getVideosList(server.url) | ||
118 | expect(res.body.total).to.equal(1) | ||
119 | expect(res.body.data).to.have.lengthOf(1) | ||
120 | |||
121 | await checkVideoServer1(server.url, res.body.data[0].uuid) | ||
122 | } | ||
123 | }) | ||
124 | |||
125 | it('Should import a video on server 2 with some fields', async function () { | ||
126 | this.timeout(60000) | ||
127 | |||
128 | const attributes = { | ||
129 | targetUrl: getYoutubeVideoUrl(), | ||
130 | channelId: channelIdServer1, | ||
131 | privacy: VideoPrivacy.PUBLIC, | ||
132 | category: 10, | ||
133 | licence: 7, | ||
134 | language: 'en', | ||
135 | name: 'my super name', | ||
136 | description: 'my super description', | ||
137 | tags: [ 'supertag1', 'supertag2' ] | ||
138 | } | ||
139 | const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) | ||
140 | expect(res.body.video.name).to.equal('my super name') | ||
141 | }) | ||
142 | |||
143 | it('Should have the video listed on the two instances', async function () { | ||
144 | this.timeout(120000) | ||
145 | |||
146 | await waitJobs(servers) | ||
147 | |||
148 | for (const server of servers) { | ||
149 | const res = await getVideosList(server.url) | ||
150 | expect(res.body.total).to.equal(2) | ||
151 | expect(res.body.data).to.have.lengthOf(2) | ||
152 | |||
153 | await checkVideoServer2(server.url, res.body.data[0].uuid) | ||
154 | await checkVideoServer1(server.url, res.body.data[1].uuid) | ||
155 | } | ||
156 | }) | ||
157 | |||
158 | after(async function () { | ||
159 | killallServers(servers) | ||
160 | }) | ||
161 | }) | ||
diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index fe750253e..0f83d4d57 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts | |||
@@ -2,9 +2,12 @@ | |||
2 | 2 | ||
3 | import * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import 'mocha' | 4 | import 'mocha' |
5 | import { omit } from 'lodash' | ||
6 | import * as ffmpeg from 'fluent-ffmpeg' | ||
5 | import { VideoDetails, VideoState } from '../../../../shared/models/videos' | 7 | import { VideoDetails, VideoState } from '../../../../shared/models/videos' |
6 | import { getVideoFileFPS } from '../../../helpers/ffmpeg-utils' | 8 | import { getVideoFileFPS, audio } from '../../../helpers/ffmpeg-utils' |
7 | import { | 9 | import { |
10 | buildAbsoluteFixturePath, | ||
8 | doubleFollow, | 11 | doubleFollow, |
9 | flushAndRunMultipleServers, | 12 | flushAndRunMultipleServers, |
10 | getMyVideos, | 13 | getMyVideos, |
@@ -32,6 +35,8 @@ describe('Test video transcoding', function () { | |||
32 | servers = await flushAndRunMultipleServers(2) | 35 | servers = await flushAndRunMultipleServers(2) |
33 | 36 | ||
34 | await setAccessTokensToServers(servers) | 37 | await setAccessTokensToServers(servers) |
38 | |||
39 | await doubleFollow(servers[0], servers[1]) | ||
35 | }) | 40 | }) |
36 | 41 | ||
37 | it('Should not transcode video on server 1', async function () { | 42 | it('Should not transcode video on server 1', async function () { |
@@ -46,20 +51,22 @@ describe('Test video transcoding', function () { | |||
46 | 51 | ||
47 | await waitJobs(servers) | 52 | await waitJobs(servers) |
48 | 53 | ||
49 | const res = await getVideosList(servers[0].url) | 54 | for (const server of servers) { |
50 | const video = res.body.data[0] | 55 | const res = await getVideosList(server.url) |
56 | const video = res.body.data[ 0 ] | ||
51 | 57 | ||
52 | const res2 = await getVideo(servers[0].url, video.id) | 58 | const res2 = await getVideo(server.url, video.id) |
53 | const videoDetails = res2.body | 59 | const videoDetails = res2.body |
54 | expect(videoDetails.files).to.have.lengthOf(1) | 60 | expect(videoDetails.files).to.have.lengthOf(1) |
55 | 61 | ||
56 | const magnetUri = videoDetails.files[0].magnetUri | 62 | const magnetUri = videoDetails.files[ 0 ].magnetUri |
57 | expect(magnetUri).to.match(/\.webm/) | 63 | expect(magnetUri).to.match(/\.webm/) |
58 | 64 | ||
59 | const torrent = await webtorrentAdd(magnetUri) | 65 | const torrent = await webtorrentAdd(magnetUri, true) |
60 | expect(torrent.files).to.be.an('array') | 66 | expect(torrent.files).to.be.an('array') |
61 | expect(torrent.files.length).to.equal(1) | 67 | expect(torrent.files.length).to.equal(1) |
62 | expect(torrent.files[0].path).match(/\.webm$/) | 68 | expect(torrent.files[ 0 ].path).match(/\.webm$/) |
69 | } | ||
63 | }) | 70 | }) |
64 | 71 | ||
65 | it('Should transcode video on server 2', async function () { | 72 | it('Should transcode video on server 2', async function () { |
@@ -74,21 +81,112 @@ describe('Test video transcoding', function () { | |||
74 | 81 | ||
75 | await waitJobs(servers) | 82 | await waitJobs(servers) |
76 | 83 | ||
77 | const res = await getVideosList(servers[1].url) | 84 | for (const server of servers) { |
85 | const res = await getVideosList(server.url) | ||
86 | |||
87 | const video = res.body.data.find(v => v.name === videoAttributes.name) | ||
88 | const res2 = await getVideo(server.url, video.id) | ||
89 | const videoDetails = res2.body | ||
90 | |||
91 | expect(videoDetails.files).to.have.lengthOf(4) | ||
92 | |||
93 | const magnetUri = videoDetails.files[ 0 ].magnetUri | ||
94 | expect(magnetUri).to.match(/\.mp4/) | ||
95 | |||
96 | const torrent = await webtorrentAdd(magnetUri, true) | ||
97 | expect(torrent.files).to.be.an('array') | ||
98 | expect(torrent.files.length).to.equal(1) | ||
99 | expect(torrent.files[ 0 ].path).match(/\.mp4$/) | ||
100 | } | ||
101 | }) | ||
102 | |||
103 | it('Should transcode high bit rate mp3 to proper bit rate', async function () { | ||
104 | this.timeout(60000) | ||
105 | |||
106 | const videoAttributes = { | ||
107 | name: 'mp3_256k', | ||
108 | fixture: 'video_short_mp3_256k.mp4' | ||
109 | } | ||
110 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | ||
111 | |||
112 | await waitJobs(servers) | ||
113 | |||
114 | for (const server of servers) { | ||
115 | const res = await getVideosList(server.url) | ||
116 | |||
117 | const video = res.body.data.find(v => v.name === videoAttributes.name) | ||
118 | const res2 = await getVideo(server.url, video.id) | ||
119 | const videoDetails: VideoDetails = res2.body | ||
120 | |||
121 | expect(videoDetails.files).to.have.lengthOf(4) | ||
122 | |||
123 | const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') | ||
124 | const probe = await audio.get(ffmpeg, path) | ||
125 | |||
126 | if (probe.audioStream) { | ||
127 | expect(probe.audioStream[ 'codec_name' ]).to.be.equal('aac') | ||
128 | expect(probe.audioStream[ 'bit_rate' ]).to.be.at.most(384 * 8000) | ||
129 | } else { | ||
130 | this.fail('Could not retrieve the audio stream on ' + probe.absolutePath) | ||
131 | } | ||
132 | } | ||
133 | }) | ||
134 | |||
135 | it('Should transcode video with no audio and have no audio itself', async function () { | ||
136 | this.timeout(60000) | ||
137 | |||
138 | const videoAttributes = { | ||
139 | name: 'no_audio', | ||
140 | fixture: 'video_short_no_audio.mp4' | ||
141 | } | ||
142 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | ||
143 | |||
144 | await waitJobs(servers) | ||
145 | |||
146 | for (const server of servers) { | ||
147 | const res = await getVideosList(server.url) | ||
148 | |||
149 | const video = res.body.data.find(v => v.name === videoAttributes.name) | ||
150 | const res2 = await getVideo(server.url, video.id) | ||
151 | const videoDetails: VideoDetails = res2.body | ||
152 | |||
153 | expect(videoDetails.files).to.have.lengthOf(4) | ||
154 | const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') | ||
155 | const probe = await audio.get(ffmpeg, path) | ||
156 | expect(probe).to.not.have.property('audioStream') | ||
157 | } | ||
158 | }) | ||
159 | |||
160 | it('Should leave the audio untouched, but properly transcode the video', async function () { | ||
161 | this.timeout(60000) | ||
162 | |||
163 | const videoAttributes = { | ||
164 | name: 'untouched_audio', | ||
165 | fixture: 'video_short.mp4' | ||
166 | } | ||
167 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | ||
78 | 168 | ||
79 | const video = res.body.data[0] | 169 | await waitJobs(servers) |
80 | const res2 = await getVideo(servers[1].url, video.id) | ||
81 | const videoDetails = res2.body | ||
82 | 170 | ||
83 | expect(videoDetails.files).to.have.lengthOf(4) | 171 | for (const server of servers) { |
172 | const res = await getVideosList(server.url) | ||
84 | 173 | ||
85 | const magnetUri = videoDetails.files[0].magnetUri | 174 | const video = res.body.data.find(v => v.name === videoAttributes.name) |
86 | expect(magnetUri).to.match(/\.mp4/) | 175 | const res2 = await getVideo(server.url, video.id) |
176 | const videoDetails: VideoDetails = res2.body | ||
87 | 177 | ||
88 | const torrent = await webtorrentAdd(magnetUri) | 178 | expect(videoDetails.files).to.have.lengthOf(4) |
89 | expect(torrent.files).to.be.an('array') | 179 | const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) |
90 | expect(torrent.files.length).to.equal(1) | 180 | const fixtureVideoProbe = await audio.get(ffmpeg, fixturePath) |
91 | expect(torrent.files[0].path).match(/\.mp4$/) | 181 | const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') |
182 | const videoProbe = await audio.get(ffmpeg, path) | ||
183 | if (videoProbe.audioStream && fixtureVideoProbe.audioStream) { | ||
184 | const toOmit = [ 'max_bit_rate', 'duration', 'duration_ts', 'nb_frames', 'start_time', 'start_pts' ] | ||
185 | expect(omit(videoProbe.audioStream, toOmit)).to.be.deep.equal(omit(fixtureVideoProbe.audioStream, toOmit)) | ||
186 | } else { | ||
187 | this.fail('Could not retrieve the audio stream on ' + videoProbe.absolutePath) | ||
188 | } | ||
189 | } | ||
92 | }) | 190 | }) |
93 | 191 | ||
94 | it('Should transcode a 60 FPS video', async function () { | 192 | it('Should transcode a 60 FPS video', async function () { |
@@ -103,38 +201,36 @@ describe('Test video transcoding', function () { | |||
103 | 201 | ||
104 | await waitJobs(servers) | 202 | await waitJobs(servers) |
105 | 203 | ||
106 | const res = await getVideosList(servers[1].url) | 204 | for (const server of servers) { |
205 | const res = await getVideosList(server.url) | ||
206 | |||
207 | const video = res.body.data.find(v => v.name === videoAttributes.name) | ||
208 | const res2 = await getVideo(server.url, video.id) | ||
209 | const videoDetails: VideoDetails = res2.body | ||
210 | |||
211 | expect(videoDetails.files).to.have.lengthOf(4) | ||
212 | expect(videoDetails.files[ 0 ].fps).to.be.above(58).and.below(62) | ||
213 | expect(videoDetails.files[ 1 ].fps).to.be.below(31) | ||
214 | expect(videoDetails.files[ 2 ].fps).to.be.below(31) | ||
215 | expect(videoDetails.files[ 3 ].fps).to.be.below(31) | ||
107 | 216 | ||
108 | const video = res.body.data[0] | 217 | for (const resolution of [ '240', '360', '480' ]) { |
109 | const res2 = await getVideo(servers[1].url, video.id) | 218 | const path = join(root(), 'test2', 'videos', video.uuid + '-' + resolution + '.mp4') |
110 | const videoDetails: VideoDetails = res2.body | 219 | const fps = await getVideoFileFPS(path) |
111 | 220 | ||
112 | expect(videoDetails.files).to.have.lengthOf(4) | 221 | expect(fps).to.be.below(31) |
113 | expect(videoDetails.files[0].fps).to.be.above(58).and.below(62) | 222 | } |
114 | expect(videoDetails.files[1].fps).to.be.below(31) | ||
115 | expect(videoDetails.files[2].fps).to.be.below(31) | ||
116 | expect(videoDetails.files[3].fps).to.be.below(31) | ||
117 | 223 | ||
118 | for (const resolution of [ '240', '360', '480' ]) { | 224 | const path = join(root(), 'test2', 'videos', video.uuid + '-720.mp4') |
119 | const path = join(root(), 'test2', 'videos', video.uuid + '-' + resolution + '.mp4') | ||
120 | const fps = await getVideoFileFPS(path) | 225 | const fps = await getVideoFileFPS(path) |
121 | 226 | ||
122 | expect(fps).to.be.below(31) | 227 | expect(fps).to.be.above(58).and.below(62) |
123 | } | 228 | } |
124 | |||
125 | const path = join(root(), 'test2', 'videos', video.uuid + '-720.mp4') | ||
126 | const fps = await getVideoFileFPS(path) | ||
127 | |||
128 | expect(fps).to.be.above(58).and.below(62) | ||
129 | }) | 229 | }) |
130 | 230 | ||
131 | it('Should wait transcoding before publishing the video', async function () { | 231 | it('Should wait transcoding before publishing the video', async function () { |
132 | this.timeout(80000) | 232 | this.timeout(80000) |
133 | 233 | ||
134 | await doubleFollow(servers[0], servers[1]) | ||
135 | |||
136 | await waitJobs(servers) | ||
137 | |||
138 | { | 234 | { |
139 | // Upload the video, but wait transcoding | 235 | // Upload the video, but wait transcoding |
140 | const videoAttributes = { | 236 | const videoAttributes = { |
@@ -154,7 +250,7 @@ describe('Test video transcoding', function () { | |||
154 | 250 | ||
155 | // Should have my video | 251 | // Should have my video |
156 | const resMyVideos = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 10) | 252 | const resMyVideos = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 10) |
157 | const videoToFindInMine = resMyVideos.body.data.find(v => v.name === 'waiting video') | 253 | const videoToFindInMine = resMyVideos.body.data.find(v => v.name === videoAttributes.name) |
158 | expect(videoToFindInMine).not.to.be.undefined | 254 | expect(videoToFindInMine).not.to.be.undefined |
159 | expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE) | 255 | expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE) |
160 | expect(videoToFindInMine.state.label).to.equal('To transcode') | 256 | expect(videoToFindInMine.state.label).to.equal('To transcode') |
@@ -162,7 +258,7 @@ describe('Test video transcoding', function () { | |||
162 | 258 | ||
163 | // Should not list this video | 259 | // Should not list this video |
164 | const resVideos = await getVideosList(servers[1].url) | 260 | const resVideos = await getVideosList(servers[1].url) |
165 | const videoToFindInList = resVideos.body.data.find(v => v.name === 'waiting video') | 261 | const videoToFindInList = resVideos.body.data.find(v => v.name === videoAttributes.name) |
166 | expect(videoToFindInList).to.be.undefined | 262 | expect(videoToFindInList).to.be.undefined |
167 | 263 | ||
168 | // Server 1 should not have the video yet | 264 | // Server 1 should not have the video yet |