]>
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 | createMultipleServers, | |
9 | doubleFollow, | |
10 | FIXTURE_URLS, | |
11 | PeerTubeServer, | |
12 | setAccessTokensToServers, | |
13 | testCaptionFile, | |
14 | testImage, | |
15 | waitJobs | |
16 | } from '@shared/extra-utils' | |
17 | import { VideoPrivacy, VideoResolution } from '@shared/models' | |
18 | ||
19 | const expect = chai.expect | |
20 | ||
21 | describe('Test video imports', function () { | |
22 | let servers: PeerTubeServer[] = [] | |
23 | let channelIdServer1: number | |
24 | let channelIdServer2: number | |
25 | ||
26 | if (areHttpImportTestsDisabled()) return | |
27 | ||
28 | async function checkVideosServer1 (server: PeerTubeServer, idHttp: string, idMagnet: string, idTorrent: string) { | |
29 | const videoHttp = await server.videos.get({ id: idHttp }) | |
30 | ||
31 | expect(videoHttp.name).to.equal('small video - youtube') | |
32 | // FIXME: youtube-dl seems broken | |
33 | // expect(videoHttp.category.label).to.equal('News & Politics') | |
34 | // expect(videoHttp.licence.label).to.equal('Attribution') | |
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) | |
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) | |
45 | ||
46 | const videoMagnet = await server.videos.get({ id: idMagnet }) | |
47 | const videoTorrent = await server.videos.get({ id: idTorrent }) | |
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 | } | |
58 | ||
59 | expect(videoTorrent.name).to.contain('你好 世界 720p.mp4') | |
60 | expect(videoMagnet.name).to.contain('super peertube2 video') | |
61 | ||
62 | const bodyCaptions = await server.captions.listVideoCaptions({ videoId: idHttp }) | |
63 | expect(bodyCaptions.total).to.equal(2) | |
64 | } | |
65 | ||
66 | async function checkVideoServer2 (server: PeerTubeServer, id: number | string) { | |
67 | const video = await server.videos.get({ id }) | |
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) | |
78 | ||
79 | const bodyCaptions = await server.captions.listVideoCaptions({ videoId: id }) | |
80 | expect(bodyCaptions.total).to.equal(2) | |
81 | } | |
82 | ||
83 | before(async function () { | |
84 | this.timeout(30_000) | |
85 | ||
86 | // Run servers | |
87 | servers = await createMultipleServers(2) | |
88 | ||
89 | await setAccessTokensToServers(servers) | |
90 | ||
91 | { | |
92 | const { videoChannels } = await servers[0].users.getMyInfo() | |
93 | channelIdServer1 = videoChannels[0].id | |
94 | } | |
95 | ||
96 | { | |
97 | const { videoChannels } = await servers[1].users.getMyInfo() | |
98 | channelIdServer2 = videoChannels[0].id | |
99 | } | |
100 | ||
101 | await doubleFollow(servers[0], servers[1]) | |
102 | }) | |
103 | ||
104 | it('Should import videos on server 1', async function () { | |
105 | this.timeout(60_000) | |
106 | ||
107 | const baseAttributes = { | |
108 | channelId: channelIdServer1, | |
109 | privacy: VideoPrivacy.PUBLIC | |
110 | } | |
111 | ||
112 | { | |
113 | const attributes = { ...baseAttributes, targetUrl: FIXTURE_URLS.youtube } | |
114 | const { video } = await servers[0].imports.importVideo({ attributes }) | |
115 | expect(video.name).to.equal('small video - youtube') | |
116 | ||
117 | expect(video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`)) | |
118 | expect(video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`)) | |
119 | ||
120 | await testImage(servers[0].url, 'video_import_thumbnail', video.thumbnailPath) | |
121 | await testImage(servers[0].url, 'video_import_preview', video.previewPath) | |
122 | ||
123 | const bodyCaptions = await servers[0].captions.listVideoCaptions({ videoId: video.id }) | |
124 | const videoCaptions = bodyCaptions.data | |
125 | expect(videoCaptions).to.have.lengthOf(2) | |
126 | ||
127 | const enCaption = videoCaptions.find(caption => caption.language.id === 'en') | |
128 | expect(enCaption).to.exist | |
129 | expect(enCaption.language.label).to.equal('English') | |
130 | expect(enCaption.captionPath).to.match(new RegExp(`^/lazy-static/video-captions/.+-en.vtt$`)) | |
131 | await testCaptionFile(servers[0].url, enCaption.captionPath, `WEBVTT | |
132 | Kind: captions | |
133 | Language: en | |
134 | ||
135 | 00:00:01.600 --> 00:00:04.200 | |
136 | English (US) | |
137 | ||
138 | 00:00:05.900 --> 00:00:07.999 | |
139 | This is a subtitle in American English | |
140 | ||
141 | 00:00:10.000 --> 00:00:14.000 | |
142 | Adding subtitles is very easy to do`) | |
143 | ||
144 | const frCaption = videoCaptions.find(caption => caption.language.id === 'fr') | |
145 | expect(frCaption).to.exist | |
146 | expect(frCaption.language.label).to.equal('French') | |
147 | expect(frCaption.captionPath).to.match(new RegExp(`^/lazy-static/video-captions/.+-fr.vtt`)) | |
148 | await testCaptionFile(servers[0].url, frCaption.captionPath, `WEBVTT | |
149 | Kind: captions | |
150 | Language: fr | |
151 | ||
152 | 00:00:01.600 --> 00:00:04.200 | |
153 | Français (FR) | |
154 | ||
155 | 00:00:05.900 --> 00:00:07.999 | |
156 | C'est un sous-titre français | |
157 | ||
158 | 00:00:10.000 --> 00:00:14.000 | |
159 | Ajouter un sous-titre est vraiment facile`) | |
160 | } | |
161 | ||
162 | { | |
163 | const attributes = { | |
164 | ...baseAttributes, | |
165 | magnetUri: FIXTURE_URLS.magnet, | |
166 | description: 'this is a super torrent description', | |
167 | tags: [ 'tag_torrent1', 'tag_torrent2' ] | |
168 | } | |
169 | const { video } = await servers[0].imports.importVideo({ attributes }) | |
170 | expect(video.name).to.equal('super peertube2 video') | |
171 | } | |
172 | ||
173 | { | |
174 | const attributes = { | |
175 | ...baseAttributes, | |
176 | torrentfile: 'video-720p.torrent' as any, | |
177 | description: 'this is a super torrent description', | |
178 | tags: [ 'tag_torrent1', 'tag_torrent2' ] | |
179 | } | |
180 | const { video } = await servers[0].imports.importVideo({ attributes }) | |
181 | expect(video.name).to.equal('你好 世界 720p.mp4') | |
182 | } | |
183 | }) | |
184 | ||
185 | it('Should list the videos to import in my videos on server 1', async function () { | |
186 | const { total, data } = await servers[0].videos.listMyVideos({ sort: 'createdAt' }) | |
187 | ||
188 | expect(total).to.equal(3) | |
189 | ||
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') | |
194 | }) | |
195 | ||
196 | it('Should list the videos to import in my imports on server 1', async function () { | |
197 | const { total, data: videoImports } = await servers[0].imports.getMyVideoImports({ sort: '-createdAt' }) | |
198 | expect(total).to.equal(3) | |
199 | ||
200 | expect(videoImports).to.have.lengthOf(3) | |
201 | ||
202 | expect(videoImports[2].targetUrl).to.equal(FIXTURE_URLS.youtube) | |
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') | |
206 | ||
207 | expect(videoImports[1].targetUrl).to.be.null | |
208 | expect(videoImports[1].magnetUri).to.equal(FIXTURE_URLS.magnet) | |
209 | expect(videoImports[1].torrentName).to.be.null | |
210 | expect(videoImports[1].video.name).to.equal('super peertube2 video') | |
211 | ||
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') | |
216 | }) | |
217 | ||
218 | it('Should have the video listed on the two instances', async function () { | |
219 | this.timeout(120_000) | |
220 | ||
221 | await waitJobs(servers) | |
222 | ||
223 | for (const server of servers) { | |
224 | const { total, data } = await server.videos.list() | |
225 | expect(total).to.equal(3) | |
226 | expect(data).to.have.lengthOf(3) | |
227 | ||
228 | const [ videoHttp, videoMagnet, videoTorrent ] = data | |
229 | await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) | |
230 | } | |
231 | }) | |
232 | ||
233 | it('Should import a video on server 2 with some fields', async function () { | |
234 | this.timeout(60_000) | |
235 | ||
236 | const attributes = { | |
237 | targetUrl: FIXTURE_URLS.youtube, | |
238 | channelId: channelIdServer2, | |
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 | } | |
247 | const { video } = await servers[1].imports.importVideo({ attributes }) | |
248 | expect(video.name).to.equal('my super name') | |
249 | }) | |
250 | ||
251 | it('Should have the videos listed on the two instances', async function () { | |
252 | this.timeout(120_000) | |
253 | ||
254 | await waitJobs(servers) | |
255 | ||
256 | for (const server of servers) { | |
257 | const { total, data } = await server.videos.list() | |
258 | expect(total).to.equal(4) | |
259 | expect(data).to.have.lengthOf(4) | |
260 | ||
261 | await checkVideoServer2(server, data[0].uuid) | |
262 | ||
263 | const [ , videoHttp, videoMagnet, videoTorrent ] = data | |
264 | await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) | |
265 | } | |
266 | }) | |
267 | ||
268 | it('Should import a video that will be transcoded', async function () { | |
269 | this.timeout(120_000) | |
270 | ||
271 | const attributes = { | |
272 | name: 'transcoded video', | |
273 | magnetUri: FIXTURE_URLS.magnet, | |
274 | channelId: channelIdServer2, | |
275 | privacy: VideoPrivacy.PUBLIC | |
276 | } | |
277 | const { video } = await servers[1].imports.importVideo({ attributes }) | |
278 | const videoUUID = video.uuid | |
279 | ||
280 | await waitJobs(servers) | |
281 | ||
282 | for (const server of servers) { | |
283 | const video = await server.videos.get({ id: videoUUID }) | |
284 | ||
285 | expect(video.name).to.equal('transcoded video') | |
286 | expect(video.files).to.have.lengthOf(4) | |
287 | } | |
288 | }) | |
289 | ||
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 | } | |
319 | await servers[0].config.updateCustomSubConfig({ newConfig: config }) | |
320 | ||
321 | const attributes = { | |
322 | name: 'hdr video', | |
323 | targetUrl: FIXTURE_URLS.youtubeHDR, | |
324 | channelId: channelIdServer1, | |
325 | privacy: VideoPrivacy.PUBLIC | |
326 | } | |
327 | const { video: videoImported } = await servers[0].imports.importVideo({ attributes }) | |
328 | const videoUUID = videoImported.uuid | |
329 | ||
330 | await waitJobs(servers) | |
331 | ||
332 | // test resolution | |
333 | const video = await servers[0].videos.get({ id: videoUUID }) | |
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 | ||
339 | after(async function () { | |
340 | await cleanupTests(servers) | |
341 | }) | |
342 | }) |