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