]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
590fb506 | 2 | |
590fb506 | 3 | import 'mocha' |
62549e6c | 4 | import { expect } from 'chai' |
1740952b | 5 | import { pathExists, readdir, remove } from 'fs-extra' |
62549e6c | 6 | import { join } from 'path' |
c55e3d72 C |
7 | import { FIXTURE_URLS, testCaptionFile, testImage } from '@server/tests/shared' |
8 | import { areHttpImportTestsDisabled } from '@shared/core-utils' | |
9 | import { VideoPrivacy, VideoResolution } from '@shared/models' | |
590fb506 | 10 | import { |
7c3b7976 | 11 | cleanupTests, |
254d3579 | 12 | createMultipleServers, |
62549e6c | 13 | createSingleServer, |
59bbcced | 14 | doubleFollow, |
254d3579 | 15 | PeerTubeServer, |
b488ba1e | 16 | setAccessTokensToServers, |
62549e6c | 17 | setDefaultVideoChannel, |
6910f20f | 18 | waitJobs |
bf54587a | 19 | } from '@shared/server-commands' |
590fb506 | 20 | |
62549e6c C |
21 | async function checkVideosServer1 (server: PeerTubeServer, idHttp: string, idMagnet: string, idTorrent: string) { |
22 | const videoHttp = await server.videos.get({ id: idHttp }) | |
23 | ||
24 | expect(videoHttp.name).to.equal('small video - youtube') | |
25 | // FIXME: youtube-dl seems broken | |
26 | // expect(videoHttp.category.label).to.equal('News & Politics') | |
27 | // expect(videoHttp.licence.label).to.equal('Attribution') | |
28 | expect(videoHttp.language.label).to.equal('Unknown') | |
29 | expect(videoHttp.nsfw).to.be.false | |
30 | expect(videoHttp.description).to.equal('this is a super description') | |
31 | expect(videoHttp.tags).to.deep.equal([ 'tag1', 'tag2' ]) | |
32 | expect(videoHttp.files).to.have.lengthOf(1) | |
33 | ||
34 | const originallyPublishedAt = new Date(videoHttp.originallyPublishedAt) | |
35 | expect(originallyPublishedAt.getDate()).to.equal(14) | |
36 | expect(originallyPublishedAt.getMonth()).to.equal(0) | |
37 | expect(originallyPublishedAt.getFullYear()).to.equal(2019) | |
38 | ||
39 | const videoMagnet = await server.videos.get({ id: idMagnet }) | |
40 | const videoTorrent = await server.videos.get({ id: idTorrent }) | |
41 | ||
42 | for (const video of [ videoMagnet, videoTorrent ]) { | |
43 | expect(video.category.label).to.equal('Misc') | |
44 | expect(video.licence.label).to.equal('Unknown') | |
45 | expect(video.language.label).to.equal('Unknown') | |
46 | expect(video.nsfw).to.be.false | |
47 | expect(video.description).to.equal('this is a super torrent description') | |
48 | expect(video.tags).to.deep.equal([ 'tag_torrent1', 'tag_torrent2' ]) | |
49 | expect(video.files).to.have.lengthOf(1) | |
50 | } | |
51 | ||
52 | expect(videoTorrent.name).to.contain('你好 世界 720p.mp4') | |
53 | expect(videoMagnet.name).to.contain('super peertube2 video') | |
54 | ||
55 | const bodyCaptions = await server.captions.list({ videoId: idHttp }) | |
56 | expect(bodyCaptions.total).to.equal(2) | |
57 | } | |
58 | ||
59 | async function checkVideoServer2 (server: PeerTubeServer, id: number | string) { | |
60 | const video = await server.videos.get({ id }) | |
61 | ||
62 | expect(video.name).to.equal('my super name') | |
63 | expect(video.category.label).to.equal('Entertainment') | |
64 | expect(video.licence.label).to.equal('Public Domain Dedication') | |
65 | expect(video.language.label).to.equal('English') | |
66 | expect(video.nsfw).to.be.false | |
67 | expect(video.description).to.equal('my super description') | |
68 | expect(video.tags).to.deep.equal([ 'supertag1', 'supertag2' ]) | |
69 | ||
70 | expect(video.files).to.have.lengthOf(1) | |
71 | ||
72 | const bodyCaptions = await server.captions.list({ videoId: id }) | |
73 | expect(bodyCaptions.total).to.equal(2) | |
74 | } | |
590fb506 C |
75 | |
76 | describe('Test video imports', function () { | |
590fb506 | 77 | |
b488ba1e C |
78 | if (areHttpImportTestsDisabled()) return |
79 | ||
62549e6c | 80 | function runSuite (mode: 'youtube-dl' | 'yt-dlp') { |
590fb506 | 81 | |
62549e6c C |
82 | describe('Import ' + mode, function () { |
83 | let servers: PeerTubeServer[] = [] | |
652c6416 | 84 | |
62549e6c C |
85 | before(async function () { |
86 | this.timeout(30_000) | |
590fb506 | 87 | |
62549e6c C |
88 | // Run servers |
89 | servers = await createMultipleServers(2, { | |
90 | import: { | |
91 | videos: { | |
92 | http: { | |
93 | youtube_dl_release: { | |
94 | url: mode === 'youtube-dl' | |
95 | ? 'https://yt-dl.org/downloads/latest/youtube-dl' | |
96 | : 'https://api.github.com/repos/yt-dlp/yt-dlp/releases', | |
590fb506 | 97 | |
62549e6c C |
98 | name: mode |
99 | } | |
100 | } | |
101 | } | |
102 | } | |
103 | }) | |
590fb506 | 104 | |
62549e6c C |
105 | await setAccessTokensToServers(servers) |
106 | await setDefaultVideoChannel(servers) | |
652c6416 | 107 | |
62549e6c C |
108 | await doubleFollow(servers[0], servers[1]) |
109 | }) | |
590fb506 | 110 | |
62549e6c C |
111 | it('Should import videos on server 1', async function () { |
112 | this.timeout(60_000) | |
590fb506 | 113 | |
62549e6c C |
114 | const baseAttributes = { |
115 | channelId: servers[0].store.channel.id, | |
116 | privacy: VideoPrivacy.PUBLIC | |
117 | } | |
590fb506 | 118 | |
62549e6c C |
119 | { |
120 | const attributes = { ...baseAttributes, targetUrl: FIXTURE_URLS.youtube } | |
121 | const { video } = await servers[0].imports.importVideo({ attributes }) | |
122 | expect(video.name).to.equal('small video - youtube') | |
590fb506 | 123 | |
62549e6c C |
124 | { |
125 | expect(video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`)) | |
126 | expect(video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`)) | |
590fb506 | 127 | |
62549e6c C |
128 | const suffix = mode === 'yt-dlp' |
129 | ? '_yt_dlp' | |
130 | : '' | |
590fb506 | 131 | |
62549e6c C |
132 | await testImage(servers[0].url, 'video_import_thumbnail' + suffix, video.thumbnailPath) |
133 | await testImage(servers[0].url, 'video_import_preview' + suffix, video.previewPath) | |
134 | } | |
590fb506 | 135 | |
62549e6c C |
136 | const bodyCaptions = await servers[0].captions.list({ videoId: video.id }) |
137 | const videoCaptions = bodyCaptions.data | |
138 | expect(videoCaptions).to.have.lengthOf(2) | |
590fb506 | 139 | |
62549e6c C |
140 | { |
141 | const enCaption = videoCaptions.find(caption => caption.language.id === 'en') | |
142 | expect(enCaption).to.exist | |
143 | expect(enCaption.language.label).to.equal('English') | |
144 | expect(enCaption.captionPath).to.match(new RegExp(`^/lazy-static/video-captions/.+-en.vtt$`)) | |
3e17515e | 145 | |
62549e6c C |
146 | const regex = `WEBVTT[ \n]+Kind: captions[ \n]+Language: en[ \n]+00:00:01.600 --> 00:00:04.200[ \n]+English \\(US\\)[ \n]+` + |
147 | `00:00:05.900 --> 00:00:07.999[ \n]+This is a subtitle in American English[ \n]+` + | |
148 | `00:00:10.000 --> 00:00:14.000[ \n]+Adding subtitles is very easy to do` | |
149 | await testCaptionFile(servers[0].url, enCaption.captionPath, new RegExp(regex)) | |
150 | } | |
53c06121 | 151 | |
62549e6c C |
152 | { |
153 | const frCaption = videoCaptions.find(caption => caption.language.id === 'fr') | |
154 | expect(frCaption).to.exist | |
155 | expect(frCaption.language.label).to.equal('French') | |
156 | expect(frCaption.captionPath).to.match(new RegExp(`^/lazy-static/video-captions/.+-fr.vtt`)) | |
53c06121 | 157 | |
62549e6c C |
158 | const regex = `WEBVTT[ \n]+Kind: captions[ \n]+Language: fr[ \n]+00:00:01.600 --> 00:00:04.200[ \n]+` + |
159 | `Français \\(FR\\)[ \n]+00:00:05.900 --> 00:00:07.999[ \n]+C'est un sous-titre français[ \n]+` + | |
160 | `00:00:10.000 --> 00:00:14.000[ \n]+Ajouter un sous-titre est vraiment facile` | |
ba6e9e8f | 161 | |
62549e6c C |
162 | await testCaptionFile(servers[0].url, frCaption.captionPath, new RegExp(regex)) |
163 | } | |
164 | } | |
ba6e9e8f | 165 | |
62549e6c C |
166 | { |
167 | const attributes = { | |
168 | ...baseAttributes, | |
169 | magnetUri: FIXTURE_URLS.magnet, | |
170 | description: 'this is a super torrent description', | |
171 | tags: [ 'tag_torrent1', 'tag_torrent2' ] | |
172 | } | |
173 | const { video } = await servers[0].imports.importVideo({ attributes }) | |
174 | expect(video.name).to.equal('super peertube2 video') | |
175 | } | |
ba6e9e8f | 176 | |
62549e6c C |
177 | { |
178 | const attributes = { | |
179 | ...baseAttributes, | |
180 | torrentfile: 'video-720p.torrent' as any, | |
181 | description: 'this is a super torrent description', | |
182 | tags: [ 'tag_torrent1', 'tag_torrent2' ] | |
183 | } | |
184 | const { video } = await servers[0].imports.importVideo({ attributes }) | |
185 | expect(video.name).to.equal('你好 世界 720p.mp4') | |
186 | } | |
187 | }) | |
ba6e9e8f | 188 | |
62549e6c C |
189 | it('Should list the videos to import in my videos on server 1', async function () { |
190 | const { total, data } = await servers[0].videos.listMyVideos({ sort: 'createdAt' }) | |
ba6e9e8f | 191 | |
62549e6c | 192 | expect(total).to.equal(3) |
ba6e9e8f | 193 | |
62549e6c C |
194 | expect(data).to.have.lengthOf(3) |
195 | expect(data[0].name).to.equal('small video - youtube') | |
196 | expect(data[1].name).to.equal('super peertube2 video') | |
197 | expect(data[2].name).to.equal('你好 世界 720p.mp4') | |
198 | }) | |
ba6e9e8f | 199 | |
62549e6c C |
200 | it('Should list the videos to import in my imports on server 1', async function () { |
201 | const { total, data: videoImports } = await servers[0].imports.getMyVideoImports({ sort: '-createdAt' }) | |
202 | expect(total).to.equal(3) | |
ba6e9e8f | 203 | |
62549e6c | 204 | expect(videoImports).to.have.lengthOf(3) |
ba6e9e8f | 205 | |
62549e6c C |
206 | expect(videoImports[2].targetUrl).to.equal(FIXTURE_URLS.youtube) |
207 | expect(videoImports[2].magnetUri).to.be.null | |
208 | expect(videoImports[2].torrentName).to.be.null | |
209 | expect(videoImports[2].video.name).to.equal('small video - youtube') | |
3e17515e | 210 | |
62549e6c C |
211 | expect(videoImports[1].targetUrl).to.be.null |
212 | expect(videoImports[1].magnetUri).to.equal(FIXTURE_URLS.magnet) | |
213 | expect(videoImports[1].torrentName).to.be.null | |
214 | expect(videoImports[1].video.name).to.equal('super peertube2 video') | |
3e17515e | 215 | |
62549e6c C |
216 | expect(videoImports[0].targetUrl).to.be.null |
217 | expect(videoImports[0].magnetUri).to.be.null | |
218 | expect(videoImports[0].torrentName).to.equal('video-720p.torrent') | |
219 | expect(videoImports[0].video.name).to.equal('你好 世界 720p.mp4') | |
220 | }) | |
590fb506 | 221 | |
62549e6c C |
222 | it('Should have the video listed on the two instances', async function () { |
223 | this.timeout(120_000) | |
590fb506 | 224 | |
62549e6c | 225 | await waitJobs(servers) |
590fb506 | 226 | |
62549e6c C |
227 | for (const server of servers) { |
228 | const { total, data } = await server.videos.list() | |
229 | expect(total).to.equal(3) | |
230 | expect(data).to.have.lengthOf(3) | |
590fb506 | 231 | |
62549e6c C |
232 | const [ videoHttp, videoMagnet, videoTorrent ] = data |
233 | await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) | |
234 | } | |
235 | }) | |
236 | ||
237 | it('Should import a video on server 2 with some fields', async function () { | |
238 | this.timeout(60_000) | |
239 | ||
240 | const attributes = { | |
241 | targetUrl: FIXTURE_URLS.youtube, | |
242 | channelId: servers[1].store.channel.id, | |
243 | privacy: VideoPrivacy.PUBLIC, | |
244 | category: 10, | |
245 | licence: 7, | |
246 | language: 'en', | |
247 | name: 'my super name', | |
248 | description: 'my super description', | |
249 | tags: [ 'supertag1', 'supertag2' ] | |
250 | } | |
251 | const { video } = await servers[1].imports.importVideo({ attributes }) | |
252 | expect(video.name).to.equal('my super name') | |
253 | }) | |
3e17515e | 254 | |
62549e6c C |
255 | it('Should have the videos listed on the two instances', async function () { |
256 | this.timeout(120_000) | |
3e17515e | 257 | |
62549e6c | 258 | await waitJobs(servers) |
590fb506 | 259 | |
62549e6c C |
260 | for (const server of servers) { |
261 | const { total, data } = await server.videos.list() | |
262 | expect(total).to.equal(4) | |
263 | expect(data).to.have.lengthOf(4) | |
590fb506 | 264 | |
62549e6c | 265 | await checkVideoServer2(server, data[0].uuid) |
590fb506 | 266 | |
62549e6c C |
267 | const [ , videoHttp, videoMagnet, videoTorrent ] = data |
268 | await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) | |
269 | } | |
270 | }) | |
590fb506 | 271 | |
62549e6c C |
272 | it('Should import a video that will be transcoded', async function () { |
273 | this.timeout(240_000) | |
590fb506 | 274 | |
62549e6c C |
275 | const attributes = { |
276 | name: 'transcoded video', | |
277 | magnetUri: FIXTURE_URLS.magnet, | |
278 | channelId: servers[1].store.channel.id, | |
279 | privacy: VideoPrivacy.PUBLIC | |
280 | } | |
281 | const { video } = await servers[1].imports.importVideo({ attributes }) | |
282 | const videoUUID = video.uuid | |
590fb506 | 283 | |
62549e6c | 284 | await waitJobs(servers) |
590fb506 | 285 | |
62549e6c C |
286 | for (const server of servers) { |
287 | const video = await server.videos.get({ id: videoUUID }) | |
590fb506 | 288 | |
62549e6c C |
289 | expect(video.name).to.equal('transcoded video') |
290 | expect(video.files).to.have.lengthOf(4) | |
291 | } | |
292 | }) | |
293 | ||
294 | it('Should import no HDR version on a HDR video', async function () { | |
295 | this.timeout(300_000) | |
296 | ||
297 | const config = { | |
298 | transcoding: { | |
299 | enabled: true, | |
300 | resolutions: { | |
8dd754c7 | 301 | '144p': true, |
62549e6c C |
302 | '240p': true, |
303 | '360p': false, | |
304 | '480p': false, | |
305 | '720p': false, | |
306 | '1080p': false, // the resulting resolution shouldn't be higher than this, and not vp9.2/av01 | |
307 | '1440p': false, | |
308 | '2160p': false | |
309 | }, | |
310 | webtorrent: { enabled: true }, | |
311 | hls: { enabled: false } | |
312 | }, | |
313 | import: { | |
314 | videos: { | |
315 | http: { | |
316 | enabled: true | |
317 | }, | |
318 | torrent: { | |
319 | enabled: true | |
320 | } | |
321 | } | |
322 | } | |
323 | } | |
324 | await servers[0].config.updateCustomSubConfig({ newConfig: config }) | |
590fb506 | 325 | |
62549e6c C |
326 | const attributes = { |
327 | name: 'hdr video', | |
328 | targetUrl: FIXTURE_URLS.youtubeHDR, | |
329 | channelId: servers[0].store.channel.id, | |
330 | privacy: VideoPrivacy.PUBLIC | |
331 | } | |
332 | const { video: videoImported } = await servers[0].imports.importVideo({ attributes }) | |
333 | const videoUUID = videoImported.uuid | |
334 | ||
335 | await waitJobs(servers) | |
336 | ||
337 | // test resolution | |
338 | const video = await servers[0].videos.get({ id: videoUUID }) | |
339 | expect(video.name).to.equal('hdr video') | |
340 | const maxResolution = Math.max.apply(Math, video.files.map(function (o) { return o.resolution.id })) | |
341 | expect(maxResolution, 'expected max resolution not met').to.equals(VideoResolution.H_240P) | |
342 | }) | |
343 | ||
344 | it('Should import a peertube video', async function () { | |
345 | this.timeout(120_000) | |
346 | ||
5480933b C |
347 | const toTest = [ FIXTURE_URLS.peertube_long ] |
348 | ||
62549e6c | 349 | // TODO: include peertube_short when https://github.com/ytdl-org/youtube-dl/pull/29475 is merged |
5480933b C |
350 | if (mode === 'yt-dlp') { |
351 | toTest.push(FIXTURE_URLS.peertube_short) | |
352 | } | |
353 | ||
354 | for (const targetUrl of toTest) { | |
62549e6c C |
355 | await servers[0].config.disableTranscoding() |
356 | ||
357 | const attributes = { | |
358 | targetUrl, | |
359 | channelId: servers[0].store.channel.id, | |
360 | privacy: VideoPrivacy.PUBLIC | |
361 | } | |
362 | const { video } = await servers[0].imports.importVideo({ attributes }) | |
363 | const videoUUID = video.uuid | |
590fb506 | 364 | |
62549e6c | 365 | await waitJobs(servers) |
590fb506 | 366 | |
62549e6c C |
367 | for (const server of servers) { |
368 | const video = await server.videos.get({ id: videoUUID }) | |
3e17515e | 369 | |
62549e6c C |
370 | expect(video.name).to.equal('E2E tests') |
371 | } | |
372 | } | |
373 | }) | |
3e17515e | 374 | |
62549e6c C |
375 | after(async function () { |
376 | await cleanupTests(servers) | |
377 | }) | |
378 | }) | |
379 | } | |
3e17515e | 380 | |
62549e6c | 381 | runSuite('youtube-dl') |
3e17515e | 382 | |
62549e6c | 383 | runSuite('yt-dlp') |
3e17515e | 384 | |
62549e6c C |
385 | describe('Auto update', function () { |
386 | let server: PeerTubeServer | |
3e17515e | 387 | |
62549e6c C |
388 | function quickPeerTubeImport () { |
389 | const attributes = { | |
390 | targetUrl: FIXTURE_URLS.peertube_long, | |
391 | channelId: server.store.channel.id, | |
392 | privacy: VideoPrivacy.PUBLIC | |
393 | } | |
394 | ||
395 | return server.imports.importVideo({ attributes }) | |
590fb506 | 396 | } |
590fb506 | 397 | |
62549e6c C |
398 | async function testBinaryUpdate (releaseUrl: string, releaseName: string) { |
399 | await remove(join(server.servers.buildDirectory('bin'), releaseName)) | |
400 | ||
401 | await server.kill() | |
402 | await server.run({ | |
403 | import: { | |
404 | videos: { | |
405 | http: { | |
406 | youtube_dl_release: { | |
407 | url: releaseUrl, | |
408 | name: releaseName | |
409 | } | |
410 | } | |
454c20fa RK |
411 | } |
412 | } | |
62549e6c C |
413 | }) |
414 | ||
415 | await quickPeerTubeImport() | |
454c20fa | 416 | |
1740952b C |
417 | const base = server.servers.buildDirectory('bin') |
418 | const content = await readdir(base) | |
419 | const binaryPath = join(base, releaseName) | |
420 | ||
421 | expect(await pathExists(binaryPath), `${binaryPath} does not exist in ${base} (${content.join(', ')})`).to.be.true | |
454c20fa | 422 | } |
454c20fa | 423 | |
62549e6c C |
424 | before(async function () { |
425 | this.timeout(30_000) | |
454c20fa | 426 | |
62549e6c C |
427 | // Run servers |
428 | server = await createSingleServer(1) | |
454c20fa | 429 | |
62549e6c C |
430 | await setAccessTokensToServers([ server ]) |
431 | await setDefaultVideoChannel([ server ]) | |
432 | }) | |
e3c9ea72 | 433 | |
62549e6c C |
434 | it('Should update youtube-dl from github URL', async function () { |
435 | this.timeout(120_000) | |
e3c9ea72 | 436 | |
62549e6c C |
437 | await testBinaryUpdate('https://api.github.com/repos/ytdl-org/youtube-dl/releases', 'youtube-dl') |
438 | }) | |
e3c9ea72 | 439 | |
62549e6c C |
440 | it('Should update youtube-dl from raw URL', async function () { |
441 | this.timeout(120_000) | |
e3c9ea72 | 442 | |
62549e6c C |
443 | await testBinaryUpdate('https://yt-dl.org/downloads/latest/youtube-dl', 'youtube-dl') |
444 | }) | |
e3c9ea72 | 445 | |
62549e6c C |
446 | it('Should update youtube-dl from youtube-dl fork', async function () { |
447 | this.timeout(120_000) | |
e3c9ea72 | 448 | |
62549e6c C |
449 | await testBinaryUpdate('https://api.github.com/repos/yt-dlp/yt-dlp/releases', 'yt-dlp') |
450 | }) | |
60409162 C |
451 | |
452 | after(async function () { | |
453 | await cleanupTests([ server ]) | |
454 | }) | |
590fb506 C |
455 | }) |
456 | }) |