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')
66 const resCaptions = await listVideoCaptions(url, idHttp)
67 expect(resCaptions.body.total).to.equal(2)
70 async function checkVideoServer2 (url: string, id: number | string) {
71 const res = await getVideo(url, id)
72 const video: VideoDetails = res.body
74 expect(video.name).to.equal('my super name')
75 expect(video.category.label).to.equal('Entertainment')
76 expect(video.licence.label).to.equal('Public Domain Dedication')
77 expect(video.language.label).to.equal('English')
78 expect(video.nsfw).to.be.false
79 expect(video.description).to.equal('my super description')
80 expect(video.tags).to.deep.equal([ 'supertag1', 'supertag2' ])
82 expect(video.files).to.have.lengthOf(1)
84 const resCaptions = await listVideoCaptions(url, id)
85 expect(resCaptions.body.total).to.equal(2)
88 before(async function () {
92 servers = await flushAndRunMultipleServers(2)
94 await setAccessTokensToServers(servers)
97 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
98 channelIdServer1 = res.body.videoChannels[0].id
102 const res = await getMyUserInformation(servers[1].url, servers[1].accessToken)
103 channelIdServer2 = res.body.videoChannels[0].id
106 await doubleFollow(servers[0], servers[1])
109 it('Should import videos on server 1', async function () {
112 const baseAttributes = {
113 channelId: channelIdServer1,
114 privacy: VideoPrivacy.PUBLIC
118 const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() })
119 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
120 expect(res.body.video.name).to.equal('small video - youtube')
122 const resCaptions = await listVideoCaptions(servers[0].url, res.body.video.id)
123 const videoCaptions: VideoCaption[] = resCaptions.body.data
124 expect(videoCaptions).to.have.lengthOf(2)
126 const enCaption = videoCaptions.find(caption => caption.language.id === 'en')
127 expect(enCaption).to.exist
128 expect(enCaption.language.label).to.equal('English')
129 expect(enCaption.captionPath).to.equal(`/static/video-captions/${res.body.video.uuid}-en.vtt`)
130 await testCaptionFile(servers[0].url, enCaption.captionPath, `WEBVTT
134 00:00:01.600 --> 00:00:04.200
137 00:00:05.900 --> 00:00:07.999
138 This is a subtitle in American English
140 00:00:10.000 --> 00:00:14.000
141 Adding subtitles is very easy to do`)
143 const frCaption = videoCaptions.find(caption => caption.language.id === 'fr')
144 expect(frCaption).to.exist
145 expect(frCaption.language.label).to.equal('French')
146 expect(frCaption.captionPath).to.equal(`/static/video-captions/${res.body.video.uuid}-fr.vtt`)
147 await testCaptionFile(servers[0].url, frCaption.captionPath, `WEBVTT
151 00:00:01.600 --> 00:00:04.200
154 00:00:05.900 --> 00:00:07.999
155 C'est un sous-titre français
157 00:00:10.000 --> 00:00:14.000
158 Ajouter un sous-titre est vraiment facile`)
162 const attributes = immutableAssign(baseAttributes, {
163 magnetUri: getMagnetURI(),
164 description: 'this is a super torrent description',
165 tags: [ 'tag_torrent1', 'tag_torrent2' ]
167 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
168 expect(res.body.video.name).to.equal('super peertube2 video')
172 const attributes = immutableAssign(baseAttributes, {
173 torrentfile: 'video-720p.torrent',
174 description: 'this is a super torrent description',
175 tags: [ 'tag_torrent1', 'tag_torrent2' ]
177 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
178 expect(res.body.video.name).to.equal('你好 世界 720p.mp4')
182 it('Should list the videos to import in my videos on server 1', async function () {
183 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5, 'createdAt')
185 expect(res.body.total).to.equal(3)
187 const videos = res.body.data
188 expect(videos).to.have.lengthOf(3)
189 expect(videos[0].name).to.equal('small video - youtube')
190 expect(videos[1].name).to.equal('super peertube2 video')
191 expect(videos[2].name).to.equal('你好 世界 720p.mp4')
194 it('Should list the videos to import in my imports on server 1', async function () {
195 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken, '-createdAt')
197 expect(res.body.total).to.equal(3)
198 const videoImports: VideoImport[] = res.body.data
199 expect(videoImports).to.have.lengthOf(3)
201 expect(videoImports[2].targetUrl).to.equal(getYoutubeVideoUrl())
202 expect(videoImports[2].magnetUri).to.be.null
203 expect(videoImports[2].torrentName).to.be.null
204 expect(videoImports[2].video.name).to.equal('small video - youtube')
206 expect(videoImports[1].targetUrl).to.be.null
207 expect(videoImports[1].magnetUri).to.equal(getMagnetURI())
208 expect(videoImports[1].torrentName).to.be.null
209 expect(videoImports[1].video.name).to.equal('super peertube2 video')
211 expect(videoImports[0].targetUrl).to.be.null
212 expect(videoImports[0].magnetUri).to.be.null
213 expect(videoImports[0].torrentName).to.equal('video-720p.torrent')
214 expect(videoImports[0].video.name).to.equal('你好 世界 720p.mp4')
217 it('Should have the video listed on the two instances', async function () {
220 await waitJobs(servers)
222 for (const server of servers) {
223 const res = await getVideosList(server.url)
224 expect(res.body.total).to.equal(3)
225 expect(res.body.data).to.have.lengthOf(3)
227 const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data
228 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
232 it('Should import a video on server 2 with some fields', async function () {
236 targetUrl: getYoutubeVideoUrl(),
237 channelId: channelIdServer2,
238 privacy: VideoPrivacy.PUBLIC,
242 name: 'my super name',
243 description: 'my super description',
244 tags: [ 'supertag1', 'supertag2' ]
246 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
247 expect(res.body.video.name).to.equal('my super name')
250 it('Should have the videos listed on the two instances', async function () {
253 await waitJobs(servers)
255 for (const server of servers) {
256 const res = await getVideosList(server.url)
257 expect(res.body.total).to.equal(4)
258 expect(res.body.data).to.have.lengthOf(4)
260 await checkVideoServer2(server.url, res.body.data[0].uuid)
262 const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data
263 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
267 it('Should import a video that will be transcoded', async function () {
271 name: 'transcoded video',
272 magnetUri: getMagnetURI(),
273 channelId: channelIdServer2,
274 privacy: VideoPrivacy.PUBLIC
276 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
277 const videoUUID = res.body.video.uuid
279 await waitJobs(servers)
281 for (const server of servers) {
282 const res = await getVideo(server.url, videoUUID)
283 const video: VideoDetails = res.body
285 expect(video.name).to.equal('transcoded video')
286 expect(video.files).to.have.lengthOf(4)
290 after(async function () {
291 await cleanupTests(servers)