1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
8 flushAndRunMultipleServers,
16 setAccessTokensToServers,
18 } from '../../../../shared/extra-utils'
19 import { areHttpImportTestsDisabled, testImage } from '../../../../shared/extra-utils/miscs/miscs'
20 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
24 getYoutubeHDRVideoUrl,
27 } from '../../../../shared/extra-utils/videos/video-imports'
28 import { VideoCaption, VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos'
30 const expect = chai.expect
32 describe('Test video imports', function () {
33 let servers: ServerInfo[] = []
34 let channelIdServer1: number
35 let channelIdServer2: number
37 if (areHttpImportTestsDisabled()) return
39 async function checkVideosServer1 (url: string, idHttp: string, idMagnet: string, idTorrent: string) {
40 const resHttp = await getVideo(url, idHttp)
41 const videoHttp: VideoDetails = resHttp.body
43 expect(videoHttp.name).to.equal('small video - youtube')
44 // FIXME: youtube-dl seems broken
45 // expect(videoHttp.category.label).to.equal('News & Politics')
46 // expect(videoHttp.licence.label).to.equal('Attribution')
47 expect(videoHttp.language.label).to.equal('Unknown')
48 expect(videoHttp.nsfw).to.be.false
49 expect(videoHttp.description).to.equal('this is a super description')
50 expect(videoHttp.tags).to.deep.equal([ 'tag1', 'tag2' ])
51 expect(videoHttp.files).to.have.lengthOf(1)
53 const originallyPublishedAt = new Date(videoHttp.originallyPublishedAt)
54 expect(originallyPublishedAt.getDate()).to.equal(14)
55 expect(originallyPublishedAt.getMonth()).to.equal(0)
56 expect(originallyPublishedAt.getFullYear()).to.equal(2019)
58 const resMagnet = await getVideo(url, idMagnet)
59 const videoMagnet: VideoDetails = resMagnet.body
60 const resTorrent = await getVideo(url, idTorrent)
61 const videoTorrent: VideoDetails = resTorrent.body
63 for (const video of [ videoMagnet, videoTorrent ]) {
64 expect(video.category.label).to.equal('Misc')
65 expect(video.licence.label).to.equal('Unknown')
66 expect(video.language.label).to.equal('Unknown')
67 expect(video.nsfw).to.be.false
68 expect(video.description).to.equal('this is a super torrent description')
69 expect(video.tags).to.deep.equal([ 'tag_torrent1', 'tag_torrent2' ])
70 expect(video.files).to.have.lengthOf(1)
73 expect(videoTorrent.name).to.contain('你好 世界 720p.mp4')
74 expect(videoMagnet.name).to.contain('super peertube2 video')
76 const resCaptions = await listVideoCaptions(url, idHttp)
77 expect(resCaptions.body.total).to.equal(2)
80 async function checkVideoServer2 (url: string, id: number | string) {
81 const res = await getVideo(url, id)
82 const video: VideoDetails = res.body
84 expect(video.name).to.equal('my super name')
85 expect(video.category.label).to.equal('Entertainment')
86 expect(video.licence.label).to.equal('Public Domain Dedication')
87 expect(video.language.label).to.equal('English')
88 expect(video.nsfw).to.be.false
89 expect(video.description).to.equal('my super description')
90 expect(video.tags).to.deep.equal([ 'supertag1', 'supertag2' ])
92 expect(video.files).to.have.lengthOf(1)
94 const resCaptions = await listVideoCaptions(url, id)
95 expect(resCaptions.body.total).to.equal(2)
98 before(async function () {
102 servers = await flushAndRunMultipleServers(2)
104 await setAccessTokensToServers(servers)
107 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
108 channelIdServer1 = res.body.videoChannels[0].id
112 const res = await getMyUserInformation(servers[1].url, servers[1].accessToken)
113 channelIdServer2 = res.body.videoChannels[0].id
116 await doubleFollow(servers[0], servers[1])
119 it('Should import videos on server 1', async function () {
122 const baseAttributes = {
123 channelId: channelIdServer1,
124 privacy: VideoPrivacy.PUBLIC
128 const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() })
129 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
130 expect(res.body.video.name).to.equal('small video - youtube')
132 expect(res.body.video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`))
133 expect(res.body.video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`))
135 await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath)
136 await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath)
138 const resCaptions = await listVideoCaptions(servers[0].url, res.body.video.id)
139 const videoCaptions: VideoCaption[] = resCaptions.body.data
140 expect(videoCaptions).to.have.lengthOf(2)
142 const enCaption = videoCaptions.find(caption => caption.language.id === 'en')
143 expect(enCaption).to.exist
144 expect(enCaption.language.label).to.equal('English')
145 expect(enCaption.captionPath).to.match(new RegExp(`^/lazy-static/video-captions/.+-en.vtt$`))
146 await testCaptionFile(servers[0].url, enCaption.captionPath, `WEBVTT
150 00:00:01.600 --> 00:00:04.200
153 00:00:05.900 --> 00:00:07.999
154 This is a subtitle in American English
156 00:00:10.000 --> 00:00:14.000
157 Adding subtitles is very easy to do`)
159 const frCaption = videoCaptions.find(caption => caption.language.id === 'fr')
160 expect(frCaption).to.exist
161 expect(frCaption.language.label).to.equal('French')
162 expect(frCaption.captionPath).to.match(new RegExp(`^/lazy-static/video-captions/.+-fr.vtt`))
163 await testCaptionFile(servers[0].url, frCaption.captionPath, `WEBVTT
167 00:00:01.600 --> 00:00:04.200
170 00:00:05.900 --> 00:00:07.999
171 C'est un sous-titre français
173 00:00:10.000 --> 00:00:14.000
174 Ajouter un sous-titre est vraiment facile`)
178 const attributes = immutableAssign(baseAttributes, {
179 magnetUri: getMagnetURI(),
180 description: 'this is a super torrent description',
181 tags: [ 'tag_torrent1', 'tag_torrent2' ]
183 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
184 expect(res.body.video.name).to.equal('super peertube2 video')
188 const attributes = immutableAssign(baseAttributes, {
189 torrentfile: 'video-720p.torrent' as any,
190 description: 'this is a super torrent description',
191 tags: [ 'tag_torrent1', 'tag_torrent2' ]
193 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
194 expect(res.body.video.name).to.equal('你好 世界 720p.mp4')
198 it('Should list the videos to import in my videos on server 1', async function () {
199 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5, 'createdAt')
201 expect(res.body.total).to.equal(3)
203 const videos = res.body.data
204 expect(videos).to.have.lengthOf(3)
205 expect(videos[0].name).to.equal('small video - youtube')
206 expect(videos[1].name).to.equal('super peertube2 video')
207 expect(videos[2].name).to.equal('你好 世界 720p.mp4')
210 it('Should list the videos to import in my imports on server 1', async function () {
211 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken, '-createdAt')
213 expect(res.body.total).to.equal(3)
214 const videoImports: VideoImport[] = res.body.data
215 expect(videoImports).to.have.lengthOf(3)
217 expect(videoImports[2].targetUrl).to.equal(getYoutubeVideoUrl())
218 expect(videoImports[2].magnetUri).to.be.null
219 expect(videoImports[2].torrentName).to.be.null
220 expect(videoImports[2].video.name).to.equal('small video - youtube')
222 expect(videoImports[1].targetUrl).to.be.null
223 expect(videoImports[1].magnetUri).to.equal(getMagnetURI())
224 expect(videoImports[1].torrentName).to.be.null
225 expect(videoImports[1].video.name).to.equal('super peertube2 video')
227 expect(videoImports[0].targetUrl).to.be.null
228 expect(videoImports[0].magnetUri).to.be.null
229 expect(videoImports[0].torrentName).to.equal('video-720p.torrent')
230 expect(videoImports[0].video.name).to.equal('你好 世界 720p.mp4')
233 it('Should have the video listed on the two instances', async function () {
234 this.timeout(120_000)
236 await waitJobs(servers)
238 for (const server of servers) {
239 const res = await getVideosList(server.url)
240 expect(res.body.total).to.equal(3)
241 expect(res.body.data).to.have.lengthOf(3)
243 const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data
244 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
248 it('Should import a video on server 2 with some fields', async function () {
252 targetUrl: getYoutubeVideoUrl(),
253 channelId: channelIdServer2,
254 privacy: VideoPrivacy.PUBLIC,
258 name: 'my super name',
259 description: 'my super description',
260 tags: [ 'supertag1', 'supertag2' ]
262 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
263 expect(res.body.video.name).to.equal('my super name')
266 it('Should have the videos listed on the two instances', async function () {
267 this.timeout(120_000)
269 await waitJobs(servers)
271 for (const server of servers) {
272 const res = await getVideosList(server.url)
273 expect(res.body.total).to.equal(4)
274 expect(res.body.data).to.have.lengthOf(4)
276 await checkVideoServer2(server.url, res.body.data[0].uuid)
278 const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data
279 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
283 it('Should import a video that will be transcoded', async function () {
284 this.timeout(120_000)
287 name: 'transcoded video',
288 magnetUri: getMagnetURI(),
289 channelId: channelIdServer2,
290 privacy: VideoPrivacy.PUBLIC
292 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
293 const videoUUID = res.body.video.uuid
295 await waitJobs(servers)
297 for (const server of servers) {
298 const res = await getVideo(server.url, videoUUID)
299 const video: VideoDetails = res.body
301 expect(video.name).to.equal('transcoded video')
302 expect(video.files).to.have.lengthOf(4)
306 it('Should import no HDR version on a HDR video', async function () {
307 this.timeout(120_000)
317 '1080p': true, // the resulting resolution shouldn't be higher than this, and not vp9.2/av01
321 webtorrent: { enabled: true },
322 hls: { enabled: false }
335 await servers[0].configCommand.updateCustomSubConfig({ newConfig: config })
339 targetUrl: getYoutubeHDRVideoUrl(),
340 channelId: channelIdServer1,
341 privacy: VideoPrivacy.PUBLIC
343 const res1 = await importVideo(servers[0].url, servers[0].accessToken, attributes)
344 const videoUUID = res1.body.video.uuid
346 await waitJobs(servers)
349 const res2 = await getVideo(servers[0].url, videoUUID)
350 const video: VideoDetails = res2.body
351 expect(video.name).to.equal('hdr video')
352 const maxResolution = Math.max.apply(Math, video.files.map(function (o) { return o.resolution.id }))
353 expect(maxResolution, 'expected max resolution not met').to.equals(VideoResolution.H_1080P)
356 after(async function () {
357 await cleanupTests(servers)