aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/video-imports.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/videos/video-imports.ts')
-rw-r--r--server/tests/api/videos/video-imports.ts172
1 files changed, 77 insertions, 95 deletions
diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts
index 80834ca86..2eac130d2 100644
--- a/server/tests/api/videos/video-imports.ts
+++ b/server/tests/api/videos/video-imports.ts
@@ -3,43 +3,30 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 areHttpImportTestsDisabled,
6 cleanupTests, 7 cleanupTests,
8 createMultipleServers,
7 doubleFollow, 9 doubleFollow,
8 flushAndRunMultipleServers, 10 FIXTURE_URLS,
9 getMyUserInformation, 11 PeerTubeServer,
10 getMyVideos,
11 getVideo,
12 getVideosList,
13 immutableAssign,
14 listVideoCaptions,
15 ServerInfo,
16 setAccessTokensToServers, 12 setAccessTokensToServers,
17 testCaptionFile, 13 testCaptionFile,
18 updateCustomSubConfig 14 testImage,
19} from '../../../../shared/extra-utils' 15 waitJobs
20import { areHttpImportTestsDisabled, testImage } from '../../../../shared/extra-utils/miscs/miscs' 16} from '@shared/extra-utils'
21import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 17import { VideoPrivacy, VideoResolution } from '@shared/models'
22import {
23 getMagnetURI,
24 getMyVideoImports,
25 getYoutubeHDRVideoUrl,
26 getYoutubeVideoUrl,
27 importVideo
28} from '../../../../shared/extra-utils/videos/video-imports'
29import { VideoCaption, VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos'
30 18
31const expect = chai.expect 19const expect = chai.expect
32 20
33describe('Test video imports', function () { 21describe('Test video imports', function () {
34 let servers: ServerInfo[] = [] 22 let servers: PeerTubeServer[] = []
35 let channelIdServer1: number 23 let channelIdServer1: number
36 let channelIdServer2: number 24 let channelIdServer2: number
37 25
38 if (areHttpImportTestsDisabled()) return 26 if (areHttpImportTestsDisabled()) return
39 27
40 async function checkVideosServer1 (url: string, idHttp: string, idMagnet: string, idTorrent: string) { 28 async function checkVideosServer1 (server: PeerTubeServer, idHttp: string, idMagnet: string, idTorrent: string) {
41 const resHttp = await getVideo(url, idHttp) 29 const videoHttp = await server.videos.get({ id: idHttp })
42 const videoHttp: VideoDetails = resHttp.body
43 30
44 expect(videoHttp.name).to.equal('small video - youtube') 31 expect(videoHttp.name).to.equal('small video - youtube')
45 // FIXME: youtube-dl seems broken 32 // FIXME: youtube-dl seems broken
@@ -56,10 +43,8 @@ describe('Test video imports', function () {
56 expect(originallyPublishedAt.getMonth()).to.equal(0) 43 expect(originallyPublishedAt.getMonth()).to.equal(0)
57 expect(originallyPublishedAt.getFullYear()).to.equal(2019) 44 expect(originallyPublishedAt.getFullYear()).to.equal(2019)
58 45
59 const resMagnet = await getVideo(url, idMagnet) 46 const videoMagnet = await server.videos.get({ id: idMagnet })
60 const videoMagnet: VideoDetails = resMagnet.body 47 const videoTorrent = await server.videos.get({ id: idTorrent })
61 const resTorrent = await getVideo(url, idTorrent)
62 const videoTorrent: VideoDetails = resTorrent.body
63 48
64 for (const video of [ videoMagnet, videoTorrent ]) { 49 for (const video of [ videoMagnet, videoTorrent ]) {
65 expect(video.category.label).to.equal('Misc') 50 expect(video.category.label).to.equal('Misc')
@@ -74,13 +59,12 @@ describe('Test video imports', function () {
74 expect(videoTorrent.name).to.contain('你好 世界 720p.mp4') 59 expect(videoTorrent.name).to.contain('你好 世界 720p.mp4')
75 expect(videoMagnet.name).to.contain('super peertube2 video') 60 expect(videoMagnet.name).to.contain('super peertube2 video')
76 61
77 const resCaptions = await listVideoCaptions(url, idHttp) 62 const bodyCaptions = await server.captions.list({ videoId: idHttp })
78 expect(resCaptions.body.total).to.equal(2) 63 expect(bodyCaptions.total).to.equal(2)
79 } 64 }
80 65
81 async function checkVideoServer2 (url: string, id: number | string) { 66 async function checkVideoServer2 (server: PeerTubeServer, id: number | string) {
82 const res = await getVideo(url, id) 67 const video = await server.videos.get({ id })
83 const video: VideoDetails = res.body
84 68
85 expect(video.name).to.equal('my super name') 69 expect(video.name).to.equal('my super name')
86 expect(video.category.label).to.equal('Entertainment') 70 expect(video.category.label).to.equal('Entertainment')
@@ -92,26 +76,26 @@ describe('Test video imports', function () {
92 76
93 expect(video.files).to.have.lengthOf(1) 77 expect(video.files).to.have.lengthOf(1)
94 78
95 const resCaptions = await listVideoCaptions(url, id) 79 const bodyCaptions = await server.captions.list({ videoId: id })
96 expect(resCaptions.body.total).to.equal(2) 80 expect(bodyCaptions.total).to.equal(2)
97 } 81 }
98 82
99 before(async function () { 83 before(async function () {
100 this.timeout(30_000) 84 this.timeout(30_000)
101 85
102 // Run servers 86 // Run servers
103 servers = await flushAndRunMultipleServers(2) 87 servers = await createMultipleServers(2)
104 88
105 await setAccessTokensToServers(servers) 89 await setAccessTokensToServers(servers)
106 90
107 { 91 {
108 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) 92 const { videoChannels } = await servers[0].users.getMyInfo()
109 channelIdServer1 = res.body.videoChannels[0].id 93 channelIdServer1 = videoChannels[0].id
110 } 94 }
111 95
112 { 96 {
113 const res = await getMyUserInformation(servers[1].url, servers[1].accessToken) 97 const { videoChannels } = await servers[1].users.getMyInfo()
114 channelIdServer2 = res.body.videoChannels[0].id 98 channelIdServer2 = videoChannels[0].id
115 } 99 }
116 100
117 await doubleFollow(servers[0], servers[1]) 101 await doubleFollow(servers[0], servers[1])
@@ -126,18 +110,18 @@ describe('Test video imports', function () {
126 } 110 }
127 111
128 { 112 {
129 const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }) 113 const attributes = { ...baseAttributes, targetUrl: FIXTURE_URLS.youtube }
130 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 114 const { video } = await servers[0].imports.importVideo({ attributes })
131 expect(res.body.video.name).to.equal('small video - youtube') 115 expect(video.name).to.equal('small video - youtube')
132 116
133 expect(res.body.video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`)) 117 expect(video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`))
134 expect(res.body.video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`)) 118 expect(video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`))
135 119
136 await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath) 120 await testImage(servers[0].url, 'video_import_thumbnail', video.thumbnailPath)
137 await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath) 121 await testImage(servers[0].url, 'video_import_preview', video.previewPath)
138 122
139 const resCaptions = await listVideoCaptions(servers[0].url, res.body.video.id) 123 const bodyCaptions = await servers[0].captions.list({ videoId: video.id })
140 const videoCaptions: VideoCaption[] = resCaptions.body.data 124 const videoCaptions = bodyCaptions.data
141 expect(videoCaptions).to.have.lengthOf(2) 125 expect(videoCaptions).to.have.lengthOf(2)
142 126
143 const enCaption = videoCaptions.find(caption => caption.language.id === 'en') 127 const enCaption = videoCaptions.find(caption => caption.language.id === 'en')
@@ -176,52 +160,52 @@ Ajouter un sous-titre est vraiment facile`)
176 } 160 }
177 161
178 { 162 {
179 const attributes = immutableAssign(baseAttributes, { 163 const attributes = {
180 magnetUri: getMagnetURI(), 164 ...baseAttributes,
165 magnetUri: FIXTURE_URLS.magnet,
181 description: 'this is a super torrent description', 166 description: 'this is a super torrent description',
182 tags: [ 'tag_torrent1', 'tag_torrent2' ] 167 tags: [ 'tag_torrent1', 'tag_torrent2' ]
183 }) 168 }
184 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 169 const { video } = await servers[0].imports.importVideo({ attributes })
185 expect(res.body.video.name).to.equal('super peertube2 video') 170 expect(video.name).to.equal('super peertube2 video')
186 } 171 }
187 172
188 { 173 {
189 const attributes = immutableAssign(baseAttributes, { 174 const attributes = {
175 ...baseAttributes,
190 torrentfile: 'video-720p.torrent' as any, 176 torrentfile: 'video-720p.torrent' as any,
191 description: 'this is a super torrent description', 177 description: 'this is a super torrent description',
192 tags: [ 'tag_torrent1', 'tag_torrent2' ] 178 tags: [ 'tag_torrent1', 'tag_torrent2' ]
193 }) 179 }
194 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 180 const { video } = await servers[0].imports.importVideo({ attributes })
195 expect(res.body.video.name).to.equal('你好 世界 720p.mp4') 181 expect(video.name).to.equal('你好 世界 720p.mp4')
196 } 182 }
197 }) 183 })
198 184
199 it('Should list the videos to import in my videos on server 1', async function () { 185 it('Should list the videos to import in my videos on server 1', async function () {
200 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5, 'createdAt') 186 const { total, data } = await servers[0].videos.listMyVideos({ sort: 'createdAt' })
201 187
202 expect(res.body.total).to.equal(3) 188 expect(total).to.equal(3)
203 189
204 const videos = res.body.data 190 expect(data).to.have.lengthOf(3)
205 expect(videos).to.have.lengthOf(3) 191 expect(data[0].name).to.equal('small video - youtube')
206 expect(videos[0].name).to.equal('small video - youtube') 192 expect(data[1].name).to.equal('super peertube2 video')
207 expect(videos[1].name).to.equal('super peertube2 video') 193 expect(data[2].name).to.equal('你好 世界 720p.mp4')
208 expect(videos[2].name).to.equal('你好 世界 720p.mp4')
209 }) 194 })
210 195
211 it('Should list the videos to import in my imports on server 1', async function () { 196 it('Should list the videos to import in my imports on server 1', async function () {
212 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken, '-createdAt') 197 const { total, data: videoImports } = await servers[0].imports.getMyVideoImports({ sort: '-createdAt' })
198 expect(total).to.equal(3)
213 199
214 expect(res.body.total).to.equal(3)
215 const videoImports: VideoImport[] = res.body.data
216 expect(videoImports).to.have.lengthOf(3) 200 expect(videoImports).to.have.lengthOf(3)
217 201
218 expect(videoImports[2].targetUrl).to.equal(getYoutubeVideoUrl()) 202 expect(videoImports[2].targetUrl).to.equal(FIXTURE_URLS.youtube)
219 expect(videoImports[2].magnetUri).to.be.null 203 expect(videoImports[2].magnetUri).to.be.null
220 expect(videoImports[2].torrentName).to.be.null 204 expect(videoImports[2].torrentName).to.be.null
221 expect(videoImports[2].video.name).to.equal('small video - youtube') 205 expect(videoImports[2].video.name).to.equal('small video - youtube')
222 206
223 expect(videoImports[1].targetUrl).to.be.null 207 expect(videoImports[1].targetUrl).to.be.null
224 expect(videoImports[1].magnetUri).to.equal(getMagnetURI()) 208 expect(videoImports[1].magnetUri).to.equal(FIXTURE_URLS.magnet)
225 expect(videoImports[1].torrentName).to.be.null 209 expect(videoImports[1].torrentName).to.be.null
226 expect(videoImports[1].video.name).to.equal('super peertube2 video') 210 expect(videoImports[1].video.name).to.equal('super peertube2 video')
227 211
@@ -237,12 +221,12 @@ Ajouter un sous-titre est vraiment facile`)
237 await waitJobs(servers) 221 await waitJobs(servers)
238 222
239 for (const server of servers) { 223 for (const server of servers) {
240 const res = await getVideosList(server.url) 224 const { total, data } = await server.videos.list()
241 expect(res.body.total).to.equal(3) 225 expect(total).to.equal(3)
242 expect(res.body.data).to.have.lengthOf(3) 226 expect(data).to.have.lengthOf(3)
243 227
244 const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data 228 const [ videoHttp, videoMagnet, videoTorrent ] = data
245 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) 229 await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
246 } 230 }
247 }) 231 })
248 232
@@ -250,7 +234,7 @@ Ajouter un sous-titre est vraiment facile`)
250 this.timeout(60_000) 234 this.timeout(60_000)
251 235
252 const attributes = { 236 const attributes = {
253 targetUrl: getYoutubeVideoUrl(), 237 targetUrl: FIXTURE_URLS.youtube,
254 channelId: channelIdServer2, 238 channelId: channelIdServer2,
255 privacy: VideoPrivacy.PUBLIC, 239 privacy: VideoPrivacy.PUBLIC,
256 category: 10, 240 category: 10,
@@ -260,8 +244,8 @@ Ajouter un sous-titre est vraiment facile`)
260 description: 'my super description', 244 description: 'my super description',
261 tags: [ 'supertag1', 'supertag2' ] 245 tags: [ 'supertag1', 'supertag2' ]
262 } 246 }
263 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) 247 const { video } = await servers[1].imports.importVideo({ attributes })
264 expect(res.body.video.name).to.equal('my super name') 248 expect(video.name).to.equal('my super name')
265 }) 249 })
266 250
267 it('Should have the videos listed on the two instances', async function () { 251 it('Should have the videos listed on the two instances', async function () {
@@ -270,14 +254,14 @@ Ajouter un sous-titre est vraiment facile`)
270 await waitJobs(servers) 254 await waitJobs(servers)
271 255
272 for (const server of servers) { 256 for (const server of servers) {
273 const res = await getVideosList(server.url) 257 const { total, data } = await server.videos.list()
274 expect(res.body.total).to.equal(4) 258 expect(total).to.equal(4)
275 expect(res.body.data).to.have.lengthOf(4) 259 expect(data).to.have.lengthOf(4)
276 260
277 await checkVideoServer2(server.url, res.body.data[0].uuid) 261 await checkVideoServer2(server, data[0].uuid)
278 262
279 const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data 263 const [ , videoHttp, videoMagnet, videoTorrent ] = data
280 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) 264 await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
281 } 265 }
282 }) 266 })
283 267
@@ -286,18 +270,17 @@ Ajouter un sous-titre est vraiment facile`)
286 270
287 const attributes = { 271 const attributes = {
288 name: 'transcoded video', 272 name: 'transcoded video',
289 magnetUri: getMagnetURI(), 273 magnetUri: FIXTURE_URLS.magnet,
290 channelId: channelIdServer2, 274 channelId: channelIdServer2,
291 privacy: VideoPrivacy.PUBLIC 275 privacy: VideoPrivacy.PUBLIC
292 } 276 }
293 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) 277 const { video } = await servers[1].imports.importVideo({ attributes })
294 const videoUUID = res.body.video.uuid 278 const videoUUID = video.uuid
295 279
296 await waitJobs(servers) 280 await waitJobs(servers)
297 281
298 for (const server of servers) { 282 for (const server of servers) {
299 const res = await getVideo(server.url, videoUUID) 283 const video = await server.videos.get({ id: videoUUID })
300 const video: VideoDetails = res.body
301 284
302 expect(video.name).to.equal('transcoded video') 285 expect(video.name).to.equal('transcoded video')
303 expect(video.files).to.have.lengthOf(4) 286 expect(video.files).to.have.lengthOf(4)
@@ -333,22 +316,21 @@ Ajouter un sous-titre est vraiment facile`)
333 } 316 }
334 } 317 }
335 } 318 }
336 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) 319 await servers[0].config.updateCustomSubConfig({ newConfig: config })
337 320
338 const attributes = { 321 const attributes = {
339 name: 'hdr video', 322 name: 'hdr video',
340 targetUrl: getYoutubeHDRVideoUrl(), 323 targetUrl: FIXTURE_URLS.youtubeHDR,
341 channelId: channelIdServer1, 324 channelId: channelIdServer1,
342 privacy: VideoPrivacy.PUBLIC 325 privacy: VideoPrivacy.PUBLIC
343 } 326 }
344 const res1 = await importVideo(servers[0].url, servers[0].accessToken, attributes) 327 const { video: videoImported } = await servers[0].imports.importVideo({ attributes })
345 const videoUUID = res1.body.video.uuid 328 const videoUUID = videoImported.uuid
346 329
347 await waitJobs(servers) 330 await waitJobs(servers)
348 331
349 // test resolution 332 // test resolution
350 const res2 = await getVideo(servers[0].url, videoUUID) 333 const video = await servers[0].videos.get({ id: videoUUID })
351 const video: VideoDetails = res2.body
352 expect(video.name).to.equal('hdr video') 334 expect(video.name).to.equal('hdr video')
353 const maxResolution = Math.max.apply(Math, video.files.map(function (o) { return o.resolution.id })) 335 const maxResolution = Math.max.apply(Math, video.files.map(function (o) { return o.resolution.id }))
354 expect(maxResolution, 'expected max resolution not met').to.equals(VideoResolution.H_1080P) 336 expect(maxResolution, 'expected max resolution not met').to.equals(VideoResolution.H_1080P)