]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
590fb506 | 2 | |
590fb506 | 3 | import 'mocha' |
b488ba1e | 4 | import * as chai from 'chai' |
590fb506 | 5 | import { |
7c3b7976 | 6 | cleanupTests, |
590fb506 C |
7 | doubleFollow, |
8 | flushAndRunMultipleServers, | |
9 | getMyUserInformation, | |
10 | getMyVideos, | |
11 | getVideo, | |
12 | getVideosList, | |
3e17515e | 13 | immutableAssign, |
b488ba1e | 14 | listVideoCaptions, |
590fb506 | 15 | ServerInfo, |
b488ba1e | 16 | setAccessTokensToServers, |
454c20fa RK |
17 | testCaptionFile, |
18 | updateCustomSubConfig | |
94565d52 | 19 | } from '../../../../shared/extra-utils' |
b488ba1e | 20 | import { areHttpImportTestsDisabled, testImage } from '../../../../shared/extra-utils/miscs/miscs' |
94565d52 | 21 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
454c20fa RK |
22 | import { |
23 | getMagnetURI, | |
24 | getMyVideoImports, | |
25 | getYoutubeHDRVideoUrl, | |
26 | getYoutubeVideoUrl, | |
27 | importVideo | |
28 | } from '../../../../shared/extra-utils/videos/video-imports' | |
29 | import { VideoCaption, VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos' | |
590fb506 C |
30 | |
31 | const expect = chai.expect | |
32 | ||
33 | describe('Test video imports', function () { | |
34 | let servers: ServerInfo[] = [] | |
35 | let channelIdServer1: number | |
36 | let channelIdServer2: number | |
37 | ||
b488ba1e C |
38 | if (areHttpImportTestsDisabled()) return |
39 | ||
3e17515e C |
40 | async function checkVideosServer1 (url: string, idHttp: string, idMagnet: string, idTorrent: string) { |
41 | const resHttp = await getVideo(url, idHttp) | |
42 | const videoHttp: VideoDetails = resHttp.body | |
43 | ||
44 | expect(videoHttp.name).to.equal('small video - youtube') | |
f9b6d51f C |
45 | // FIXME: youtube-dl seems broken |
46 | // expect(videoHttp.category.label).to.equal('News & Politics') | |
1dee8d68 | 47 | // expect(videoHttp.licence.label).to.equal('Attribution') |
3e17515e C |
48 | expect(videoHttp.language.label).to.equal('Unknown') |
49 | expect(videoHttp.nsfw).to.be.false | |
50 | expect(videoHttp.description).to.equal('this is a super description') | |
51 | expect(videoHttp.tags).to.deep.equal([ 'tag1', 'tag2' ]) | |
52 | expect(videoHttp.files).to.have.lengthOf(1) | |
17036be5 C |
53 | |
54 | const originallyPublishedAt = new Date(videoHttp.originallyPublishedAt) | |
55 | expect(originallyPublishedAt.getDate()).to.equal(14) | |
56 | expect(originallyPublishedAt.getMonth()).to.equal(0) | |
57 | expect(originallyPublishedAt.getFullYear()).to.equal(2019) | |
3e17515e C |
58 | |
59 | const resMagnet = await getVideo(url, idMagnet) | |
60 | const videoMagnet: VideoDetails = resMagnet.body | |
61 | const resTorrent = await getVideo(url, idTorrent) | |
62 | const videoTorrent: VideoDetails = resTorrent.body | |
63 | ||
64 | for (const video of [ videoMagnet, videoTorrent ]) { | |
65 | expect(video.category.label).to.equal('Misc') | |
66 | expect(video.licence.label).to.equal('Unknown') | |
67 | expect(video.language.label).to.equal('Unknown') | |
68 | expect(video.nsfw).to.be.false | |
69 | expect(video.description).to.equal('this is a super torrent description') | |
70 | expect(video.tags).to.deep.equal([ 'tag_torrent1', 'tag_torrent2' ]) | |
71 | expect(video.files).to.have.lengthOf(1) | |
72 | } | |
590fb506 | 73 | |
3e17515e C |
74 | expect(videoTorrent.name).to.contain('你好 世界 720p.mp4') |
75 | expect(videoMagnet.name).to.contain('super peertube2 video') | |
652c6416 C |
76 | |
77 | const resCaptions = await listVideoCaptions(url, idHttp) | |
78 | expect(resCaptions.body.total).to.equal(2) | |
590fb506 C |
79 | } |
80 | ||
81 | async function checkVideoServer2 (url: string, id: number | string) { | |
82 | const res = await getVideo(url, id) | |
652c6416 | 83 | const video: VideoDetails = res.body |
590fb506 C |
84 | |
85 | expect(video.name).to.equal('my super name') | |
86 | expect(video.category.label).to.equal('Entertainment') | |
87 | expect(video.licence.label).to.equal('Public Domain Dedication') | |
88 | expect(video.language.label).to.equal('English') | |
89 | expect(video.nsfw).to.be.false | |
90 | expect(video.description).to.equal('my super description') | |
91 | expect(video.tags).to.deep.equal([ 'supertag1', 'supertag2' ]) | |
92 | ||
93 | expect(video.files).to.have.lengthOf(1) | |
652c6416 C |
94 | |
95 | const resCaptions = await listVideoCaptions(url, id) | |
96 | expect(resCaptions.body.total).to.equal(2) | |
590fb506 C |
97 | } |
98 | ||
99 | before(async function () { | |
454c20fa | 100 | this.timeout(30_000) |
590fb506 C |
101 | |
102 | // Run servers | |
103 | servers = await flushAndRunMultipleServers(2) | |
104 | ||
105 | await setAccessTokensToServers(servers) | |
106 | ||
107 | { | |
108 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | |
a1587156 | 109 | channelIdServer1 = res.body.videoChannels[0].id |
590fb506 C |
110 | } |
111 | ||
112 | { | |
113 | const res = await getMyUserInformation(servers[1].url, servers[1].accessToken) | |
a1587156 | 114 | channelIdServer2 = res.body.videoChannels[0].id |
590fb506 C |
115 | } |
116 | ||
117 | await doubleFollow(servers[0], servers[1]) | |
118 | }) | |
119 | ||
3e17515e | 120 | it('Should import videos on server 1', async function () { |
454c20fa | 121 | this.timeout(60_000) |
590fb506 | 122 | |
3e17515e | 123 | const baseAttributes = { |
590fb506 C |
124 | channelId: channelIdServer1, |
125 | privacy: VideoPrivacy.PUBLIC | |
126 | } | |
3e17515e C |
127 | |
128 | { | |
129 | const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }) | |
130 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | |
131 | expect(res.body.video.name).to.equal('small video - youtube') | |
53c06121 C |
132 | |
133 | expect(res.body.video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`)) | |
134 | expect(res.body.video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`)) | |
135 | ||
b1770a0a K |
136 | await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath) |
137 | await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath) | |
ba6e9e8f | 138 | |
139 | const resCaptions = await listVideoCaptions(servers[0].url, res.body.video.id) | |
652c6416 | 140 | const videoCaptions: VideoCaption[] = resCaptions.body.data |
ba6e9e8f | 141 | expect(videoCaptions).to.have.lengthOf(2) |
142 | ||
652c6416 C |
143 | const enCaption = videoCaptions.find(caption => caption.language.id === 'en') |
144 | expect(enCaption).to.exist | |
145 | expect(enCaption.language.label).to.equal('English') | |
53c06121 | 146 | expect(enCaption.captionPath).to.match(new RegExp(`^/lazy-static/video-captions/.+-en.vtt$`)) |
ba6e9e8f | 147 | await testCaptionFile(servers[0].url, enCaption.captionPath, `WEBVTT |
652c6416 C |
148 | Kind: captions |
149 | Language: en | |
ba6e9e8f | 150 | |
652c6416 C |
151 | 00:00:01.600 --> 00:00:04.200 |
152 | English (US) | |
ba6e9e8f | 153 | |
652c6416 C |
154 | 00:00:05.900 --> 00:00:07.999 |
155 | This is a subtitle in American English | |
ba6e9e8f | 156 | |
652c6416 C |
157 | 00:00:10.000 --> 00:00:14.000 |
158 | Adding subtitles is very easy to do`) | |
ba6e9e8f | 159 | |
652c6416 C |
160 | const frCaption = videoCaptions.find(caption => caption.language.id === 'fr') |
161 | expect(frCaption).to.exist | |
162 | expect(frCaption.language.label).to.equal('French') | |
53c06121 | 163 | expect(frCaption.captionPath).to.match(new RegExp(`^/lazy-static/video-captions/.+-fr.vtt`)) |
ba6e9e8f | 164 | await testCaptionFile(servers[0].url, frCaption.captionPath, `WEBVTT |
652c6416 C |
165 | Kind: captions |
166 | Language: fr | |
ba6e9e8f | 167 | |
652c6416 C |
168 | 00:00:01.600 --> 00:00:04.200 |
169 | Français (FR) | |
ba6e9e8f | 170 | |
652c6416 C |
171 | 00:00:05.900 --> 00:00:07.999 |
172 | C'est un sous-titre français | |
ba6e9e8f | 173 | |
652c6416 C |
174 | 00:00:10.000 --> 00:00:14.000 |
175 | Ajouter un sous-titre est vraiment facile`) | |
3e17515e C |
176 | } |
177 | ||
178 | { | |
179 | const attributes = immutableAssign(baseAttributes, { | |
180 | magnetUri: getMagnetURI(), | |
181 | description: 'this is a super torrent description', | |
182 | tags: [ 'tag_torrent1', 'tag_torrent2' ] | |
183 | }) | |
184 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | |
185 | expect(res.body.video.name).to.equal('super peertube2 video') | |
186 | } | |
187 | ||
188 | { | |
189 | const attributes = immutableAssign(baseAttributes, { | |
9a7fd960 | 190 | torrentfile: 'video-720p.torrent' as any, |
3e17515e C |
191 | description: 'this is a super torrent description', |
192 | tags: [ 'tag_torrent1', 'tag_torrent2' ] | |
193 | }) | |
194 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | |
195 | expect(res.body.video.name).to.equal('你好 世界 720p.mp4') | |
196 | } | |
590fb506 C |
197 | }) |
198 | ||
3e17515e C |
199 | it('Should list the videos to import in my videos on server 1', async function () { |
200 | const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5, 'createdAt') | |
590fb506 | 201 | |
3e17515e | 202 | expect(res.body.total).to.equal(3) |
590fb506 C |
203 | |
204 | const videos = res.body.data | |
3e17515e | 205 | expect(videos).to.have.lengthOf(3) |
590fb506 | 206 | expect(videos[0].name).to.equal('small video - youtube') |
3e17515e C |
207 | expect(videos[1].name).to.equal('super peertube2 video') |
208 | expect(videos[2].name).to.equal('你好 世界 720p.mp4') | |
590fb506 C |
209 | }) |
210 | ||
3e17515e C |
211 | it('Should list the videos to import in my imports on server 1', async function () { |
212 | const res = await getMyVideoImports(servers[0].url, servers[0].accessToken, '-createdAt') | |
213 | ||
214 | expect(res.body.total).to.equal(3) | |
215 | const videoImports: VideoImport[] = res.body.data | |
216 | expect(videoImports).to.have.lengthOf(3) | |
217 | ||
218 | expect(videoImports[2].targetUrl).to.equal(getYoutubeVideoUrl()) | |
219 | expect(videoImports[2].magnetUri).to.be.null | |
220 | expect(videoImports[2].torrentName).to.be.null | |
221 | expect(videoImports[2].video.name).to.equal('small video - youtube') | |
590fb506 | 222 | |
3e17515e C |
223 | expect(videoImports[1].targetUrl).to.be.null |
224 | expect(videoImports[1].magnetUri).to.equal(getMagnetURI()) | |
225 | expect(videoImports[1].torrentName).to.be.null | |
226 | expect(videoImports[1].video.name).to.equal('super peertube2 video') | |
590fb506 | 227 | |
3e17515e C |
228 | expect(videoImports[0].targetUrl).to.be.null |
229 | expect(videoImports[0].magnetUri).to.be.null | |
230 | expect(videoImports[0].torrentName).to.equal('video-720p.torrent') | |
231 | expect(videoImports[0].video.name).to.equal('你好 世界 720p.mp4') | |
590fb506 C |
232 | }) |
233 | ||
3e17515e | 234 | it('Should have the video listed on the two instances', async function () { |
454c20fa | 235 | this.timeout(120_000) |
590fb506 C |
236 | |
237 | await waitJobs(servers) | |
238 | ||
239 | for (const server of servers) { | |
240 | const res = await getVideosList(server.url) | |
3e17515e C |
241 | expect(res.body.total).to.equal(3) |
242 | expect(res.body.data).to.have.lengthOf(3) | |
590fb506 | 243 | |
3e17515e C |
244 | const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data |
245 | await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) | |
590fb506 C |
246 | } |
247 | }) | |
248 | ||
249 | it('Should import a video on server 2 with some fields', async function () { | |
454c20fa | 250 | this.timeout(60_000) |
590fb506 C |
251 | |
252 | const attributes = { | |
253 | targetUrl: getYoutubeVideoUrl(), | |
3e17515e | 254 | channelId: channelIdServer2, |
590fb506 C |
255 | privacy: VideoPrivacy.PUBLIC, |
256 | category: 10, | |
257 | licence: 7, | |
258 | language: 'en', | |
259 | name: 'my super name', | |
260 | description: 'my super description', | |
261 | tags: [ 'supertag1', 'supertag2' ] | |
262 | } | |
263 | const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) | |
264 | expect(res.body.video.name).to.equal('my super name') | |
265 | }) | |
266 | ||
3e17515e | 267 | it('Should have the videos listed on the two instances', async function () { |
454c20fa | 268 | this.timeout(120_000) |
590fb506 C |
269 | |
270 | await waitJobs(servers) | |
271 | ||
272 | for (const server of servers) { | |
273 | const res = await getVideosList(server.url) | |
3e17515e C |
274 | expect(res.body.total).to.equal(4) |
275 | expect(res.body.data).to.have.lengthOf(4) | |
590fb506 C |
276 | |
277 | await checkVideoServer2(server.url, res.body.data[0].uuid) | |
3e17515e | 278 | |
a1587156 | 279 | const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data |
3e17515e C |
280 | await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) |
281 | } | |
282 | }) | |
283 | ||
284 | it('Should import a video that will be transcoded', async function () { | |
454c20fa | 285 | this.timeout(120_000) |
3e17515e C |
286 | |
287 | const attributes = { | |
288 | name: 'transcoded video', | |
289 | magnetUri: getMagnetURI(), | |
290 | channelId: channelIdServer2, | |
291 | privacy: VideoPrivacy.PUBLIC | |
292 | } | |
293 | const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) | |
294 | const videoUUID = res.body.video.uuid | |
295 | ||
296 | await waitJobs(servers) | |
297 | ||
298 | for (const server of servers) { | |
299 | const res = await getVideo(server.url, videoUUID) | |
300 | const video: VideoDetails = res.body | |
301 | ||
302 | expect(video.name).to.equal('transcoded video') | |
303 | expect(video.files).to.have.lengthOf(4) | |
590fb506 C |
304 | } |
305 | }) | |
306 | ||
454c20fa RK |
307 | it('Should import no HDR version on a HDR video', async function () { |
308 | this.timeout(120_000) | |
309 | ||
310 | const config = { | |
311 | transcoding: { | |
312 | enabled: true, | |
313 | resolutions: { | |
314 | '240p': false, | |
315 | '360p': false, | |
316 | '480p': false, | |
317 | '720p': false, | |
318 | '1080p': true, // the resulting resolution shouldn't be higher than this, and not vp9.2/av01 | |
319 | '1440p': false, | |
320 | '2160p': false | |
321 | }, | |
322 | webtorrent: { enabled: true }, | |
323 | hls: { enabled: false } | |
324 | }, | |
325 | import: { | |
326 | videos: { | |
327 | http: { | |
328 | enabled: true | |
329 | }, | |
330 | torrent: { | |
331 | enabled: true | |
332 | } | |
333 | } | |
334 | } | |
335 | } | |
336 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | |
337 | ||
338 | const attributes = { | |
339 | name: 'hdr video', | |
340 | targetUrl: getYoutubeHDRVideoUrl(), | |
341 | channelId: channelIdServer1, | |
342 | privacy: VideoPrivacy.PUBLIC | |
343 | } | |
344 | const res1 = await importVideo(servers[0].url, servers[0].accessToken, attributes) | |
345 | const videoUUID = res1.body.video.uuid | |
346 | ||
347 | await waitJobs(servers) | |
348 | ||
349 | // test resolution | |
350 | const res2 = await getVideo(servers[0].url, videoUUID) | |
351 | const video: VideoDetails = res2.body | |
352 | expect(video.name).to.equal('hdr video') | |
353 | const maxResolution = Math.max.apply(Math, video.files.map(function (o) { return o.resolution.id })) | |
354 | expect(maxResolution, 'expected max resolution not met').to.equals(VideoResolution.H_1080P) | |
355 | }) | |
356 | ||
7c3b7976 C |
357 | after(async function () { |
358 | await cleanupTests(servers) | |
590fb506 C |
359 | }) |
360 | }) |