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