]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/videos/videos.ts
Tests for viewsPerDay
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / videos / videos.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */
a20399c9
C
2
3import { expect } from 'chai'
df0b219d 4import { pathExists, readdir, readFile } from 'fs-extra'
fdbda9e3 5import * as parseTorrent from 'parse-torrent'
1d791a26 6import { extname, join } from 'path'
c5d31dba 7import * as request from 'supertest'
ac81d1a0
C
8import {
9 buildAbsoluteFixturePath,
62689b94
C
10 getMyUserInformation,
11 immutableAssign,
ac81d1a0
C
12 makeGetRequest,
13 makePutBodyRequest,
14 makeUploadRequest,
15 root,
16 ServerInfo,
17 testImage
18} from '../'
7cde3b9c 19import validator from 'validator'
d4681c00 20import { VideoDetails, VideoPrivacy } from '../../models/videos'
8f0bc73d 21import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, loadLanguages, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants'
e2600d8b 22import { dateIsValid, webtorrentAdd, buildServerDirectory } from '../miscs/miscs'
0e1dc3e7 23
8f0bc73d
C
24loadLanguages()
25
0e1dc3e7
C
26type VideoAttributes = {
27 name?: string
28 category?: number
29 licence?: number
9d3ef9fe 30 language?: string
0e1dc3e7 31 nsfw?: boolean
47564bbe 32 commentsEnabled?: boolean
7f2cfe3a 33 downloadEnabled?: boolean
2186386c 34 waitTranscoding?: boolean
0e1dc3e7 35 description?: string
7519127b 36 originallyPublishedAt?: string
0e1dc3e7 37 tags?: string[]
5f04dd2f 38 channelId?: number
11474c3c 39 privacy?: VideoPrivacy
0e1dc3e7 40 fixture?: string
ac81d1a0
C
41 thumbnailfile?: string
42 previewfile?: string
2baea0c7
C
43 scheduleUpdate?: {
44 updateAt: string
45 privacy?: VideoPrivacy
46 }
0e1dc3e7
C
47}
48
49function getVideoCategories (url: string) {
50 const path = '/api/v1/videos/categories'
51
eec63bbc
C
52 return makeGetRequest({
53 url,
59651eee
C
54 path,
55 statusCodeExpected: 200
eec63bbc 56 })
0e1dc3e7
C
57}
58
59function getVideoLicences (url: string) {
60 const path = '/api/v1/videos/licences'
61
eec63bbc
C
62 return makeGetRequest({
63 url,
59651eee
C
64 path,
65 statusCodeExpected: 200
eec63bbc 66 })
0e1dc3e7
C
67}
68
69function getVideoLanguages (url: string) {
70 const path = '/api/v1/videos/languages'
71
eec63bbc
C
72 return makeGetRequest({
73 url,
59651eee
C
74 path,
75 statusCodeExpected: 200
eec63bbc 76 })
0e1dc3e7
C
77}
78
11474c3c
C
79function getVideoPrivacies (url: string) {
80 const path = '/api/v1/videos/privacies'
81
eec63bbc
C
82 return makeGetRequest({
83 url,
59651eee
C
84 path,
85 statusCodeExpected: 200
eec63bbc 86 })
11474c3c
C
87}
88
11474c3c 89function getVideo (url: string, id: number | string, expectedStatus = 200) {
0e1dc3e7
C
90 const path = '/api/v1/videos/' + id
91
92 return request(url)
93 .get(path)
94 .set('Accept', 'application/json')
11474c3c
C
95 .expect(expectedStatus)
96}
97
8319d6ae
RK
98function getVideoFileMetadataUrl (url: string) {
99 return request(url)
100 .get('/')
101 .set('Accept', 'application/json')
102 .expect(200)
103 .expect('Content-Type', /json/)
104}
105
490b595a 106function viewVideo (url: string, id: number | string, expectedStatus = 204, xForwardedFor?: string) {
1f3e9fec
C
107 const path = '/api/v1/videos/' + id + '/views'
108
490b595a 109 const req = request(url)
1f3e9fec
C
110 .post(path)
111 .set('Accept', 'application/json')
490b595a
C
112
113 if (xForwardedFor) {
114 req.set('X-Forwarded-For', xForwardedFor)
115 }
116
117 return req.expect(expectedStatus)
1f3e9fec
C
118}
119
11474c3c
C
120function getVideoWithToken (url: string, token: string, id: number | string, expectedStatus = 200) {
121 const path = '/api/v1/videos/' + id
122
123 return request(url)
124 .get(path)
125 .set('Authorization', 'Bearer ' + token)
126 .set('Accept', 'application/json')
127 .expect(expectedStatus)
0e1dc3e7
C
128}
129
9567011b
C
130function getVideoDescription (url: string, descriptionPath: string) {
131 return request(url)
132 .get(descriptionPath)
133 .set('Accept', 'application/json')
134 .expect(200)
135 .expect('Content-Type', /json/)
136}
137
0e1dc3e7
C
138function getVideosList (url: string) {
139 const path = '/api/v1/videos'
140
141 return request(url)
142 .get(path)
143 .query({ sort: 'name' })
144 .set('Accept', 'application/json')
145 .expect(200)
146 .expect('Content-Type', /json/)
147}
148
d525fc39 149function getVideosListWithToken (url: string, token: string, query: { nsfw?: boolean } = {}) {
0883b324
C
150 const path = '/api/v1/videos'
151
152 return request(url)
153 .get(path)
154 .set('Authorization', 'Bearer ' + token)
d525fc39 155 .query(immutableAssign(query, { sort: 'name' }))
0883b324
C
156 .set('Accept', 'application/json')
157 .expect(200)
158 .expect('Content-Type', /json/)
159}
160
066e94c5
C
161function getLocalVideos (url: string) {
162 const path = '/api/v1/videos'
163
164 return request(url)
165 .get(path)
166 .query({ sort: 'name', filter: 'local' })
167 .set('Accept', 'application/json')
168 .expect(200)
169 .expect('Content-Type', /json/)
170}
171
cca1e13b 172function getMyVideos (url: string, accessToken: string, start: number, count: number, sort?: string, search?: string) {
11474c3c
C
173 const path = '/api/v1/users/me/videos'
174
175 const req = request(url)
176 .get(path)
177 .query({ start: start })
178 .query({ count: count })
cca1e13b 179 .query({ search: search })
11474c3c
C
180
181 if (sort) req.query({ sort })
182
183 return req.set('Accept', 'application/json')
184 .set('Authorization', 'Bearer ' + accessToken)
185 .expect(200)
186 .expect('Content-Type', /json/)
187}
188
d525fc39
C
189function getAccountVideos (
190 url: string,
191 accessToken: string,
192 accountName: string,
193 start: number,
194 count: number,
195 sort?: string,
196 query: { nsfw?: boolean } = {}
197) {
ad9e39fb 198 const path = '/api/v1/accounts/' + accountName + '/videos'
6b738c7a
C
199
200 return makeGetRequest({
201 url,
202 path,
d525fc39 203 query: immutableAssign(query, {
6b738c7a
C
204 start,
205 count,
206 sort
d525fc39 207 }),
6b738c7a
C
208 token: accessToken,
209 statusCodeExpected: 200
210 })
211}
212
213function getVideoChannelVideos (
214 url: string,
215 accessToken: string,
8a19bee1 216 videoChannelName: string,
6b738c7a
C
217 start: number,
218 count: number,
d525fc39
C
219 sort?: string,
220 query: { nsfw?: boolean } = {}
6b738c7a 221) {
8a19bee1 222 const path = '/api/v1/video-channels/' + videoChannelName + '/videos'
6b738c7a
C
223
224 return makeGetRequest({
225 url,
226 path,
d525fc39 227 query: immutableAssign(query, {
6b738c7a
C
228 start,
229 count,
230 sort
d525fc39 231 }),
6b738c7a
C
232 token: accessToken,
233 statusCodeExpected: 200
234 })
235}
236
418d092a
C
237function getPlaylistVideos (
238 url: string,
239 accessToken: string,
240 playlistId: number | string,
241 start: number,
242 count: number,
243 query: { nsfw?: boolean } = {}
244) {
245 const path = '/api/v1/video-playlists/' + playlistId + '/videos'
246
247 return makeGetRequest({
248 url,
249 path,
250 query: immutableAssign(query, {
251 start,
252 count
253 }),
254 token: accessToken,
255 statusCodeExpected: 200
256 })
257}
258
fe987656 259function getVideosListPagination (url: string, start: number, count: number, sort?: string, skipCount?: boolean) {
0e1dc3e7
C
260 const path = '/api/v1/videos'
261
262 const req = request(url)
263 .get(path)
264 .query({ start: start })
265 .query({ count: count })
266
267 if (sort) req.query({ sort })
fe987656 268 if (skipCount) req.query({ skipCount })
0e1dc3e7
C
269
270 return req.set('Accept', 'application/json')
271 .expect(200)
272 .expect('Content-Type', /json/)
273}
274
275function getVideosListSort (url: string, sort: string) {
276 const path = '/api/v1/videos'
277
278 return request(url)
279 .get(path)
280 .query({ sort: sort })
281 .set('Accept', 'application/json')
282 .expect(200)
283 .expect('Content-Type', /json/)
284}
285
d525fc39 286function getVideosWithFilters (url: string, query: { tagsAllOf: string[], categoryOneOf: number[] | number }) {
0e1dc3e7
C
287 const path = '/api/v1/videos'
288
289 return request(url)
57c36b27 290 .get(path)
d525fc39 291 .query(query)
f3aaa9a9 292 .set('Accept', 'application/json')
d525fc39 293 .expect(200)
f3aaa9a9 294 .expect('Content-Type', /json/)
0e1dc3e7
C
295}
296
d525fc39 297function removeVideo (url: string, token: string, id: number | string, expectedStatus = 204) {
0883b324 298 const path = '/api/v1/videos'
0e1dc3e7
C
299
300 return request(url)
d525fc39 301 .delete(path + '/' + id)
0e1dc3e7 302 .set('Accept', 'application/json')
d525fc39
C
303 .set('Authorization', 'Bearer ' + token)
304 .expect(expectedStatus)
0e1dc3e7
C
305}
306
25378bc8
C
307async function checkVideoFilesWereRemoved (
308 videoUUID: string,
309 serverNumber: number,
09209296
C
310 directories = [
311 'redundancy',
312 'videos',
313 'thumbnails',
314 'torrents',
315 'previews',
316 'captions',
317 join('playlists', 'hls'),
318 join('redundancy', 'hls')
319 ]
25378bc8 320) {
25378bc8 321 for (const directory of directories) {
e2600d8b 322 const directoryPath = buildServerDirectory(serverNumber, directory)
f05a1c30 323
df0b219d
C
324 const directoryExists = await pathExists(directoryPath)
325 if (directoryExists === false) continue
f05a1c30 326
62689b94 327 const files = await readdir(directoryPath)
f05a1c30
C
328 for (const file of files) {
329 expect(file).to.not.contain(videoUUID)
330 }
331 }
332}
333
e11f68a3 334async function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 200) {
e95561cd 335 const path = '/api/v1/videos/upload'
5f04dd2f
C
336 let defaultChannelId = '1'
337
338 try {
339 const res = await getMyUserInformation(url, accessToken)
340 defaultChannelId = res.body.videoChannels[0].id
341 } catch (e) { /* empty */ }
0e1dc3e7 342
ac81d1a0
C
343 // Override default attributes
344 const attributes = Object.assign({
0e1dc3e7
C
345 name: 'my super video',
346 category: 5,
347 licence: 4,
9d3ef9fe 348 language: 'zh',
5f04dd2f 349 channelId: defaultChannelId,
0e1dc3e7 350 nsfw: true,
2186386c 351 waitTranscoding: false,
0e1dc3e7 352 description: 'my super description',
2422c46b 353 support: 'my super support text',
0e1dc3e7 354 tags: [ 'tag' ],
11474c3c 355 privacy: VideoPrivacy.PUBLIC,
47564bbe 356 commentsEnabled: true,
7f2cfe3a 357 downloadEnabled: true,
0e1dc3e7 358 fixture: 'video_short.webm'
ac81d1a0 359 }, videoAttributesArg)
0e1dc3e7
C
360
361 const req = request(url)
362 .post(path)
363 .set('Accept', 'application/json')
364 .set('Authorization', 'Bearer ' + accessToken)
365 .field('name', attributes.name)
0e1dc3e7 366 .field('nsfw', JSON.stringify(attributes.nsfw))
47564bbe 367 .field('commentsEnabled', JSON.stringify(attributes.commentsEnabled))
7f2cfe3a 368 .field('downloadEnabled', JSON.stringify(attributes.downloadEnabled))
2186386c 369 .field('waitTranscoding', JSON.stringify(attributes.waitTranscoding))
11474c3c 370 .field('privacy', attributes.privacy.toString())
5f04dd2f 371 .field('channelId', attributes.channelId)
0e1dc3e7 372
fc8c024a
C
373 if (attributes.support !== undefined) {
374 req.field('support', attributes.support)
375 }
376
a87d467a
C
377 if (attributes.description !== undefined) {
378 req.field('description', attributes.description)
379 }
8df87ce7
C
380 if (attributes.language !== undefined) {
381 req.field('language', attributes.language.toString())
382 }
a7fea183
C
383 if (attributes.category !== undefined) {
384 req.field('category', attributes.category.toString())
385 }
386 if (attributes.licence !== undefined) {
387 req.field('licence', attributes.licence.toString())
388 }
8df87ce7 389
970ceac0
C
390 const tags = attributes.tags || []
391 for (let i = 0; i < tags.length; i++) {
2422c46b
C
392 req.field('tags[' + i + ']', attributes.tags[i])
393 }
394
ac81d1a0
C
395 if (attributes.thumbnailfile !== undefined) {
396 req.attach('thumbnailfile', buildAbsoluteFixturePath(attributes.thumbnailfile))
397 }
398 if (attributes.previewfile !== undefined) {
399 req.attach('previewfile', buildAbsoluteFixturePath(attributes.previewfile))
0e1dc3e7
C
400 }
401
2baea0c7
C
402 if (attributes.scheduleUpdate) {
403 req.field('scheduleUpdate[updateAt]', attributes.scheduleUpdate.updateAt)
404
405 if (attributes.scheduleUpdate.privacy) {
406 req.field('scheduleUpdate[privacy]', attributes.scheduleUpdate.privacy)
407 }
408 }
409
84929846
AM
410 if (attributes.originallyPublishedAt !== undefined) {
411 req.field('originallyPublishedAt', attributes.originallyPublishedAt)
412 }
413
ac81d1a0 414 return req.attach('videofile', buildAbsoluteFixturePath(attributes.fixture))
0e1dc3e7
C
415 .expect(specialStatus)
416}
417
ac81d1a0 418function updateVideo (url: string, accessToken: string, id: number | string, attributes: VideoAttributes, statusCodeExpected = 204) {
0e1dc3e7
C
419 const path = '/api/v1/videos/' + id
420 const body = {}
421
422 if (attributes.name) body['name'] = attributes.name
423 if (attributes.category) body['category'] = attributes.category
424 if (attributes.licence) body['licence'] = attributes.licence
425 if (attributes.language) body['language'] = attributes.language
47564bbe
C
426 if (attributes.nsfw !== undefined) body['nsfw'] = JSON.stringify(attributes.nsfw)
427 if (attributes.commentsEnabled !== undefined) body['commentsEnabled'] = JSON.stringify(attributes.commentsEnabled)
7f2cfe3a 428 if (attributes.downloadEnabled !== undefined) body['downloadEnabled'] = JSON.stringify(attributes.downloadEnabled)
7519127b 429 if (attributes.originallyPublishedAt !== undefined) body['originallyPublishedAt'] = attributes.originallyPublishedAt
0e1dc3e7
C
430 if (attributes.description) body['description'] = attributes.description
431 if (attributes.tags) body['tags'] = attributes.tags
11474c3c 432 if (attributes.privacy) body['privacy'] = attributes.privacy
0f320037 433 if (attributes.channelId) body['channelId'] = attributes.channelId
2baea0c7 434 if (attributes.scheduleUpdate) body['scheduleUpdate'] = attributes.scheduleUpdate
0e1dc3e7 435
ac81d1a0
C
436 // Upload request
437 if (attributes.thumbnailfile || attributes.previewfile) {
438 const attaches: any = {}
439 if (attributes.thumbnailfile) attaches.thumbnailfile = attributes.thumbnailfile
440 if (attributes.previewfile) attaches.previewfile = attributes.previewfile
441
442 return makeUploadRequest({
443 url,
444 method: 'PUT',
445 path,
446 token: accessToken,
447 fields: body,
448 attaches,
449 statusCodeExpected
450 })
451 }
452
453 return makePutBodyRequest({
454 url,
455 path,
456 fields: body,
457 token: accessToken,
458 statusCodeExpected
459 })
0e1dc3e7
C
460}
461
462function rateVideo (url: string, accessToken: string, id: number, rating: string, specialStatus = 204) {
463 const path = '/api/v1/videos/' + id + '/rate'
464
465 return request(url)
466 .put(path)
467 .set('Accept', 'application/json')
468 .set('Authorization', 'Bearer ' + accessToken)
469 .send({ rating })
470 .expect(specialStatus)
471}
472
14d3270f 473function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) {
fdbda9e3 474 return new Promise<any>((res, rej) => {
14d3270f 475 const torrentName = videoUUID + '-' + resolution + '.torrent'
ffc65cbd 476 const torrentPath = join(root(), 'test' + server.internalServerNumber, 'torrents', torrentName)
fdbda9e3
C
477 readFile(torrentPath, (err, data) => {
478 if (err) return rej(err)
479
480 return res(parseTorrent(data))
481 })
482 })
483}
484
a20399c9
C
485async function completeVideoCheck (
486 url: string,
487 video: any,
488 attributes: {
489 name: string
490 category: number
491 licence: number
9d3ef9fe 492 language: string
a20399c9 493 nsfw: boolean
47564bbe 494 commentsEnabled: boolean
7f2cfe3a 495 downloadEnabled: boolean
a20399c9 496 description: string
53a61317 497 publishedAt?: string
2422c46b 498 support: string
a1587156 499 originallyPublishedAt?: string
b64c950a
C
500 account: {
501 name: string
502 host: string
503 }
f6eebcb3
C
504 isLocal: boolean
505 tags: string[]
506 privacy: number
507 likes?: number
508 dislikes?: number
509 duration: number
a20399c9 510 channel: {
f6eebcb3
C
511 displayName: string
512 name: string
b1f5b93e 513 description
a20399c9
C
514 isLocal: boolean
515 }
f6eebcb3 516 fixture: string
a20399c9
C
517 files: {
518 resolution: number
519 size: number
a1587156 520 }[]
ac81d1a0
C
521 thumbnailfile?: string
522 previewfile?: string
a20399c9
C
523 }
524) {
b1f5b93e
C
525 if (!attributes.likes) attributes.likes = 0
526 if (!attributes.dislikes) attributes.dislikes = 0
527
a20399c9 528 expect(video.name).to.equal(attributes.name)
09700934 529 expect(video.category.id).to.equal(attributes.category)
9d3ef9fe 530 expect(video.category.label).to.equal(attributes.category !== null ? VIDEO_CATEGORIES[attributes.category] : 'Misc')
09700934 531 expect(video.licence.id).to.equal(attributes.licence)
9d3ef9fe 532 expect(video.licence.label).to.equal(attributes.licence !== null ? VIDEO_LICENCES[attributes.licence] : 'Unknown')
09700934 533 expect(video.language.id).to.equal(attributes.language)
9d3ef9fe 534 expect(video.language.label).to.equal(attributes.language !== null ? VIDEO_LANGUAGES[attributes.language] : 'Unknown')
2243730c
C
535 expect(video.privacy.id).to.deep.equal(attributes.privacy)
536 expect(video.privacy.label).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy])
a20399c9
C
537 expect(video.nsfw).to.equal(attributes.nsfw)
538 expect(video.description).to.equal(attributes.description)
03e12d7c 539 expect(video.account.id).to.be.a('number')
b64c950a
C
540 expect(video.account.host).to.equal(attributes.account.host)
541 expect(video.account.name).to.equal(attributes.account.name)
f6eebcb3
C
542 expect(video.channel.displayName).to.equal(attributes.channel.displayName)
543 expect(video.channel.name).to.equal(attributes.channel.name)
b1f5b93e
C
544 expect(video.likes).to.equal(attributes.likes)
545 expect(video.dislikes).to.equal(attributes.dislikes)
a20399c9 546 expect(video.isLocal).to.equal(attributes.isLocal)
b1f5b93e 547 expect(video.duration).to.equal(attributes.duration)
a20399c9 548 expect(dateIsValid(video.createdAt)).to.be.true
c49db162 549 expect(dateIsValid(video.publishedAt)).to.be.true
a20399c9
C
550 expect(dateIsValid(video.updatedAt)).to.be.true
551
53a61317 552 if (attributes.publishedAt) {
53a61317
C
553 expect(video.publishedAt).to.equal(attributes.publishedAt)
554 }
555
7519127b
C
556 if (attributes.originallyPublishedAt) {
557 expect(video.originallyPublishedAt).to.equal(attributes.originallyPublishedAt)
558 } else {
559 expect(video.originallyPublishedAt).to.be.null
560 }
561
66b16caf 562 const res = await getVideo(url, video.uuid)
0f320037 563 const videoDetails: VideoDetails = res.body
a20399c9
C
564
565 expect(videoDetails.files).to.have.lengthOf(attributes.files.length)
566 expect(videoDetails.tags).to.deep.equal(attributes.tags)
19a3b914
C
567 expect(videoDetails.account.name).to.equal(attributes.account.name)
568 expect(videoDetails.account.host).to.equal(attributes.account.host)
f6eebcb3
C
569 expect(video.channel.displayName).to.equal(attributes.channel.displayName)
570 expect(video.channel.name).to.equal(attributes.channel.name)
0f320037 571 expect(videoDetails.channel.host).to.equal(attributes.account.host)
a20399c9 572 expect(videoDetails.channel.isLocal).to.equal(attributes.channel.isLocal)
0f320037
C
573 expect(dateIsValid(videoDetails.channel.createdAt.toString())).to.be.true
574 expect(dateIsValid(videoDetails.channel.updatedAt.toString())).to.be.true
575 expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled)
7f2cfe3a 576 expect(videoDetails.downloadEnabled).to.equal(attributes.downloadEnabled)
a20399c9
C
577
578 for (const attributeFile of attributes.files) {
5d00a3d7 579 const file = videoDetails.files.find(f => f.resolution.id === attributeFile.resolution)
a20399c9
C
580 expect(file).not.to.be.undefined
581
b1f5b93e 582 let extension = extname(attributes.fixture)
48f07b4a
C
583 // Transcoding enabled: extension will always be .mp4
584 if (attributes.files.length > 1) extension = '.mp4'
b1f5b93e 585
a20399c9 586 expect(file.magnetUri).to.have.lengthOf.above(2)
5d00a3d7
C
587 expect(file.torrentUrl).to.equal(`http://${attributes.account.host}/static/torrents/${videoDetails.uuid}-${file.resolution.id}.torrent`)
588 expect(file.fileUrl).to.equal(`http://${attributes.account.host}/static/webseed/${videoDetails.uuid}-${file.resolution.id}${extension}`)
09700934
C
589 expect(file.resolution.id).to.equal(attributeFile.resolution)
590 expect(file.resolution.label).to.equal(attributeFile.resolution + 'p')
b1f5b93e
C
591
592 const minSize = attributeFile.size - ((10 * attributeFile.size) / 100)
593 const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100)
a1587156
C
594 expect(
595 file.size,
596 'File size for resolution ' + file.resolution.label + ' outside confidence interval (' + minSize + '> size <' + maxSize + ')'
597 ).to.be.above(minSize).and.below(maxSize)
a20399c9 598
d7a25329 599 const torrent = await webtorrentAdd(file.magnetUri, true)
a20399c9
C
600 expect(torrent.files).to.be.an('array')
601 expect(torrent.files.length).to.equal(1)
602 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
603 }
44d4ee4f
C
604
605 await testImage(url, attributes.thumbnailfile || attributes.fixture, videoDetails.thumbnailPath)
606
607 if (attributes.previewfile) {
608 await testImage(url, attributes.previewfile, videoDetails.previewPath)
609 }
a20399c9
C
610}
611
df0b219d
C
612async function videoUUIDToId (url: string, id: number | string) {
613 if (validator.isUUID('' + id) === false) return id
614
615 const res = await getVideo(url, id)
616 return res.body.id
617}
618
b764380a 619async function uploadVideoAndGetId (options: {
a1587156
C
620 server: ServerInfo
621 videoName: string
622 nsfw?: boolean
623 privacy?: VideoPrivacy
b764380a
C
624 token?: string
625}) {
df0b219d
C
626 const videoAttrs: any = { name: options.videoName }
627 if (options.nsfw) videoAttrs.nsfw = options.nsfw
b764380a 628 if (options.privacy) videoAttrs.privacy = options.privacy
df0b219d 629
df0b219d
C
630 const res = await uploadVideo(options.server.url, options.token || options.server.accessToken, videoAttrs)
631
632 return { id: res.body.video.id, uuid: res.body.video.uuid }
633}
634
b764380a
C
635async function getLocalIdByUUID (url: string, uuid: string) {
636 const res = await getVideo(url, uuid)
637
638 return res.body.id
639}
640
0e1dc3e7
C
641// ---------------------------------------------------------------------------
642
643export {
9567011b 644 getVideoDescription,
0e1dc3e7
C
645 getVideoCategories,
646 getVideoLicences,
df0b219d 647 videoUUIDToId,
11474c3c 648 getVideoPrivacies,
0e1dc3e7 649 getVideoLanguages,
11474c3c 650 getMyVideos,
6b738c7a
C
651 getAccountVideos,
652 getVideoChannelVideos,
0e1dc3e7 653 getVideo,
8319d6ae 654 getVideoFileMetadataUrl,
11474c3c 655 getVideoWithToken,
0e1dc3e7
C
656 getVideosList,
657 getVideosListPagination,
658 getVideosListSort,
659 removeVideo,
0883b324 660 getVideosListWithToken,
0e1dc3e7 661 uploadVideo,
d525fc39 662 getVideosWithFilters,
0e1dc3e7 663 updateVideo,
fdbda9e3 664 rateVideo,
1f3e9fec 665 viewVideo,
a20399c9 666 parseTorrentVideo,
066e94c5 667 getLocalVideos,
f05a1c30 668 completeVideoCheck,
418d092a 669 checkVideoFilesWereRemoved,
df0b219d 670 getPlaylistVideos,
b764380a
C
671 uploadVideoAndGetId,
672 getLocalIdByUUID
0e1dc3e7 673}