1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
6 areHttpImportTestsDisabled,
12 setAccessTokensToServers,
16 } from '@shared/extra-utils'
17 import { VideoPrivacy, VideoResolution } from '@shared/models'
19 const expect = chai.expect
21 describe('Test video imports', function () {
22 let servers: PeerTubeServer[] = []
23 let channelIdServer1: number
24 let channelIdServer2: number
26 if (areHttpImportTestsDisabled()) return
28 async function checkVideosServer1 (server: PeerTubeServer, idHttp: string, idMagnet: string, idTorrent: string) {
29 const videoHttp = await server.videos.get({ id: idHttp })
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)
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)
46 const videoMagnet = await server.videos.get({ id: idMagnet })
47 const videoTorrent = await server.videos.get({ id: idTorrent })
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)
59 expect(videoTorrent.name).to.contain('你好 世界 720p.mp4')
60 expect(videoMagnet.name).to.contain('super peertube2 video')
62 const bodyCaptions = await server.captions.list({ videoId: idHttp })
63 expect(bodyCaptions.total).to.equal(2)
66 async function checkVideoServer2 (server: PeerTubeServer, id: number | string) {
67 const video = await server.videos.get({ id })
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' ])
77 expect(video.files).to.have.lengthOf(1)
79 const bodyCaptions = await server.captions.list({ videoId: id })
80 expect(bodyCaptions.total).to.equal(2)
83 before(async function () {
87 servers = await createMultipleServers(2)
89 await setAccessTokensToServers(servers)
92 const { videoChannels } = await servers[0].users.getMyInfo()
93 channelIdServer1 = videoChannels[0].id
97 const { videoChannels } = await servers[1].users.getMyInfo()
98 channelIdServer2 = videoChannels[0].id
101 await doubleFollow(servers[0], servers[1])
104 it('Should import videos on server 1', async function () {
107 const baseAttributes = {
108 channelId: channelIdServer1,
109 privacy: VideoPrivacy.PUBLIC
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')
117 expect(video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`))
118 expect(video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`))
120 await testImage(servers[0].url, 'video_import_thumbnail', video.thumbnailPath)
121 await testImage(servers[0].url, 'video_import_preview', video.previewPath)
123 const bodyCaptions = await servers[0].captions.list({ videoId: video.id })
124 const videoCaptions = bodyCaptions.data
125 expect(videoCaptions).to.have.lengthOf(2)
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
135 00:00:01.600 --> 00:00:04.200
138 00:00:05.900 --> 00:00:07.999
139 This is a subtitle in American English
141 00:00:10.000 --> 00:00:14.000
142 Adding subtitles is very easy to do`)
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
152 00:00:01.600 --> 00:00:04.200
155 00:00:05.900 --> 00:00:07.999
156 C'est un sous-titre français
158 00:00:10.000 --> 00:00:14.000
159 Ajouter un sous-titre est vraiment facile`)
165 magnetUri: FIXTURE_URLS.magnet,
166 description: 'this is a super torrent description',
167 tags: [ 'tag_torrent1', 'tag_torrent2' ]
169 const { video } = await servers[0].imports.importVideo({ attributes })
170 expect(video.name).to.equal('super peertube2 video')
176 torrentfile: 'video-720p.torrent' as any,
177 description: 'this is a super torrent description',
178 tags: [ 'tag_torrent1', 'tag_torrent2' ]
180 const { video } = await servers[0].imports.importVideo({ attributes })
181 expect(video.name).to.equal('你好 世界 720p.mp4')
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' })
188 expect(total).to.equal(3)
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')
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)
200 expect(videoImports).to.have.lengthOf(3)
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')
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')
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')
218 it('Should have the video listed on the two instances', async function () {
219 this.timeout(120_000)
221 await waitJobs(servers)
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)
228 const [ videoHttp, videoMagnet, videoTorrent ] = data
229 await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
233 it('Should import a video on server 2 with some fields', async function () {
237 targetUrl: FIXTURE_URLS.youtube,
238 channelId: channelIdServer2,
239 privacy: VideoPrivacy.PUBLIC,
243 name: 'my super name',
244 description: 'my super description',
245 tags: [ 'supertag1', 'supertag2' ]
247 const { video } = await servers[1].imports.importVideo({ attributes })
248 expect(video.name).to.equal('my super name')
251 it('Should have the videos listed on the two instances', async function () {
252 this.timeout(120_000)
254 await waitJobs(servers)
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)
261 await checkVideoServer2(server, data[0].uuid)
263 const [ , videoHttp, videoMagnet, videoTorrent ] = data
264 await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
268 it('Should import a video that will be transcoded', async function () {
269 this.timeout(120_000)
272 name: 'transcoded video',
273 magnetUri: FIXTURE_URLS.magnet,
274 channelId: channelIdServer2,
275 privacy: VideoPrivacy.PUBLIC
277 const { video } = await servers[1].imports.importVideo({ attributes })
278 const videoUUID = video.uuid
280 await waitJobs(servers)
282 for (const server of servers) {
283 const video = await server.videos.get({ id: videoUUID })
285 expect(video.name).to.equal('transcoded video')
286 expect(video.files).to.have.lengthOf(4)
290 it('Should import no HDR version on a HDR video', async function () {
291 this.timeout(120_000)
301 '1080p': true, // the resulting resolution shouldn't be higher than this, and not vp9.2/av01
305 webtorrent: { enabled: true },
306 hls: { enabled: false }
319 await servers[0].config.updateCustomSubConfig({ newConfig: config })
323 targetUrl: FIXTURE_URLS.youtubeHDR,
324 channelId: channelIdServer1,
325 privacy: VideoPrivacy.PUBLIC
327 const { video: videoImported } = await servers[0].imports.importVideo({ attributes })
328 const videoUUID = videoImported.uuid
330 await waitJobs(servers)
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)
339 after(async function () {
340 await cleanupTests(servers)