]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-imports.ts
emit more specific status codes on video upload (#3423)
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-imports.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
590fb506 2
590fb506 3import 'mocha'
b488ba1e 4import * as chai from 'chai'
590fb506 5import {
7c3b7976 6 cleanupTests,
590fb506
C
7 doubleFollow,
8 flushAndRunMultipleServers,
9 getMyUserInformation,
10 getMyVideos,
11 getVideo,
12 getVideosList,
3e17515e 13 immutableAssign,
b488ba1e 14 listVideoCaptions,
590fb506 15 ServerInfo,
b488ba1e
C
16 setAccessTokensToServers,
17 testCaptionFile
94565d52 18} from '../../../../shared/extra-utils'
b488ba1e 19import { areHttpImportTestsDisabled, testImage } from '../../../../shared/extra-utils/miscs/miscs'
94565d52 20import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
a1587156 21import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
b488ba1e 22import { VideoCaption, VideoDetails, VideoImport, VideoPrivacy } from '../../../../shared/models/videos'
590fb506
C
23
24const expect = chai.expect
25
26describe('Test video imports', function () {
27 let servers: ServerInfo[] = []
28 let channelIdServer1: number
29 let channelIdServer2: number
30
b488ba1e
C
31 if (areHttpImportTestsDisabled()) return
32
3e17515e
C
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
36
37 expect(videoHttp.name).to.equal('small video - youtube')
f9b6d51f
C
38 // FIXME: youtube-dl seems broken
39 // expect(videoHttp.category.label).to.equal('News & Politics')
1dee8d68 40 // expect(videoHttp.licence.label).to.equal('Attribution')
3e17515e
C
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)
17036be5
C
46
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)
3e17515e
C
51
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
56
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)
65 }
590fb506 66
3e17515e
C
67 expect(videoTorrent.name).to.contain('你好 世界 720p.mp4')
68 expect(videoMagnet.name).to.contain('super peertube2 video')
652c6416
C
69
70 const resCaptions = await listVideoCaptions(url, idHttp)
71 expect(resCaptions.body.total).to.equal(2)
590fb506
C
72 }
73
74 async function checkVideoServer2 (url: string, id: number | string) {
75 const res = await getVideo(url, id)
652c6416 76 const video: VideoDetails = res.body
590fb506
C
77
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' ])
85
86 expect(video.files).to.have.lengthOf(1)
652c6416
C
87
88 const resCaptions = await listVideoCaptions(url, id)
89 expect(resCaptions.body.total).to.equal(2)
590fb506
C
90 }
91
92 before(async function () {
93 this.timeout(30000)
94
95 // Run servers
96 servers = await flushAndRunMultipleServers(2)
97
98 await setAccessTokensToServers(servers)
99
100 {
101 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
a1587156 102 channelIdServer1 = res.body.videoChannels[0].id
590fb506
C
103 }
104
105 {
106 const res = await getMyUserInformation(servers[1].url, servers[1].accessToken)
a1587156 107 channelIdServer2 = res.body.videoChannels[0].id
590fb506
C
108 }
109
110 await doubleFollow(servers[0], servers[1])
111 })
112
3e17515e 113 it('Should import videos on server 1', async function () {
590fb506
C
114 this.timeout(60000)
115
3e17515e 116 const baseAttributes = {
590fb506
C
117 channelId: channelIdServer1,
118 privacy: VideoPrivacy.PUBLIC
119 }
3e17515e
C
120
121 {
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')
b1770a0a 125 expect(res.body.video.thumbnailPath).to.equal(`/static/thumbnails/${res.body.video.uuid}.jpg`)
20dcfd74 126 expect(res.body.video.previewPath).to.equal(`/lazy-static/previews/${res.body.video.uuid}.jpg`)
b1770a0a
K
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)
ba6e9e8f 129
130 const resCaptions = await listVideoCaptions(servers[0].url, res.body.video.id)
652c6416 131 const videoCaptions: VideoCaption[] = resCaptions.body.data
ba6e9e8f 132 expect(videoCaptions).to.have.lengthOf(2)
133
652c6416
C
134 const enCaption = videoCaptions.find(caption => caption.language.id === 'en')
135 expect(enCaption).to.exist
136 expect(enCaption.language.label).to.equal('English')
25ae2110 137 expect(enCaption.captionPath).to.equal(`/lazy-static/video-captions/${res.body.video.uuid}-en.vtt`)
ba6e9e8f 138 await testCaptionFile(servers[0].url, enCaption.captionPath, `WEBVTT
652c6416
C
139Kind: captions
140Language: en
ba6e9e8f 141
652c6416
C
14200:00:01.600 --> 00:00:04.200
143English (US)
ba6e9e8f 144
652c6416
C
14500:00:05.900 --> 00:00:07.999
146This is a subtitle in American English
ba6e9e8f 147
652c6416
C
14800:00:10.000 --> 00:00:14.000
149Adding subtitles is very easy to do`)
ba6e9e8f 150
652c6416
C
151 const frCaption = videoCaptions.find(caption => caption.language.id === 'fr')
152 expect(frCaption).to.exist
153 expect(frCaption.language.label).to.equal('French')
25ae2110 154 expect(frCaption.captionPath).to.equal(`/lazy-static/video-captions/${res.body.video.uuid}-fr.vtt`)
ba6e9e8f 155 await testCaptionFile(servers[0].url, frCaption.captionPath, `WEBVTT
652c6416
C
156Kind: captions
157Language: fr
ba6e9e8f 158
652c6416
C
15900:00:01.600 --> 00:00:04.200
160Français (FR)
ba6e9e8f 161
652c6416
C
16200:00:05.900 --> 00:00:07.999
163C'est un sous-titre français
ba6e9e8f 164
652c6416
C
16500:00:10.000 --> 00:00:14.000
166Ajouter un sous-titre est vraiment facile`)
3e17515e
C
167 }
168
169 {
170 const attributes = immutableAssign(baseAttributes, {
171 magnetUri: getMagnetURI(),
172 description: 'this is a super torrent description',
173 tags: [ 'tag_torrent1', 'tag_torrent2' ]
174 })
175 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
176 expect(res.body.video.name).to.equal('super peertube2 video')
177 }
178
179 {
180 const attributes = immutableAssign(baseAttributes, {
9a7fd960 181 torrentfile: 'video-720p.torrent' as any,
3e17515e
C
182 description: 'this is a super torrent description',
183 tags: [ 'tag_torrent1', 'tag_torrent2' ]
184 })
185 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
186 expect(res.body.video.name).to.equal('你好 世界 720p.mp4')
187 }
590fb506
C
188 })
189
3e17515e
C
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')
590fb506 192
3e17515e 193 expect(res.body.total).to.equal(3)
590fb506
C
194
195 const videos = res.body.data
3e17515e 196 expect(videos).to.have.lengthOf(3)
590fb506 197 expect(videos[0].name).to.equal('small video - youtube')
3e17515e
C
198 expect(videos[1].name).to.equal('super peertube2 video')
199 expect(videos[2].name).to.equal('你好 世界 720p.mp4')
590fb506
C
200 })
201
3e17515e
C
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')
204
205 expect(res.body.total).to.equal(3)
206 const videoImports: VideoImport[] = res.body.data
207 expect(videoImports).to.have.lengthOf(3)
208
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')
590fb506 213
3e17515e
C
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')
590fb506 218
3e17515e
C
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')
590fb506
C
223 })
224
3e17515e 225 it('Should have the video listed on the two instances', async function () {
590fb506
C
226 this.timeout(120000)
227
228 await waitJobs(servers)
229
230 for (const server of servers) {
231 const res = await getVideosList(server.url)
3e17515e
C
232 expect(res.body.total).to.equal(3)
233 expect(res.body.data).to.have.lengthOf(3)
590fb506 234
3e17515e
C
235 const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data
236 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
590fb506
C
237 }
238 })
239
240 it('Should import a video on server 2 with some fields', async function () {
241 this.timeout(60000)
242
243 const attributes = {
244 targetUrl: getYoutubeVideoUrl(),
3e17515e 245 channelId: channelIdServer2,
590fb506
C
246 privacy: VideoPrivacy.PUBLIC,
247 category: 10,
248 licence: 7,
249 language: 'en',
250 name: 'my super name',
251 description: 'my super description',
252 tags: [ 'supertag1', 'supertag2' ]
253 }
254 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
255 expect(res.body.video.name).to.equal('my super name')
256 })
257
3e17515e 258 it('Should have the videos listed on the two instances', async function () {
590fb506
C
259 this.timeout(120000)
260
261 await waitJobs(servers)
262
263 for (const server of servers) {
264 const res = await getVideosList(server.url)
3e17515e
C
265 expect(res.body.total).to.equal(4)
266 expect(res.body.data).to.have.lengthOf(4)
590fb506
C
267
268 await checkVideoServer2(server.url, res.body.data[0].uuid)
3e17515e 269
a1587156 270 const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data
3e17515e
C
271 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
272 }
273 })
274
275 it('Should import a video that will be transcoded', async function () {
276 this.timeout(120000)
277
278 const attributes = {
279 name: 'transcoded video',
280 magnetUri: getMagnetURI(),
281 channelId: channelIdServer2,
282 privacy: VideoPrivacy.PUBLIC
283 }
284 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
285 const videoUUID = res.body.video.uuid
286
287 await waitJobs(servers)
288
289 for (const server of servers) {
290 const res = await getVideo(server.url, videoUUID)
291 const video: VideoDetails = res.body
292
293 expect(video.name).to.equal('transcoded video')
294 expect(video.files).to.have.lengthOf(4)
590fb506
C
295 }
296 })
297
7c3b7976
C
298 after(async function () {
299 await cleanupTests(servers)
590fb506
C
300 })
301})