1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
5 import { VideoDetails, VideoImport, VideoPrivacy, VideoCaption } from '../../../../shared/models/videos'
9 flushAndRunMultipleServers,
18 setAccessTokensToServers
19 } from '../../../../shared/extra-utils'
20 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
21 import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
23 const expect = chai.expect
25 describe('Test video imports', function () {
26 let servers: ServerInfo[] = []
27 let channelIdServer1: number
28 let channelIdServer2: number
30 async function checkVideosServer1 (url: string, idHttp: string, idMagnet: string, idTorrent: string) {
31 const resHttp = await getVideo(url, idHttp)
32 const videoHttp: VideoDetails = resHttp.body
34 expect(videoHttp.name).to.equal('small video - youtube')
35 expect(videoHttp.category.label).to.equal('News & Politics')
36 expect(videoHttp.licence.label).to.equal('Attribution')
37 expect(videoHttp.language.label).to.equal('Unknown')
38 expect(videoHttp.nsfw).to.be.false
39 expect(videoHttp.description).to.equal('this is a super description')
40 expect(videoHttp.tags).to.deep.equal([ 'tag1', 'tag2' ])
41 expect(videoHttp.files).to.have.lengthOf(1)
43 const originallyPublishedAt = new Date(videoHttp.originallyPublishedAt)
44 expect(originallyPublishedAt.getDate()).to.equal(14)
45 expect(originallyPublishedAt.getMonth()).to.equal(0)
46 expect(originallyPublishedAt.getFullYear()).to.equal(2019)
48 const resMagnet = await getVideo(url, idMagnet)
49 const videoMagnet: VideoDetails = resMagnet.body
50 const resTorrent = await getVideo(url, idTorrent)
51 const videoTorrent: VideoDetails = resTorrent.body
53 for (const video of [ videoMagnet, videoTorrent ]) {
54 expect(video.category.label).to.equal('Misc')
55 expect(video.licence.label).to.equal('Unknown')
56 expect(video.language.label).to.equal('Unknown')
57 expect(video.nsfw).to.be.false
58 expect(video.description).to.equal('this is a super torrent description')
59 expect(video.tags).to.deep.equal([ 'tag_torrent1', 'tag_torrent2' ])
60 expect(video.files).to.have.lengthOf(1)
63 expect(videoTorrent.name).to.contain('你好 世界 720p.mp4')
64 expect(videoMagnet.name).to.contain('super peertube2 video')
67 async function checkVideoServer2 (url: string, id: number | string) {
68 const res = await getVideo(url, id)
69 const video = res.body
71 expect(video.name).to.equal('my super name')
72 expect(video.category.label).to.equal('Entertainment')
73 expect(video.licence.label).to.equal('Public Domain Dedication')
74 expect(video.language.label).to.equal('English')
75 expect(video.nsfw).to.be.false
76 expect(video.description).to.equal('my super description')
77 expect(video.tags).to.deep.equal([ 'supertag1', 'supertag2' ])
79 expect(video.files).to.have.lengthOf(1)
82 before(async function () {
86 servers = await flushAndRunMultipleServers(2)
88 await setAccessTokensToServers(servers)
91 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
92 channelIdServer1 = res.body.videoChannels[0].id
96 const res = await getMyUserInformation(servers[1].url, servers[1].accessToken)
97 channelIdServer2 = res.body.videoChannels[0].id
100 await doubleFollow(servers[0], servers[1])
103 it('Should import videos on server 1', async function () {
106 const baseAttributes = {
107 channelId: channelIdServer1,
108 privacy: VideoPrivacy.PUBLIC
112 const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() })
113 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
114 expect(res.body.video.name).to.equal('small video - youtube')
116 const resCaptions = await listVideoCaptions(servers[0].url, res.body.video.id)
117 const videoCaptions: VideoCaption[] = resCaptions.body
118 expect(videoCaptions).to.have.lengthOf(2)
120 const enCaption = videoCaptions.filter(caption => caption.language.label === 'en')[0]
121 expect(enCaption).to.not(undefined)
122 expect(enCaption.language.label).to.equal('en')
123 expect(enCaption.captionPath).to.equal(`/static/video-captions/${res.body.video.uuid}-en.vtt`)
124 await testCaptionFile(servers[0].url, enCaption.captionPath, `WEBVTT
127 00:00:01.600 --> 00:00:04.200
131 00:00:05.900 --> 00:00:07.999
132 This is a subtitle in American English
135 00:00:10.000 --> 00:00:14.000
136 Adding subtitles is very easy to do`)
138 const frCaption = videoCaptions.filter(caption => caption.language.label === 'fr')[0]
139 expect(frCaption).to.not(undefined)
140 expect(frCaption.language.label).to.equal('fr')
141 expect(frCaption.captionPath).to.equal(`/static/video-captions/${res.body.video.uuid}-en.vtt`)
142 await testCaptionFile(servers[0].url, frCaption.captionPath, `WEBVTT
145 00:00:01,600 --> 00:00:04.200
149 00:00:05,900 --> 00:00:07.999
150 C'est un sous-titre français
153 00:00:10,000 --> 00:00:14.000
154 Ajouter un sous-titre est vraiment facile`)
158 const attributes = immutableAssign(baseAttributes, {
159 magnetUri: getMagnetURI(),
160 description: 'this is a super torrent description',
161 tags: [ 'tag_torrent1', 'tag_torrent2' ]
163 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
164 expect(res.body.video.name).to.equal('super peertube2 video')
168 const attributes = immutableAssign(baseAttributes, {
169 torrentfile: 'video-720p.torrent',
170 description: 'this is a super torrent description',
171 tags: [ 'tag_torrent1', 'tag_torrent2' ]
173 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
174 expect(res.body.video.name).to.equal('你好 世界 720p.mp4')
178 it('Should list the videos to import in my videos on server 1', async function () {
179 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5, 'createdAt')
181 expect(res.body.total).to.equal(3)
183 const videos = res.body.data
184 expect(videos).to.have.lengthOf(3)
185 expect(videos[0].name).to.equal('small video - youtube')
186 expect(videos[1].name).to.equal('super peertube2 video')
187 expect(videos[2].name).to.equal('你好 世界 720p.mp4')
190 it('Should list the videos to import in my imports on server 1', async function () {
191 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken, '-createdAt')
193 expect(res.body.total).to.equal(3)
194 const videoImports: VideoImport[] = res.body.data
195 expect(videoImports).to.have.lengthOf(3)
197 expect(videoImports[2].targetUrl).to.equal(getYoutubeVideoUrl())
198 expect(videoImports[2].magnetUri).to.be.null
199 expect(videoImports[2].torrentName).to.be.null
200 expect(videoImports[2].video.name).to.equal('small video - youtube')
202 expect(videoImports[1].targetUrl).to.be.null
203 expect(videoImports[1].magnetUri).to.equal(getMagnetURI())
204 expect(videoImports[1].torrentName).to.be.null
205 expect(videoImports[1].video.name).to.equal('super peertube2 video')
207 expect(videoImports[0].targetUrl).to.be.null
208 expect(videoImports[0].magnetUri).to.be.null
209 expect(videoImports[0].torrentName).to.equal('video-720p.torrent')
210 expect(videoImports[0].video.name).to.equal('你好 世界 720p.mp4')
213 it('Should have the video listed on the two instances', async function () {
216 await waitJobs(servers)
218 for (const server of servers) {
219 const res = await getVideosList(server.url)
220 expect(res.body.total).to.equal(3)
221 expect(res.body.data).to.have.lengthOf(3)
223 const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data
224 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
228 it('Should import a video on server 2 with some fields', async function () {
232 targetUrl: getYoutubeVideoUrl(),
233 channelId: channelIdServer2,
234 privacy: VideoPrivacy.PUBLIC,
238 name: 'my super name',
239 description: 'my super description',
240 tags: [ 'supertag1', 'supertag2' ]
242 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
243 expect(res.body.video.name).to.equal('my super name')
246 it('Should have the videos listed on the two instances', async function () {
249 await waitJobs(servers)
251 for (const server of servers) {
252 const res = await getVideosList(server.url)
253 expect(res.body.total).to.equal(4)
254 expect(res.body.data).to.have.lengthOf(4)
256 await checkVideoServer2(server.url, res.body.data[0].uuid)
258 const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data
259 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
263 it('Should import a video that will be transcoded', async function () {
267 name: 'transcoded video',
268 magnetUri: getMagnetURI(),
269 channelId: channelIdServer2,
270 privacy: VideoPrivacy.PUBLIC
272 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
273 const videoUUID = res.body.video.uuid
275 await waitJobs(servers)
277 for (const server of servers) {
278 const res = await getVideo(server.url, videoUUID)
279 const video: VideoDetails = res.body
281 expect(video.name).to.equal('transcoded video')
282 expect(video.files).to.have.lengthOf(4)
286 after(async function () {
287 await cleanupTests(servers)