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