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'
21 import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
22 import { VideoCaption, VideoDetails, VideoImport, VideoPrivacy } from '../../../../shared/models/videos'
24 const expect = chai.expect
26 describe('Test video imports', function () {
27 let servers: ServerInfo[] = []
28 let channelIdServer1: number
29 let channelIdServer2: number
31 if (areHttpImportTestsDisabled()) return
33 async function checkVideosServer1 (url: string, idHttp: string, idMagnet: string, idTorrent: string) {
34 const resHttp = await getVideo(url, idHttp)
35 const videoHttp: VideoDetails = resHttp.body
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)
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)
52 const resMagnet = await getVideo(url, idMagnet)
53 const videoMagnet: VideoDetails = resMagnet.body
54 const resTorrent = await getVideo(url, idTorrent)
55 const videoTorrent: VideoDetails = resTorrent.body
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)
67 expect(videoTorrent.name).to.contain('你好 世界 720p.mp4')
68 expect(videoMagnet.name).to.contain('super peertube2 video')
70 const resCaptions = await listVideoCaptions(url, idHttp)
71 expect(resCaptions.body.total).to.equal(2)
74 async function checkVideoServer2 (url: string, id: number | string) {
75 const res = await getVideo(url, id)
76 const video: VideoDetails = res.body
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' ])
86 expect(video.files).to.have.lengthOf(1)
88 const resCaptions = await listVideoCaptions(url, id)
89 expect(resCaptions.body.total).to.equal(2)
92 before(async function () {
96 servers = await flushAndRunMultipleServers(2)
98 await setAccessTokensToServers(servers)
101 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
102 channelIdServer1 = res.body.videoChannels[0].id
106 const res = await getMyUserInformation(servers[1].url, servers[1].accessToken)
107 channelIdServer2 = res.body.videoChannels[0].id
110 await doubleFollow(servers[0], servers[1])
113 it('Should import videos on server 1', async function () {
116 const baseAttributes = {
117 channelId: channelIdServer1,
118 privacy: VideoPrivacy.PUBLIC
122 const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() })
123 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
124 expect(res.body.video.name).to.equal('small video - youtube')
125 expect(res.body.video.thumbnailPath).to.equal(`/static/thumbnails/${res.body.video.uuid}.jpg`)
126 expect(res.body.video.previewPath).to.equal(`/lazy-static/previews/${res.body.video.uuid}.jpg`)
127 await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath)
128 await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath)
130 const resCaptions = await listVideoCaptions(servers[0].url, res.body.video.id)
131 const videoCaptions: VideoCaption[] = resCaptions.body.data
132 expect(videoCaptions).to.have.lengthOf(2)
134 const enCaption = videoCaptions.find(caption => caption.language.id === 'en')
135 expect(enCaption).to.exist
136 expect(enCaption.language.label).to.equal('English')
137 expect(enCaption.captionPath).to.equal(`/lazy-static/video-captions/${res.body.video.uuid}-en.vtt`)
138 await testCaptionFile(servers[0].url, enCaption.captionPath, `WEBVTT
142 00:00:01.600 --> 00:00:04.200
145 00:00:05.900 --> 00:00:07.999
146 This is a subtitle in American English
148 00:00:10.000 --> 00:00:14.000
149 Adding subtitles is very easy to do`)
151 const frCaption = videoCaptions.find(caption => caption.language.id === 'fr')
152 expect(frCaption).to.exist
153 expect(frCaption.language.label).to.equal('French')
154 expect(frCaption.captionPath).to.equal(`/lazy-static/video-captions/${res.body.video.uuid}-fr.vtt`)
155 await testCaptionFile(servers[0].url, frCaption.captionPath, `WEBVTT
159 00:00:01.600 --> 00:00:04.200
162 00:00:05.900 --> 00:00:07.999
163 C'est un sous-titre français
165 00:00:10.000 --> 00:00:14.000
166 Ajouter un sous-titre est vraiment facile`)
170 const attributes = immutableAssign(baseAttributes, {
171 magnetUri: getMagnetURI(),
172 description: 'this is a super torrent description',
173 tags: [ 'tag_torrent1', 'tag_torrent2' ]
175 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
176 expect(res.body.video.name).to.equal('super peertube2 video')
180 const attributes = immutableAssign(baseAttributes, {
181 torrentfile: 'video-720p.torrent' as any,
182 description: 'this is a super torrent description',
183 tags: [ 'tag_torrent1', 'tag_torrent2' ]
185 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
186 expect(res.body.video.name).to.equal('你好 世界 720p.mp4')
190 it('Should list the videos to import in my videos on server 1', async function () {
191 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5, 'createdAt')
193 expect(res.body.total).to.equal(3)
195 const videos = res.body.data
196 expect(videos).to.have.lengthOf(3)
197 expect(videos[0].name).to.equal('small video - youtube')
198 expect(videos[1].name).to.equal('super peertube2 video')
199 expect(videos[2].name).to.equal('你好 世界 720p.mp4')
202 it('Should list the videos to import in my imports on server 1', async function () {
203 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken, '-createdAt')
205 expect(res.body.total).to.equal(3)
206 const videoImports: VideoImport[] = res.body.data
207 expect(videoImports).to.have.lengthOf(3)
209 expect(videoImports[2].targetUrl).to.equal(getYoutubeVideoUrl())
210 expect(videoImports[2].magnetUri).to.be.null
211 expect(videoImports[2].torrentName).to.be.null
212 expect(videoImports[2].video.name).to.equal('small video - youtube')
214 expect(videoImports[1].targetUrl).to.be.null
215 expect(videoImports[1].magnetUri).to.equal(getMagnetURI())
216 expect(videoImports[1].torrentName).to.be.null
217 expect(videoImports[1].video.name).to.equal('super peertube2 video')
219 expect(videoImports[0].targetUrl).to.be.null
220 expect(videoImports[0].magnetUri).to.be.null
221 expect(videoImports[0].torrentName).to.equal('video-720p.torrent')
222 expect(videoImports[0].video.name).to.equal('你好 世界 720p.mp4')
225 it('Should have the video listed on the two instances', async function () {
228 await waitJobs(servers)
230 for (const server of servers) {
231 const res = await getVideosList(server.url)
232 expect(res.body.total).to.equal(3)
233 expect(res.body.data).to.have.lengthOf(3)
235 const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data
236 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
240 it('Should import a video on server 2 with some fields', async function () {
244 targetUrl: getYoutubeVideoUrl(),
245 channelId: channelIdServer2,
246 privacy: VideoPrivacy.PUBLIC,
250 name: 'my super name',
251 description: 'my super description',
252 tags: [ 'supertag1', 'supertag2' ]
254 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
255 expect(res.body.video.name).to.equal('my super name')
258 it('Should have the videos listed on the two instances', async function () {
261 await waitJobs(servers)
263 for (const server of servers) {
264 const res = await getVideosList(server.url)
265 expect(res.body.total).to.equal(4)
266 expect(res.body.data).to.have.lengthOf(4)
268 await checkVideoServer2(server.url, res.body.data[0].uuid)
270 const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data
271 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
275 it('Should import a video that will be transcoded', async function () {
279 name: 'transcoded video',
280 magnetUri: getMagnetURI(),
281 channelId: channelIdServer2,
282 privacy: VideoPrivacy.PUBLIC
284 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
285 const videoUUID = res.body.video.uuid
287 await waitJobs(servers)
289 for (const server of servers) {
290 const res = await getVideo(server.url, videoUUID)
291 const video: VideoDetails = res.body
293 expect(video.name).to.equal('transcoded video')
294 expect(video.files).to.have.lengthOf(4)
298 after(async function () {
299 await cleanupTests(servers)