]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-imports.ts
Fix migrations
[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
C
2
3import * as chai from 'chai'
4import 'mocha'
ba6e9e8f 5import { VideoDetails, VideoImport, VideoPrivacy, VideoCaption } from '../../../../shared/models/videos'
590fb506 6import {
7c3b7976 7 cleanupTests,
590fb506
C
8 doubleFollow,
9 flushAndRunMultipleServers,
10 getMyUserInformation,
11 getMyVideos,
12 getVideo,
13 getVideosList,
ba6e9e8f 14 listVideoCaptions,
15 testCaptionFile,
3e17515e 16 immutableAssign,
590fb506
C
17 ServerInfo,
18 setAccessTokensToServers
94565d52
C
19} from '../../../../shared/extra-utils'
20import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
a1587156 21import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
b1770a0a 22import { testImage } from '../../../../shared/extra-utils/miscs/miscs'
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
3e17515e
C
31 async function checkVideosServer1 (url: string, idHttp: string, idMagnet: string, idTorrent: string) {
32 const resHttp = await getVideo(url, idHttp)
33 const videoHttp: VideoDetails = resHttp.body
34
35 expect(videoHttp.name).to.equal('small video - youtube')
6f2ae7a1 36 expect(videoHttp.category.label).to.equal('News & Politics')
3e17515e
C
37 expect(videoHttp.licence.label).to.equal('Attribution')
38 expect(videoHttp.language.label).to.equal('Unknown')
39 expect(videoHttp.nsfw).to.be.false
40 expect(videoHttp.description).to.equal('this is a super description')
41 expect(videoHttp.tags).to.deep.equal([ 'tag1', 'tag2' ])
42 expect(videoHttp.files).to.have.lengthOf(1)
17036be5
C
43
44 const originallyPublishedAt = new Date(videoHttp.originallyPublishedAt)
45 expect(originallyPublishedAt.getDate()).to.equal(14)
46 expect(originallyPublishedAt.getMonth()).to.equal(0)
47 expect(originallyPublishedAt.getFullYear()).to.equal(2019)
3e17515e
C
48
49 const resMagnet = await getVideo(url, idMagnet)
50 const videoMagnet: VideoDetails = resMagnet.body
51 const resTorrent = await getVideo(url, idTorrent)
52 const videoTorrent: VideoDetails = resTorrent.body
53
54 for (const video of [ videoMagnet, videoTorrent ]) {
55 expect(video.category.label).to.equal('Misc')
56 expect(video.licence.label).to.equal('Unknown')
57 expect(video.language.label).to.equal('Unknown')
58 expect(video.nsfw).to.be.false
59 expect(video.description).to.equal('this is a super torrent description')
60 expect(video.tags).to.deep.equal([ 'tag_torrent1', 'tag_torrent2' ])
61 expect(video.files).to.have.lengthOf(1)
62 }
590fb506 63
3e17515e
C
64 expect(videoTorrent.name).to.contain('你好 世界 720p.mp4')
65 expect(videoMagnet.name).to.contain('super peertube2 video')
652c6416
C
66
67 const resCaptions = await listVideoCaptions(url, idHttp)
68 expect(resCaptions.body.total).to.equal(2)
590fb506
C
69 }
70
71 async function checkVideoServer2 (url: string, id: number | string) {
72 const res = await getVideo(url, id)
652c6416 73 const video: VideoDetails = res.body
590fb506
C
74
75 expect(video.name).to.equal('my super name')
76 expect(video.category.label).to.equal('Entertainment')
77 expect(video.licence.label).to.equal('Public Domain Dedication')
78 expect(video.language.label).to.equal('English')
79 expect(video.nsfw).to.be.false
80 expect(video.description).to.equal('my super description')
81 expect(video.tags).to.deep.equal([ 'supertag1', 'supertag2' ])
82
83 expect(video.files).to.have.lengthOf(1)
652c6416
C
84
85 const resCaptions = await listVideoCaptions(url, id)
86 expect(resCaptions.body.total).to.equal(2)
590fb506
C
87 }
88
89 before(async function () {
90 this.timeout(30000)
91
92 // Run servers
93 servers = await flushAndRunMultipleServers(2)
94
95 await setAccessTokensToServers(servers)
96
97 {
98 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
a1587156 99 channelIdServer1 = res.body.videoChannels[0].id
590fb506
C
100 }
101
102 {
103 const res = await getMyUserInformation(servers[1].url, servers[1].accessToken)
a1587156 104 channelIdServer2 = res.body.videoChannels[0].id
590fb506
C
105 }
106
107 await doubleFollow(servers[0], servers[1])
108 })
109
3e17515e 110 it('Should import videos on server 1', async function () {
590fb506
C
111 this.timeout(60000)
112
3e17515e 113 const baseAttributes = {
590fb506
C
114 channelId: channelIdServer1,
115 privacy: VideoPrivacy.PUBLIC
116 }
3e17515e
C
117
118 {
119 const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() })
120 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
121 expect(res.body.video.name).to.equal('small video - youtube')
b1770a0a
K
122 expect(res.body.video.thumbnailPath).to.equal(`/static/thumbnails/${res.body.video.uuid}.jpg`)
123 expect(res.body.video.previewPath).to.equal(`/static/previews/${res.body.video.uuid}.jpg`)
124 await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath)
125 await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath)
ba6e9e8f 126
127 const resCaptions = await listVideoCaptions(servers[0].url, res.body.video.id)
652c6416 128 const videoCaptions: VideoCaption[] = resCaptions.body.data
ba6e9e8f 129 expect(videoCaptions).to.have.lengthOf(2)
130
652c6416
C
131 const enCaption = videoCaptions.find(caption => caption.language.id === 'en')
132 expect(enCaption).to.exist
133 expect(enCaption.language.label).to.equal('English')
ba6e9e8f 134 expect(enCaption.captionPath).to.equal(`/static/video-captions/${res.body.video.uuid}-en.vtt`)
135 await testCaptionFile(servers[0].url, enCaption.captionPath, `WEBVTT
652c6416
C
136Kind: captions
137Language: en
ba6e9e8f 138
652c6416
C
13900:00:01.600 --> 00:00:04.200
140English (US)
ba6e9e8f 141
652c6416
C
14200:00:05.900 --> 00:00:07.999
143This is a subtitle in American English
ba6e9e8f 144
652c6416
C
14500:00:10.000 --> 00:00:14.000
146Adding subtitles is very easy to do`)
ba6e9e8f 147
652c6416
C
148 const frCaption = videoCaptions.find(caption => caption.language.id === 'fr')
149 expect(frCaption).to.exist
150 expect(frCaption.language.label).to.equal('French')
151 expect(frCaption.captionPath).to.equal(`/static/video-captions/${res.body.video.uuid}-fr.vtt`)
ba6e9e8f 152 await testCaptionFile(servers[0].url, frCaption.captionPath, `WEBVTT
652c6416
C
153Kind: captions
154Language: fr
ba6e9e8f 155
652c6416
C
15600:00:01.600 --> 00:00:04.200
157Français (FR)
ba6e9e8f 158
652c6416
C
15900:00:05.900 --> 00:00:07.999
160C'est un sous-titre français
ba6e9e8f 161
652c6416
C
16200:00:10.000 --> 00:00:14.000
163Ajouter un sous-titre est vraiment facile`)
3e17515e
C
164 }
165
166 {
167 const attributes = immutableAssign(baseAttributes, {
168 magnetUri: getMagnetURI(),
169 description: 'this is a super torrent description',
170 tags: [ 'tag_torrent1', 'tag_torrent2' ]
171 })
172 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
173 expect(res.body.video.name).to.equal('super peertube2 video')
174 }
175
176 {
177 const attributes = immutableAssign(baseAttributes, {
178 torrentfile: 'video-720p.torrent',
179 description: 'this is a super torrent description',
180 tags: [ 'tag_torrent1', 'tag_torrent2' ]
181 })
182 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
183 expect(res.body.video.name).to.equal('你好 世界 720p.mp4')
184 }
590fb506
C
185 })
186
3e17515e
C
187 it('Should list the videos to import in my videos on server 1', async function () {
188 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5, 'createdAt')
590fb506 189
3e17515e 190 expect(res.body.total).to.equal(3)
590fb506
C
191
192 const videos = res.body.data
3e17515e 193 expect(videos).to.have.lengthOf(3)
590fb506 194 expect(videos[0].name).to.equal('small video - youtube')
3e17515e
C
195 expect(videos[1].name).to.equal('super peertube2 video')
196 expect(videos[2].name).to.equal('你好 世界 720p.mp4')
590fb506
C
197 })
198
3e17515e
C
199 it('Should list the videos to import in my imports on server 1', async function () {
200 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken, '-createdAt')
201
202 expect(res.body.total).to.equal(3)
203 const videoImports: VideoImport[] = res.body.data
204 expect(videoImports).to.have.lengthOf(3)
205
206 expect(videoImports[2].targetUrl).to.equal(getYoutubeVideoUrl())
207 expect(videoImports[2].magnetUri).to.be.null
208 expect(videoImports[2].torrentName).to.be.null
209 expect(videoImports[2].video.name).to.equal('small video - youtube')
590fb506 210
3e17515e
C
211 expect(videoImports[1].targetUrl).to.be.null
212 expect(videoImports[1].magnetUri).to.equal(getMagnetURI())
213 expect(videoImports[1].torrentName).to.be.null
214 expect(videoImports[1].video.name).to.equal('super peertube2 video')
590fb506 215
3e17515e
C
216 expect(videoImports[0].targetUrl).to.be.null
217 expect(videoImports[0].magnetUri).to.be.null
218 expect(videoImports[0].torrentName).to.equal('video-720p.torrent')
219 expect(videoImports[0].video.name).to.equal('你好 世界 720p.mp4')
590fb506
C
220 })
221
3e17515e 222 it('Should have the video listed on the two instances', async function () {
590fb506
C
223 this.timeout(120000)
224
225 await waitJobs(servers)
226
227 for (const server of servers) {
228 const res = await getVideosList(server.url)
3e17515e
C
229 expect(res.body.total).to.equal(3)
230 expect(res.body.data).to.have.lengthOf(3)
590fb506 231
3e17515e
C
232 const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data
233 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
590fb506
C
234 }
235 })
236
237 it('Should import a video on server 2 with some fields', async function () {
238 this.timeout(60000)
239
240 const attributes = {
241 targetUrl: getYoutubeVideoUrl(),
3e17515e 242 channelId: channelIdServer2,
590fb506
C
243 privacy: VideoPrivacy.PUBLIC,
244 category: 10,
245 licence: 7,
246 language: 'en',
247 name: 'my super name',
248 description: 'my super description',
249 tags: [ 'supertag1', 'supertag2' ]
250 }
251 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
252 expect(res.body.video.name).to.equal('my super name')
253 })
254
3e17515e 255 it('Should have the videos listed on the two instances', async function () {
590fb506
C
256 this.timeout(120000)
257
258 await waitJobs(servers)
259
260 for (const server of servers) {
261 const res = await getVideosList(server.url)
3e17515e
C
262 expect(res.body.total).to.equal(4)
263 expect(res.body.data).to.have.lengthOf(4)
590fb506
C
264
265 await checkVideoServer2(server.url, res.body.data[0].uuid)
3e17515e 266
a1587156 267 const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data
3e17515e
C
268 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
269 }
270 })
271
272 it('Should import a video that will be transcoded', async function () {
273 this.timeout(120000)
274
275 const attributes = {
276 name: 'transcoded video',
277 magnetUri: getMagnetURI(),
278 channelId: channelIdServer2,
279 privacy: VideoPrivacy.PUBLIC
280 }
281 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
282 const videoUUID = res.body.video.uuid
283
284 await waitJobs(servers)
285
286 for (const server of servers) {
287 const res = await getVideo(server.url, videoUUID)
288 const video: VideoDetails = res.body
289
290 expect(video.name).to.equal('transcoded video')
291 expect(video.files).to.have.lengthOf(4)
590fb506
C
292 }
293 })
294
7c3b7976
C
295 after(async function () {
296 await cleanupTests(servers)
590fb506
C
297 })
298})