diff options
Diffstat (limited to 'packages/tests/src/api/videos/video-imports.ts')
-rw-r--r-- | packages/tests/src/api/videos/video-imports.ts | 634 |
1 files changed, 634 insertions, 0 deletions
diff --git a/packages/tests/src/api/videos/video-imports.ts b/packages/tests/src/api/videos/video-imports.ts new file mode 100644 index 000000000..09efe9931 --- /dev/null +++ b/packages/tests/src/api/videos/video-imports.ts | |||
@@ -0,0 +1,634 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { pathExists, remove } from 'fs-extra/esm' | ||
5 | import { readdir } from 'fs/promises' | ||
6 | import { join } from 'path' | ||
7 | import { areHttpImportTestsDisabled } from '@peertube/peertube-node-utils' | ||
8 | import { CustomConfig, HttpStatusCode, Video, VideoImportState, VideoPrivacy, VideoResolution, VideoState } from '@peertube/peertube-models' | ||
9 | import { | ||
10 | cleanupTests, | ||
11 | createMultipleServers, | ||
12 | createSingleServer, | ||
13 | doubleFollow, | ||
14 | getServerImportConfig, | ||
15 | PeerTubeServer, | ||
16 | setAccessTokensToServers, | ||
17 | setDefaultVideoChannel, | ||
18 | waitJobs | ||
19 | } from '@peertube/peertube-server-commands' | ||
20 | import { DeepPartial } from '@peertube/peertube-typescript-utils' | ||
21 | import { testCaptionFile } from '@tests/shared/captions.js' | ||
22 | import { testImageGeneratedByFFmpeg } from '@tests/shared/checks.js' | ||
23 | import { FIXTURE_URLS } from '@tests/shared/tests.js' | ||
24 | |||
25 | async function checkVideosServer1 (server: PeerTubeServer, idHttp: string, idMagnet: string, idTorrent: string) { | ||
26 | const videoHttp = await server.videos.get({ id: idHttp }) | ||
27 | |||
28 | expect(videoHttp.name).to.equal('small video - youtube') | ||
29 | expect(videoHttp.category.label).to.equal('News & Politics') | ||
30 | expect(videoHttp.licence.label).to.equal('Attribution') | ||
31 | expect(videoHttp.language.label).to.equal('Unknown') | ||
32 | expect(videoHttp.nsfw).to.be.false | ||
33 | expect(videoHttp.description).to.equal('this is a super description') | ||
34 | expect(videoHttp.tags).to.deep.equal([ 'tag1', 'tag2' ]) | ||
35 | expect(videoHttp.files).to.have.lengthOf(1) | ||
36 | |||
37 | const originallyPublishedAt = new Date(videoHttp.originallyPublishedAt) | ||
38 | expect(originallyPublishedAt.getDate()).to.equal(14) | ||
39 | expect(originallyPublishedAt.getMonth()).to.equal(0) | ||
40 | expect(originallyPublishedAt.getFullYear()).to.equal(2019) | ||
41 | |||
42 | const videoMagnet = await server.videos.get({ id: idMagnet }) | ||
43 | const videoTorrent = await server.videos.get({ id: idTorrent }) | ||
44 | |||
45 | for (const video of [ videoMagnet, videoTorrent ]) { | ||
46 | expect(video.category.label).to.equal('Unknown') | ||
47 | expect(video.licence.label).to.equal('Unknown') | ||
48 | expect(video.language.label).to.equal('Unknown') | ||
49 | expect(video.nsfw).to.be.false | ||
50 | expect(video.description).to.equal('this is a super torrent description') | ||
51 | expect(video.tags).to.deep.equal([ 'tag_torrent1', 'tag_torrent2' ]) | ||
52 | expect(video.files).to.have.lengthOf(1) | ||
53 | } | ||
54 | |||
55 | expect(videoTorrent.name).to.contain('你好 世界 720p.mp4') | ||
56 | expect(videoMagnet.name).to.contain('super peertube2 video') | ||
57 | |||
58 | const bodyCaptions = await server.captions.list({ videoId: idHttp }) | ||
59 | expect(bodyCaptions.total).to.equal(2) | ||
60 | } | ||
61 | |||
62 | async function checkVideoServer2 (server: PeerTubeServer, id: number | string) { | ||
63 | const video = await server.videos.get({ id }) | ||
64 | |||
65 | expect(video.name).to.equal('my super name') | ||
66 | expect(video.category.label).to.equal('Entertainment') | ||
67 | expect(video.licence.label).to.equal('Public Domain Dedication') | ||
68 | expect(video.language.label).to.equal('English') | ||
69 | expect(video.nsfw).to.be.false | ||
70 | expect(video.description).to.equal('my super description') | ||
71 | expect(video.tags).to.deep.equal([ 'supertag1', 'supertag2' ]) | ||
72 | |||
73 | await testImageGeneratedByFFmpeg(server.url, 'custom-thumbnail', video.thumbnailPath) | ||
74 | |||
75 | expect(video.files).to.have.lengthOf(1) | ||
76 | |||
77 | const bodyCaptions = await server.captions.list({ videoId: id }) | ||
78 | expect(bodyCaptions.total).to.equal(2) | ||
79 | } | ||
80 | |||
81 | describe('Test video imports', function () { | ||
82 | |||
83 | if (areHttpImportTestsDisabled()) return | ||
84 | |||
85 | function runSuite (mode: 'youtube-dl' | 'yt-dlp') { | ||
86 | |||
87 | describe('Import ' + mode, function () { | ||
88 | let servers: PeerTubeServer[] = [] | ||
89 | |||
90 | before(async function () { | ||
91 | this.timeout(60_000) | ||
92 | |||
93 | servers = await createMultipleServers(2, getServerImportConfig(mode)) | ||
94 | |||
95 | await setAccessTokensToServers(servers) | ||
96 | await setDefaultVideoChannel(servers) | ||
97 | |||
98 | for (const server of servers) { | ||
99 | await server.config.updateExistingSubConfig({ | ||
100 | newConfig: { | ||
101 | transcoding: { | ||
102 | alwaysTranscodeOriginalResolution: false | ||
103 | } | ||
104 | } | ||
105 | }) | ||
106 | } | ||
107 | |||
108 | await doubleFollow(servers[0], servers[1]) | ||
109 | }) | ||
110 | |||
111 | it('Should import videos on server 1', async function () { | ||
112 | this.timeout(60_000) | ||
113 | |||
114 | const baseAttributes = { | ||
115 | channelId: servers[0].store.channel.id, | ||
116 | privacy: VideoPrivacy.PUBLIC | ||
117 | } | ||
118 | |||
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') | ||
123 | |||
124 | { | ||
125 | expect(video.thumbnailPath).to.match(new RegExp(`^/lazy-static/thumbnails/.+.jpg$`)) | ||
126 | expect(video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`)) | ||
127 | |||
128 | const suffix = mode === 'yt-dlp' | ||
129 | ? '_yt_dlp' | ||
130 | : '' | ||
131 | |||
132 | await testImageGeneratedByFFmpeg(servers[0].url, 'video_import_thumbnail' + suffix, video.thumbnailPath) | ||
133 | await testImageGeneratedByFFmpeg(servers[0].url, 'video_import_preview' + suffix, video.previewPath) | ||
134 | } | ||
135 | |||
136 | const bodyCaptions = await servers[0].captions.list({ videoId: video.id }) | ||
137 | const videoCaptions = bodyCaptions.data | ||
138 | expect(videoCaptions).to.have.lengthOf(2) | ||
139 | |||
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$`)) | ||
145 | |||
146 | const regex = `WEBVTT[ \n]+Kind: captions[ \n]+` + | ||
147 | `(Language: en[ \n]+)?` + | ||
148 | `00:00:01.600 --> 00:00:04.200( position:\\d+% line:\\d+%)?[ \n]+English \\(US\\)[ \n]+` + | ||
149 | `00:00:05.900 --> 00:00:07.999( position:\\d+% line:\\d+%)?[ \n]+This is a subtitle in American English[ \n]+` + | ||
150 | `00:00:10.000 --> 00:00:14.000( position:\\d+% line:\\d+%)?[ \n]+Adding subtitles is very easy to do` | ||
151 | await testCaptionFile(servers[0].url, enCaption.captionPath, new RegExp(regex)) | ||
152 | } | ||
153 | |||
154 | { | ||
155 | const frCaption = videoCaptions.find(caption => caption.language.id === 'fr') | ||
156 | expect(frCaption).to.exist | ||
157 | expect(frCaption.language.label).to.equal('French') | ||
158 | expect(frCaption.captionPath).to.match(new RegExp(`^/lazy-static/video-captions/.+-fr.vtt`)) | ||
159 | |||
160 | const regex = `WEBVTT[ \n]+Kind: captions[ \n]+` + | ||
161 | `(Language: fr[ \n]+)?` + | ||
162 | `00:00:01.600 --> 00:00:04.200( position:\\d+% line:\\d+%)?[ \n]+Français \\(FR\\)[ \n]+` + | ||
163 | `00:00:05.900 --> 00:00:07.999( position:\\d+% line:\\d+%)?[ \n]+C'est un sous-titre français[ \n]+` + | ||
164 | `00:00:10.000 --> 00:00:14.000( position:\\d+% line:\\d+%)?[ \n]+Ajouter un sous-titre est vraiment facile` | ||
165 | |||
166 | await testCaptionFile(servers[0].url, frCaption.captionPath, new RegExp(regex)) | ||
167 | } | ||
168 | } | ||
169 | |||
170 | { | ||
171 | const attributes = { | ||
172 | ...baseAttributes, | ||
173 | magnetUri: FIXTURE_URLS.magnet, | ||
174 | description: 'this is a super torrent description', | ||
175 | tags: [ 'tag_torrent1', 'tag_torrent2' ] | ||
176 | } | ||
177 | const { video } = await servers[0].imports.importVideo({ attributes }) | ||
178 | expect(video.name).to.equal('super peertube2 video') | ||
179 | } | ||
180 | |||
181 | { | ||
182 | const attributes = { | ||
183 | ...baseAttributes, | ||
184 | torrentfile: 'video-720p.torrent' as any, | ||
185 | description: 'this is a super torrent description', | ||
186 | tags: [ 'tag_torrent1', 'tag_torrent2' ] | ||
187 | } | ||
188 | const { video } = await servers[0].imports.importVideo({ attributes }) | ||
189 | expect(video.name).to.equal('你好 世界 720p.mp4') | ||
190 | } | ||
191 | }) | ||
192 | |||
193 | it('Should list the videos to import in my videos on server 1', async function () { | ||
194 | const { total, data } = await servers[0].videos.listMyVideos({ sort: 'createdAt' }) | ||
195 | |||
196 | expect(total).to.equal(3) | ||
197 | |||
198 | expect(data).to.have.lengthOf(3) | ||
199 | expect(data[0].name).to.equal('small video - youtube') | ||
200 | expect(data[1].name).to.equal('super peertube2 video') | ||
201 | expect(data[2].name).to.equal('你好 世界 720p.mp4') | ||
202 | }) | ||
203 | |||
204 | it('Should list the videos to import in my imports on server 1', async function () { | ||
205 | const { total, data: videoImports } = await servers[0].imports.getMyVideoImports({ sort: '-createdAt' }) | ||
206 | expect(total).to.equal(3) | ||
207 | |||
208 | expect(videoImports).to.have.lengthOf(3) | ||
209 | |||
210 | expect(videoImports[2].targetUrl).to.equal(FIXTURE_URLS.youtube) | ||
211 | expect(videoImports[2].magnetUri).to.be.null | ||
212 | expect(videoImports[2].torrentName).to.be.null | ||
213 | expect(videoImports[2].video.name).to.equal('small video - youtube') | ||
214 | |||
215 | expect(videoImports[1].targetUrl).to.be.null | ||
216 | expect(videoImports[1].magnetUri).to.equal(FIXTURE_URLS.magnet) | ||
217 | expect(videoImports[1].torrentName).to.be.null | ||
218 | expect(videoImports[1].video.name).to.equal('super peertube2 video') | ||
219 | |||
220 | expect(videoImports[0].targetUrl).to.be.null | ||
221 | expect(videoImports[0].magnetUri).to.be.null | ||
222 | expect(videoImports[0].torrentName).to.equal('video-720p.torrent') | ||
223 | expect(videoImports[0].video.name).to.equal('你好 世界 720p.mp4') | ||
224 | }) | ||
225 | |||
226 | it('Should filter my imports on target URL', async function () { | ||
227 | const { total, data: videoImports } = await servers[0].imports.getMyVideoImports({ targetUrl: FIXTURE_URLS.youtube }) | ||
228 | expect(total).to.equal(1) | ||
229 | expect(videoImports).to.have.lengthOf(1) | ||
230 | |||
231 | expect(videoImports[0].targetUrl).to.equal(FIXTURE_URLS.youtube) | ||
232 | }) | ||
233 | |||
234 | it('Should search in my imports', async function () { | ||
235 | const { total, data: videoImports } = await servers[0].imports.getMyVideoImports({ search: 'peertube2' }) | ||
236 | expect(total).to.equal(1) | ||
237 | expect(videoImports).to.have.lengthOf(1) | ||
238 | |||
239 | expect(videoImports[0].magnetUri).to.equal(FIXTURE_URLS.magnet) | ||
240 | expect(videoImports[0].video.name).to.equal('super peertube2 video') | ||
241 | }) | ||
242 | |||
243 | it('Should have the video listed on the two instances', async function () { | ||
244 | this.timeout(120_000) | ||
245 | |||
246 | await waitJobs(servers) | ||
247 | |||
248 | for (const server of servers) { | ||
249 | const { total, data } = await server.videos.list() | ||
250 | expect(total).to.equal(3) | ||
251 | expect(data).to.have.lengthOf(3) | ||
252 | |||
253 | const [ videoHttp, videoMagnet, videoTorrent ] = data | ||
254 | await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) | ||
255 | } | ||
256 | }) | ||
257 | |||
258 | it('Should import a video on server 2 with some fields', async function () { | ||
259 | this.timeout(60_000) | ||
260 | |||
261 | const { video } = await servers[1].imports.importVideo({ | ||
262 | attributes: { | ||
263 | targetUrl: FIXTURE_URLS.youtube, | ||
264 | channelId: servers[1].store.channel.id, | ||
265 | privacy: VideoPrivacy.PUBLIC, | ||
266 | category: 10, | ||
267 | licence: 7, | ||
268 | language: 'en', | ||
269 | name: 'my super name', | ||
270 | description: 'my super description', | ||
271 | tags: [ 'supertag1', 'supertag2' ], | ||
272 | thumbnailfile: 'custom-thumbnail.jpg' | ||
273 | } | ||
274 | }) | ||
275 | expect(video.name).to.equal('my super name') | ||
276 | }) | ||
277 | |||
278 | it('Should have the videos listed on the two instances', async function () { | ||
279 | this.timeout(120_000) | ||
280 | |||
281 | await waitJobs(servers) | ||
282 | |||
283 | for (const server of servers) { | ||
284 | const { total, data } = await server.videos.list() | ||
285 | expect(total).to.equal(4) | ||
286 | expect(data).to.have.lengthOf(4) | ||
287 | |||
288 | await checkVideoServer2(server, data[0].uuid) | ||
289 | |||
290 | const [ , videoHttp, videoMagnet, videoTorrent ] = data | ||
291 | await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) | ||
292 | } | ||
293 | }) | ||
294 | |||
295 | it('Should import a video that will be transcoded', async function () { | ||
296 | this.timeout(240_000) | ||
297 | |||
298 | const attributes = { | ||
299 | name: 'transcoded video', | ||
300 | magnetUri: FIXTURE_URLS.magnet, | ||
301 | channelId: servers[1].store.channel.id, | ||
302 | privacy: VideoPrivacy.PUBLIC | ||
303 | } | ||
304 | const { video } = await servers[1].imports.importVideo({ attributes }) | ||
305 | const videoUUID = video.uuid | ||
306 | |||
307 | await waitJobs(servers) | ||
308 | |||
309 | for (const server of servers) { | ||
310 | const video = await server.videos.get({ id: videoUUID }) | ||
311 | |||
312 | expect(video.name).to.equal('transcoded video') | ||
313 | expect(video.files).to.have.lengthOf(4) | ||
314 | } | ||
315 | }) | ||
316 | |||
317 | it('Should import no HDR version on a HDR video', async function () { | ||
318 | this.timeout(300_000) | ||
319 | |||
320 | const config: DeepPartial<CustomConfig> = { | ||
321 | transcoding: { | ||
322 | enabled: true, | ||
323 | resolutions: { | ||
324 | '0p': false, | ||
325 | '144p': true, | ||
326 | '240p': true, | ||
327 | '360p': false, | ||
328 | '480p': false, | ||
329 | '720p': false, | ||
330 | '1080p': false, // the resulting resolution shouldn't be higher than this, and not vp9.2/av01 | ||
331 | '1440p': false, | ||
332 | '2160p': false | ||
333 | }, | ||
334 | webVideos: { enabled: true }, | ||
335 | hls: { enabled: false } | ||
336 | } | ||
337 | } | ||
338 | await servers[0].config.updateExistingSubConfig({ newConfig: config }) | ||
339 | |||
340 | const attributes = { | ||
341 | name: 'hdr video', | ||
342 | targetUrl: FIXTURE_URLS.youtubeHDR, | ||
343 | channelId: servers[0].store.channel.id, | ||
344 | privacy: VideoPrivacy.PUBLIC | ||
345 | } | ||
346 | const { video: videoImported } = await servers[0].imports.importVideo({ attributes }) | ||
347 | const videoUUID = videoImported.uuid | ||
348 | |||
349 | await waitJobs(servers) | ||
350 | |||
351 | // test resolution | ||
352 | const video = await servers[0].videos.get({ id: videoUUID }) | ||
353 | expect(video.name).to.equal('hdr video') | ||
354 | const maxResolution = Math.max.apply(Math, video.files.map(function (o) { return o.resolution.id })) | ||
355 | expect(maxResolution, 'expected max resolution not met').to.equals(VideoResolution.H_240P) | ||
356 | }) | ||
357 | |||
358 | it('Should not import resolution higher than enabled transcoding resolution', async function () { | ||
359 | this.timeout(300_000) | ||
360 | |||
361 | const config: DeepPartial<CustomConfig> = { | ||
362 | transcoding: { | ||
363 | enabled: true, | ||
364 | resolutions: { | ||
365 | '0p': false, | ||
366 | '144p': true, | ||
367 | '240p': false, | ||
368 | '360p': false, | ||
369 | '480p': false, | ||
370 | '720p': false, | ||
371 | '1080p': false, | ||
372 | '1440p': false, | ||
373 | '2160p': false | ||
374 | }, | ||
375 | alwaysTranscodeOriginalResolution: false | ||
376 | } | ||
377 | } | ||
378 | await servers[0].config.updateExistingSubConfig({ newConfig: config }) | ||
379 | |||
380 | const attributes = { | ||
381 | name: 'small resolution video', | ||
382 | targetUrl: FIXTURE_URLS.youtube, | ||
383 | channelId: servers[0].store.channel.id, | ||
384 | privacy: VideoPrivacy.PUBLIC | ||
385 | } | ||
386 | const { video: videoImported } = await servers[0].imports.importVideo({ attributes }) | ||
387 | const videoUUID = videoImported.uuid | ||
388 | |||
389 | await waitJobs(servers) | ||
390 | |||
391 | // test resolution | ||
392 | const video = await servers[0].videos.get({ id: videoUUID }) | ||
393 | expect(video.name).to.equal('small resolution video') | ||
394 | expect(video.files).to.have.lengthOf(1) | ||
395 | expect(video.files[0].resolution.id).to.equal(144) | ||
396 | }) | ||
397 | |||
398 | it('Should import resolution higher than enabled transcoding resolution', async function () { | ||
399 | this.timeout(300_000) | ||
400 | |||
401 | const config: DeepPartial<CustomConfig> = { | ||
402 | transcoding: { | ||
403 | alwaysTranscodeOriginalResolution: true | ||
404 | } | ||
405 | } | ||
406 | await servers[0].config.updateExistingSubConfig({ newConfig: config }) | ||
407 | |||
408 | const attributes = { | ||
409 | name: 'bigger resolution video', | ||
410 | targetUrl: FIXTURE_URLS.youtube, | ||
411 | channelId: servers[0].store.channel.id, | ||
412 | privacy: VideoPrivacy.PUBLIC | ||
413 | } | ||
414 | const { video: videoImported } = await servers[0].imports.importVideo({ attributes }) | ||
415 | const videoUUID = videoImported.uuid | ||
416 | |||
417 | await waitJobs(servers) | ||
418 | |||
419 | // test resolution | ||
420 | const video = await servers[0].videos.get({ id: videoUUID }) | ||
421 | expect(video.name).to.equal('bigger resolution video') | ||
422 | |||
423 | expect(video.files).to.have.lengthOf(2) | ||
424 | expect(video.files.find(f => f.resolution.id === 240)).to.exist | ||
425 | expect(video.files.find(f => f.resolution.id === 144)).to.exist | ||
426 | }) | ||
427 | |||
428 | it('Should import a peertube video', async function () { | ||
429 | this.timeout(120_000) | ||
430 | |||
431 | const toTest = [ FIXTURE_URLS.peertube_long ] | ||
432 | |||
433 | // TODO: include peertube_short when https://github.com/ytdl-org/youtube-dl/pull/29475 is merged | ||
434 | if (mode === 'yt-dlp') { | ||
435 | toTest.push(FIXTURE_URLS.peertube_short) | ||
436 | } | ||
437 | |||
438 | for (const targetUrl of toTest) { | ||
439 | await servers[0].config.disableTranscoding() | ||
440 | |||
441 | const attributes = { | ||
442 | targetUrl, | ||
443 | channelId: servers[0].store.channel.id, | ||
444 | privacy: VideoPrivacy.PUBLIC | ||
445 | } | ||
446 | const { video } = await servers[0].imports.importVideo({ attributes }) | ||
447 | const videoUUID = video.uuid | ||
448 | |||
449 | await waitJobs(servers) | ||
450 | |||
451 | for (const server of servers) { | ||
452 | const video = await server.videos.get({ id: videoUUID }) | ||
453 | |||
454 | expect(video.name).to.equal('E2E tests') | ||
455 | |||
456 | const { data: captions } = await server.captions.list({ videoId: videoUUID }) | ||
457 | expect(captions).to.have.lengthOf(1) | ||
458 | expect(captions[0].language.id).to.equal('fr') | ||
459 | |||
460 | const str = `WEBVTT FILE\r?\n\r?\n` + | ||
461 | `1\r?\n` + | ||
462 | `00:00:04.000 --> 00:00:09.000\r?\n` + | ||
463 | `January 1, 1994. The North American` | ||
464 | await testCaptionFile(server.url, captions[0].captionPath, new RegExp(str)) | ||
465 | } | ||
466 | } | ||
467 | }) | ||
468 | |||
469 | after(async function () { | ||
470 | await cleanupTests(servers) | ||
471 | }) | ||
472 | }) | ||
473 | } | ||
474 | |||
475 | // FIXME: youtube-dl seems broken | ||
476 | // runSuite('youtube-dl') | ||
477 | |||
478 | runSuite('yt-dlp') | ||
479 | |||
480 | describe('Delete/cancel an import', function () { | ||
481 | let server: PeerTubeServer | ||
482 | |||
483 | let finishedImportId: number | ||
484 | let finishedVideo: Video | ||
485 | let pendingImportId: number | ||
486 | |||
487 | async function importVideo (name: string) { | ||
488 | const attributes = { name, channelId: server.store.channel.id, targetUrl: FIXTURE_URLS.goodVideo } | ||
489 | const res = await server.imports.importVideo({ attributes }) | ||
490 | |||
491 | return res.id | ||
492 | } | ||
493 | |||
494 | before(async function () { | ||
495 | this.timeout(120_000) | ||
496 | |||
497 | server = await createSingleServer(1) | ||
498 | |||
499 | await setAccessTokensToServers([ server ]) | ||
500 | await setDefaultVideoChannel([ server ]) | ||
501 | |||
502 | finishedImportId = await importVideo('finished') | ||
503 | await waitJobs([ server ]) | ||
504 | |||
505 | await server.jobs.pauseJobQueue() | ||
506 | pendingImportId = await importVideo('pending') | ||
507 | |||
508 | const { data } = await server.imports.getMyVideoImports() | ||
509 | expect(data).to.have.lengthOf(2) | ||
510 | |||
511 | finishedVideo = data.find(i => i.id === finishedImportId).video | ||
512 | }) | ||
513 | |||
514 | it('Should delete a video import', async function () { | ||
515 | await server.imports.delete({ importId: finishedImportId }) | ||
516 | |||
517 | const { data } = await server.imports.getMyVideoImports() | ||
518 | expect(data).to.have.lengthOf(1) | ||
519 | expect(data[0].id).to.equal(pendingImportId) | ||
520 | expect(data[0].state.id).to.equal(VideoImportState.PENDING) | ||
521 | }) | ||
522 | |||
523 | it('Should not have deleted the associated video', async function () { | ||
524 | const video = await server.videos.get({ id: finishedVideo.id, token: server.accessToken, expectedStatus: HttpStatusCode.OK_200 }) | ||
525 | expect(video.name).to.equal('finished') | ||
526 | expect(video.state.id).to.equal(VideoState.PUBLISHED) | ||
527 | }) | ||
528 | |||
529 | it('Should cancel a video import', async function () { | ||
530 | await server.imports.cancel({ importId: pendingImportId }) | ||
531 | |||
532 | const { data } = await server.imports.getMyVideoImports() | ||
533 | expect(data).to.have.lengthOf(1) | ||
534 | expect(data[0].id).to.equal(pendingImportId) | ||
535 | expect(data[0].state.id).to.equal(VideoImportState.CANCELLED) | ||
536 | }) | ||
537 | |||
538 | it('Should not have processed the cancelled video import', async function () { | ||
539 | this.timeout(60_000) | ||
540 | |||
541 | await server.jobs.resumeJobQueue() | ||
542 | |||
543 | await waitJobs([ server ]) | ||
544 | |||
545 | const { data } = await server.imports.getMyVideoImports() | ||
546 | expect(data).to.have.lengthOf(1) | ||
547 | expect(data[0].id).to.equal(pendingImportId) | ||
548 | expect(data[0].state.id).to.equal(VideoImportState.CANCELLED) | ||
549 | expect(data[0].video.state.id).to.equal(VideoState.TO_IMPORT) | ||
550 | }) | ||
551 | |||
552 | it('Should delete the cancelled video import', async function () { | ||
553 | await server.imports.delete({ importId: pendingImportId }) | ||
554 | const { data } = await server.imports.getMyVideoImports() | ||
555 | expect(data).to.have.lengthOf(0) | ||
556 | }) | ||
557 | |||
558 | after(async function () { | ||
559 | await cleanupTests([ server ]) | ||
560 | }) | ||
561 | }) | ||
562 | |||
563 | describe('Auto update', function () { | ||
564 | let server: PeerTubeServer | ||
565 | |||
566 | function quickPeerTubeImport () { | ||
567 | const attributes = { | ||
568 | targetUrl: FIXTURE_URLS.peertube_long, | ||
569 | channelId: server.store.channel.id, | ||
570 | privacy: VideoPrivacy.PUBLIC | ||
571 | } | ||
572 | |||
573 | return server.imports.importVideo({ attributes }) | ||
574 | } | ||
575 | |||
576 | async function testBinaryUpdate (releaseUrl: string, releaseName: string) { | ||
577 | await remove(join(server.servers.buildDirectory('bin'), releaseName)) | ||
578 | |||
579 | await server.kill() | ||
580 | await server.run({ | ||
581 | import: { | ||
582 | videos: { | ||
583 | http: { | ||
584 | youtube_dl_release: { | ||
585 | url: releaseUrl, | ||
586 | name: releaseName | ||
587 | } | ||
588 | } | ||
589 | } | ||
590 | } | ||
591 | }) | ||
592 | |||
593 | await quickPeerTubeImport() | ||
594 | |||
595 | const base = server.servers.buildDirectory('bin') | ||
596 | const content = await readdir(base) | ||
597 | const binaryPath = join(base, releaseName) | ||
598 | |||
599 | expect(await pathExists(binaryPath), `${binaryPath} does not exist in ${base} (${content.join(', ')})`).to.be.true | ||
600 | } | ||
601 | |||
602 | before(async function () { | ||
603 | this.timeout(30_000) | ||
604 | |||
605 | // Run servers | ||
606 | server = await createSingleServer(1) | ||
607 | |||
608 | await setAccessTokensToServers([ server ]) | ||
609 | await setDefaultVideoChannel([ server ]) | ||
610 | }) | ||
611 | |||
612 | it('Should update youtube-dl from github URL', async function () { | ||
613 | this.timeout(120_000) | ||
614 | |||
615 | await testBinaryUpdate('https://api.github.com/repos/ytdl-org/youtube-dl/releases', 'youtube-dl') | ||
616 | }) | ||
617 | |||
618 | it('Should update youtube-dl from raw URL', async function () { | ||
619 | this.timeout(120_000) | ||
620 | |||
621 | await testBinaryUpdate('https://yt-dl.org/downloads/latest/youtube-dl', 'youtube-dl') | ||
622 | }) | ||
623 | |||
624 | it('Should update youtube-dl from youtube-dl fork', async function () { | ||
625 | this.timeout(120_000) | ||
626 | |||
627 | await testBinaryUpdate('https://api.github.com/repos/yt-dlp/yt-dlp/releases', 'yt-dlp') | ||
628 | }) | ||
629 | |||
630 | after(async function () { | ||
631 | await cleanupTests([ server ]) | ||
632 | }) | ||
633 | }) | ||
634 | }) | ||