diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-08 16:49:51 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:18 +0200 |
commit | 6910f20f114b5bd020258a3a9a3f2117819a60c2 (patch) | |
tree | 0f50d33e20814b581dd9b2c175e511ac7a66f8df | |
parent | 313228e9c3b5bcef5391228c9b949d05d32ad7bb (diff) | |
download | PeerTube-6910f20f114b5bd020258a3a9a3f2117819a60c2.tar.gz PeerTube-6910f20f114b5bd020258a3a9a3f2117819a60c2.tar.zst PeerTube-6910f20f114b5bd020258a3a9a3f2117819a60c2.zip |
Introduce import command
-rw-r--r-- | server/tests/api/check-params/upload-quota.ts | 16 | ||||
-rw-r--r-- | server/tests/api/check-params/video-imports.ts | 6 | ||||
-rw-r--r-- | server/tests/api/moderation/video-blacklist.ts | 10 | ||||
-rw-r--r-- | server/tests/api/notifications/user-notifications.ts | 30 | ||||
-rw-r--r-- | server/tests/api/videos/video-imports.ts | 72 | ||||
-rw-r--r-- | server/tests/cli/peertube.ts | 7 | ||||
-rw-r--r-- | server/tests/plugins/filter-hooks.ts | 67 | ||||
-rw-r--r-- | shared/extra-utils/server/servers.ts | 13 | ||||
-rw-r--r-- | shared/extra-utils/videos/imports-command.ts | 86 | ||||
-rw-r--r-- | shared/extra-utils/videos/index.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/videos/video-imports.ts | 90 |
11 files changed, 192 insertions, 207 deletions
diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts index d0fbec415..c444663b8 100644 --- a/server/tests/api/check-params/upload-quota.ts +++ b/server/tests/api/check-params/upload-quota.ts | |||
@@ -3,13 +3,12 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
5 | import { HttpStatusCode, randomInt } from '@shared/core-utils' | 5 | import { HttpStatusCode, randomInt } from '@shared/core-utils' |
6 | import { getGoodVideoUrl, getMagnetURI, getMyVideoImports, importVideo } from '@shared/extra-utils/videos/video-imports' | 6 | import { MyUser, VideoImportState, VideoPrivacy } from '@shared/models' |
7 | import { MyUser, VideoImport, VideoImportState, VideoPrivacy } from '@shared/models' | ||
8 | import { | 7 | import { |
9 | cleanupTests, | 8 | cleanupTests, |
10 | flushAndRunServer, | 9 | flushAndRunServer, |
11 | getMyUserInformation, | 10 | getMyUserInformation, |
12 | immutableAssign, | 11 | ImportsCommand, |
13 | registerUser, | 12 | registerUser, |
14 | ServerInfo, | 13 | ServerInfo, |
15 | setAccessTokensToServers, | 14 | setAccessTokensToServers, |
@@ -83,16 +82,15 @@ describe('Test upload quota', function () { | |||
83 | channelId: server.videoChannel.id, | 82 | channelId: server.videoChannel.id, |
84 | privacy: VideoPrivacy.PUBLIC | 83 | privacy: VideoPrivacy.PUBLIC |
85 | } | 84 | } |
86 | await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getGoodVideoUrl() })) | 85 | await server.importsCommand.importVideo({ attributes: { ...baseAttributes, targetUrl: ImportsCommand.getGoodVideoUrl() } }) |
87 | await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() })) | 86 | await server.importsCommand.importVideo({ attributes: { ...baseAttributes, magnetUri: ImportsCommand.getMagnetURI() } }) |
88 | await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' as any })) | 87 | await server.importsCommand.importVideo({ attributes: { ...baseAttributes, torrentfile: 'video-720p.torrent' as any } }) |
89 | 88 | ||
90 | await waitJobs([ server ]) | 89 | await waitJobs([ server ]) |
91 | 90 | ||
92 | const res = await getMyVideoImports(server.url, server.accessToken) | 91 | const { total, data: videoImports } = await server.importsCommand.getMyVideoImports() |
92 | expect(total).to.equal(3) | ||
93 | 93 | ||
94 | expect(res.body.total).to.equal(3) | ||
95 | const videoImports: VideoImport[] = res.body.data | ||
96 | expect(videoImports).to.have.lengthOf(3) | 94 | expect(videoImports).to.have.lengthOf(3) |
97 | 95 | ||
98 | for (const videoImport of videoImports) { | 96 | for (const videoImport of videoImports) { |
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index dae3860ef..ea473191e 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts | |||
@@ -13,6 +13,7 @@ import { | |||
13 | flushAndRunServer, | 13 | flushAndRunServer, |
14 | getMyUserInformation, | 14 | getMyUserInformation, |
15 | immutableAssign, | 15 | immutableAssign, |
16 | ImportsCommand, | ||
16 | makeGetRequest, | 17 | makeGetRequest, |
17 | makePostBodyRequest, | 18 | makePostBodyRequest, |
18 | makeUploadRequest, | 19 | makeUploadRequest, |
@@ -20,7 +21,6 @@ import { | |||
20 | setAccessTokensToServers, | 21 | setAccessTokensToServers, |
21 | userLogin | 22 | userLogin |
22 | } from '@shared/extra-utils' | 23 | } from '@shared/extra-utils' |
23 | import { getGoodVideoUrl, getMagnetURI } from '@shared/extra-utils/videos/video-imports' | ||
24 | import { VideoPrivacy } from '@shared/models' | 24 | import { VideoPrivacy } from '@shared/models' |
25 | 25 | ||
26 | describe('Test video imports API validator', function () { | 26 | describe('Test video imports API validator', function () { |
@@ -74,7 +74,7 @@ describe('Test video imports API validator', function () { | |||
74 | 74 | ||
75 | before(function () { | 75 | before(function () { |
76 | baseCorrectParams = { | 76 | baseCorrectParams = { |
77 | targetUrl: getGoodVideoUrl(), | 77 | targetUrl: ImportsCommand.getGoodVideoUrl(), |
78 | name: 'my super name', | 78 | name: 'my super name', |
79 | category: 5, | 79 | category: 5, |
80 | licence: 1, | 80 | licence: 1, |
@@ -301,7 +301,7 @@ describe('Test video imports API validator', function () { | |||
301 | }) | 301 | }) |
302 | 302 | ||
303 | let fields = omit(baseCorrectParams, 'targetUrl') | 303 | let fields = omit(baseCorrectParams, 'targetUrl') |
304 | fields = immutableAssign(fields, { magnetUri: getMagnetURI() }) | 304 | fields = immutableAssign(fields, { magnetUri: ImportsCommand.getMagnetURI() }) |
305 | 305 | ||
306 | await makePostBodyRequest({ | 306 | await makePostBodyRequest({ |
307 | url: server.url, | 307 | url: server.url, |
diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index 17a68e4a6..c72ebc16b 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts | |||
@@ -12,6 +12,7 @@ import { | |||
12 | getMyUserInformation, | 12 | getMyUserInformation, |
13 | getMyVideos, | 13 | getMyVideos, |
14 | getVideosList, | 14 | getVideosList, |
15 | ImportsCommand, | ||
15 | killallServers, | 16 | killallServers, |
16 | reRunServer, | 17 | reRunServer, |
17 | ServerInfo, | 18 | ServerInfo, |
@@ -21,7 +22,6 @@ import { | |||
21 | userLogin, | 22 | userLogin, |
22 | waitJobs | 23 | waitJobs |
23 | } from '@shared/extra-utils' | 24 | } from '@shared/extra-utils' |
24 | import { getGoodVideoUrl, getMagnetURI, importVideo } from '@shared/extra-utils/videos/video-imports' | ||
25 | import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' | 25 | import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' |
26 | 26 | ||
27 | const expect = chai.expect | 27 | const expect = chai.expect |
@@ -402,11 +402,11 @@ describe('Test video blacklist', function () { | |||
402 | this.timeout(15000) | 402 | this.timeout(15000) |
403 | 403 | ||
404 | const attributes = { | 404 | const attributes = { |
405 | targetUrl: getGoodVideoUrl(), | 405 | targetUrl: ImportsCommand.getGoodVideoUrl(), |
406 | name: 'URL import', | 406 | name: 'URL import', |
407 | channelId: channelOfUserWithoutFlag | 407 | channelId: channelOfUserWithoutFlag |
408 | } | 408 | } |
409 | await importVideo(servers[0].url, userWithoutFlag, attributes) | 409 | await servers[0].importsCommand.importVideo({ token: userWithoutFlag, attributes }) |
410 | 410 | ||
411 | const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) | 411 | const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) |
412 | expect(body.total).to.equal(2) | 412 | expect(body.total).to.equal(2) |
@@ -415,11 +415,11 @@ describe('Test video blacklist', function () { | |||
415 | 415 | ||
416 | it('Should auto blacklist a video on torrent import', async function () { | 416 | it('Should auto blacklist a video on torrent import', async function () { |
417 | const attributes = { | 417 | const attributes = { |
418 | magnetUri: getMagnetURI(), | 418 | magnetUri: ImportsCommand.getMagnetURI(), |
419 | name: 'Torrent import', | 419 | name: 'Torrent import', |
420 | channelId: channelOfUserWithoutFlag | 420 | channelId: channelOfUserWithoutFlag |
421 | } | 421 | } |
422 | await importVideo(servers[0].url, userWithoutFlag, attributes) | 422 | await servers[0].importsCommand.importVideo({ token: userWithoutFlag, attributes }) |
423 | 423 | ||
424 | const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) | 424 | const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) |
425 | expect(body.total).to.equal(3) | 425 | expect(body.total).to.equal(3) |
diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index 15be983f2..a9315c818 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts | |||
@@ -11,6 +11,7 @@ import { | |||
11 | checkVideoIsPublished, | 11 | checkVideoIsPublished, |
12 | cleanupTests, | 12 | cleanupTests, |
13 | getLastNotification, | 13 | getLastNotification, |
14 | ImportsCommand, | ||
14 | MockSmtpServer, | 15 | MockSmtpServer, |
15 | prepareNotificationsTest, | 16 | prepareNotificationsTest, |
16 | ServerInfo, | 17 | ServerInfo, |
@@ -21,7 +22,6 @@ import { | |||
21 | wait, | 22 | wait, |
22 | waitJobs | 23 | waitJobs |
23 | } from '@shared/extra-utils' | 24 | } from '@shared/extra-utils' |
24 | import { getBadVideoUrl, getGoodVideoUrl, importVideo } from '@shared/extra-utils/videos/video-imports' | ||
25 | import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models' | 25 | import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models' |
26 | 26 | ||
27 | const expect = chai.expect | 27 | const expect = chai.expect |
@@ -209,14 +209,13 @@ describe('Test user notifications', function () { | |||
209 | name, | 209 | name, |
210 | channelId, | 210 | channelId, |
211 | privacy: VideoPrivacy.PUBLIC, | 211 | privacy: VideoPrivacy.PUBLIC, |
212 | targetUrl: getGoodVideoUrl() | 212 | targetUrl: ImportsCommand.getGoodVideoUrl() |
213 | } | 213 | } |
214 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | 214 | const { video } = await servers[0].importsCommand.importVideo({ attributes }) |
215 | const uuid = res.body.video.uuid | ||
216 | 215 | ||
217 | await waitJobs(servers) | 216 | await waitJobs(servers) |
218 | 217 | ||
219 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | 218 | await checkNewVideoFromSubscription(baseParams, name, video.uuid, 'presence') |
220 | }) | 219 | }) |
221 | }) | 220 | }) |
222 | 221 | ||
@@ -280,14 +279,13 @@ describe('Test user notifications', function () { | |||
280 | name, | 279 | name, |
281 | channelId, | 280 | channelId, |
282 | privacy: VideoPrivacy.PUBLIC, | 281 | privacy: VideoPrivacy.PUBLIC, |
283 | targetUrl: getGoodVideoUrl(), | 282 | targetUrl: ImportsCommand.getGoodVideoUrl(), |
284 | waitTranscoding: true | 283 | waitTranscoding: true |
285 | } | 284 | } |
286 | const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) | 285 | const { video } = await servers[1].importsCommand.importVideo({ attributes }) |
287 | const uuid = res.body.video.uuid | ||
288 | 286 | ||
289 | await waitJobs(servers) | 287 | await waitJobs(servers) |
290 | await checkVideoIsPublished(baseParams, name, uuid, 'presence') | 288 | await checkVideoIsPublished(baseParams, name, video.uuid, 'presence') |
291 | }) | 289 | }) |
292 | 290 | ||
293 | it('Should send a notification when the scheduled update has been proceeded', async function () { | 291 | it('Should send a notification when the scheduled update has been proceeded', async function () { |
@@ -349,13 +347,12 @@ describe('Test user notifications', function () { | |||
349 | name, | 347 | name, |
350 | channelId, | 348 | channelId, |
351 | privacy: VideoPrivacy.PRIVATE, | 349 | privacy: VideoPrivacy.PRIVATE, |
352 | targetUrl: getBadVideoUrl() | 350 | targetUrl: ImportsCommand.getBadVideoUrl() |
353 | } | 351 | } |
354 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | 352 | const { video } = await servers[0].importsCommand.importVideo({ attributes }) |
355 | const uuid = res.body.video.uuid | ||
356 | 353 | ||
357 | await waitJobs(servers) | 354 | await waitJobs(servers) |
358 | await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence') | 355 | await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getBadVideoUrl(), false, 'presence') |
359 | }) | 356 | }) |
360 | 357 | ||
361 | it('Should send a notification when the video import succeeded', async function () { | 358 | it('Should send a notification when the video import succeeded', async function () { |
@@ -367,13 +364,12 @@ describe('Test user notifications', function () { | |||
367 | name, | 364 | name, |
368 | channelId, | 365 | channelId, |
369 | privacy: VideoPrivacy.PRIVATE, | 366 | privacy: VideoPrivacy.PRIVATE, |
370 | targetUrl: getGoodVideoUrl() | 367 | targetUrl: ImportsCommand.getGoodVideoUrl() |
371 | } | 368 | } |
372 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | 369 | const { video } = await servers[0].importsCommand.importVideo({ attributes }) |
373 | const uuid = res.body.video.uuid | ||
374 | 370 | ||
375 | await waitJobs(servers) | 371 | await waitJobs(servers) |
376 | await checkMyVideoImportIsFinished(baseParams, name, uuid, getGoodVideoUrl(), true, 'presence') | 372 | await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getGoodVideoUrl(), true, 'presence') |
377 | }) | 373 | }) |
378 | }) | 374 | }) |
379 | 375 | ||
diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 14aed604f..4f9ecbe8e 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts | |||
@@ -3,6 +3,7 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { | 5 | import { |
6 | areHttpImportTestsDisabled, | ||
6 | cleanupTests, | 7 | cleanupTests, |
7 | doubleFollow, | 8 | doubleFollow, |
8 | flushAndRunMultipleServers, | 9 | flushAndRunMultipleServers, |
@@ -11,20 +12,14 @@ import { | |||
11 | getVideo, | 12 | getVideo, |
12 | getVideosList, | 13 | getVideosList, |
13 | immutableAssign, | 14 | immutableAssign, |
15 | ImportsCommand, | ||
14 | ServerInfo, | 16 | ServerInfo, |
15 | setAccessTokensToServers, | 17 | setAccessTokensToServers, |
16 | testCaptionFile | 18 | testCaptionFile, |
17 | } from '../../../../shared/extra-utils' | 19 | testImage, |
18 | import { areHttpImportTestsDisabled, testImage } from '../../../../shared/extra-utils/miscs/miscs' | 20 | waitJobs |
19 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 21 | } from '@shared/extra-utils' |
20 | import { | 22 | import { VideoDetails, VideoPrivacy, VideoResolution } from '@shared/models' |
21 | getMagnetURI, | ||
22 | getMyVideoImports, | ||
23 | getYoutubeHDRVideoUrl, | ||
24 | getYoutubeVideoUrl, | ||
25 | importVideo | ||
26 | } from '../../../../shared/extra-utils/videos/video-imports' | ||
27 | import { VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos' | ||
28 | 23 | ||
29 | const expect = chai.expect | 24 | const expect = chai.expect |
30 | 25 | ||
@@ -124,17 +119,17 @@ describe('Test video imports', function () { | |||
124 | } | 119 | } |
125 | 120 | ||
126 | { | 121 | { |
127 | const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }) | 122 | const attributes = immutableAssign(baseAttributes, { targetUrl: ImportsCommand.getYoutubeVideoUrl() }) |
128 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | 123 | const { video } = await servers[0].importsCommand.importVideo({ attributes }) |
129 | expect(res.body.video.name).to.equal('small video - youtube') | 124 | expect(video.name).to.equal('small video - youtube') |
130 | 125 | ||
131 | expect(res.body.video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`)) | 126 | expect(video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`)) |
132 | expect(res.body.video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`)) | 127 | expect(video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`)) |
133 | 128 | ||
134 | await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath) | 129 | await testImage(servers[0].url, 'video_import_thumbnail', video.thumbnailPath) |
135 | await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath) | 130 | await testImage(servers[0].url, 'video_import_preview', video.previewPath) |
136 | 131 | ||
137 | const bodyCaptions = await servers[0].captionsCommand.listVideoCaptions({ videoId: res.body.video.id }) | 132 | const bodyCaptions = await servers[0].captionsCommand.listVideoCaptions({ videoId: video.id }) |
138 | const videoCaptions = bodyCaptions.data | 133 | const videoCaptions = bodyCaptions.data |
139 | expect(videoCaptions).to.have.lengthOf(2) | 134 | expect(videoCaptions).to.have.lengthOf(2) |
140 | 135 | ||
@@ -175,12 +170,12 @@ Ajouter un sous-titre est vraiment facile`) | |||
175 | 170 | ||
176 | { | 171 | { |
177 | const attributes = immutableAssign(baseAttributes, { | 172 | const attributes = immutableAssign(baseAttributes, { |
178 | magnetUri: getMagnetURI(), | 173 | magnetUri: ImportsCommand.getMagnetURI(), |
179 | description: 'this is a super torrent description', | 174 | description: 'this is a super torrent description', |
180 | tags: [ 'tag_torrent1', 'tag_torrent2' ] | 175 | tags: [ 'tag_torrent1', 'tag_torrent2' ] |
181 | }) | 176 | }) |
182 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | 177 | const { video } = await servers[0].importsCommand.importVideo({ attributes }) |
183 | expect(res.body.video.name).to.equal('super peertube2 video') | 178 | expect(video.name).to.equal('super peertube2 video') |
184 | } | 179 | } |
185 | 180 | ||
186 | { | 181 | { |
@@ -189,8 +184,8 @@ Ajouter un sous-titre est vraiment facile`) | |||
189 | description: 'this is a super torrent description', | 184 | description: 'this is a super torrent description', |
190 | tags: [ 'tag_torrent1', 'tag_torrent2' ] | 185 | tags: [ 'tag_torrent1', 'tag_torrent2' ] |
191 | }) | 186 | }) |
192 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | 187 | const { video } = await servers[0].importsCommand.importVideo({ attributes }) |
193 | expect(res.body.video.name).to.equal('ä½ å¥½ 世界 720p.mp4') | 188 | expect(video.name).to.equal('ä½ å¥½ 世界 720p.mp4') |
194 | } | 189 | } |
195 | }) | 190 | }) |
196 | 191 | ||
@@ -207,19 +202,18 @@ Ajouter un sous-titre est vraiment facile`) | |||
207 | }) | 202 | }) |
208 | 203 | ||
209 | it('Should list the videos to import in my imports on server 1', async function () { | 204 | it('Should list the videos to import in my imports on server 1', async function () { |
210 | const res = await getMyVideoImports(servers[0].url, servers[0].accessToken, '-createdAt') | 205 | const { total, data: videoImports } = await servers[0].importsCommand.getMyVideoImports({ sort: '-createdAt' }) |
206 | expect(total).to.equal(3) | ||
211 | 207 | ||
212 | expect(res.body.total).to.equal(3) | ||
213 | const videoImports: VideoImport[] = res.body.data | ||
214 | expect(videoImports).to.have.lengthOf(3) | 208 | expect(videoImports).to.have.lengthOf(3) |
215 | 209 | ||
216 | expect(videoImports[2].targetUrl).to.equal(getYoutubeVideoUrl()) | 210 | expect(videoImports[2].targetUrl).to.equal(ImportsCommand.getYoutubeVideoUrl()) |
217 | expect(videoImports[2].magnetUri).to.be.null | 211 | expect(videoImports[2].magnetUri).to.be.null |
218 | expect(videoImports[2].torrentName).to.be.null | 212 | expect(videoImports[2].torrentName).to.be.null |
219 | expect(videoImports[2].video.name).to.equal('small video - youtube') | 213 | expect(videoImports[2].video.name).to.equal('small video - youtube') |
220 | 214 | ||
221 | expect(videoImports[1].targetUrl).to.be.null | 215 | expect(videoImports[1].targetUrl).to.be.null |
222 | expect(videoImports[1].magnetUri).to.equal(getMagnetURI()) | 216 | expect(videoImports[1].magnetUri).to.equal(ImportsCommand.getMagnetURI()) |
223 | expect(videoImports[1].torrentName).to.be.null | 217 | expect(videoImports[1].torrentName).to.be.null |
224 | expect(videoImports[1].video.name).to.equal('super peertube2 video') | 218 | expect(videoImports[1].video.name).to.equal('super peertube2 video') |
225 | 219 | ||
@@ -248,7 +242,7 @@ Ajouter un sous-titre est vraiment facile`) | |||
248 | this.timeout(60_000) | 242 | this.timeout(60_000) |
249 | 243 | ||
250 | const attributes = { | 244 | const attributes = { |
251 | targetUrl: getYoutubeVideoUrl(), | 245 | targetUrl: ImportsCommand.getYoutubeVideoUrl(), |
252 | channelId: channelIdServer2, | 246 | channelId: channelIdServer2, |
253 | privacy: VideoPrivacy.PUBLIC, | 247 | privacy: VideoPrivacy.PUBLIC, |
254 | category: 10, | 248 | category: 10, |
@@ -258,8 +252,8 @@ Ajouter un sous-titre est vraiment facile`) | |||
258 | description: 'my super description', | 252 | description: 'my super description', |
259 | tags: [ 'supertag1', 'supertag2' ] | 253 | tags: [ 'supertag1', 'supertag2' ] |
260 | } | 254 | } |
261 | const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) | 255 | const { video } = await servers[1].importsCommand.importVideo({ attributes }) |
262 | expect(res.body.video.name).to.equal('my super name') | 256 | expect(video.name).to.equal('my super name') |
263 | }) | 257 | }) |
264 | 258 | ||
265 | it('Should have the videos listed on the two instances', async function () { | 259 | it('Should have the videos listed on the two instances', async function () { |
@@ -284,12 +278,12 @@ Ajouter un sous-titre est vraiment facile`) | |||
284 | 278 | ||
285 | const attributes = { | 279 | const attributes = { |
286 | name: 'transcoded video', | 280 | name: 'transcoded video', |
287 | magnetUri: getMagnetURI(), | 281 | magnetUri: ImportsCommand.getMagnetURI(), |
288 | channelId: channelIdServer2, | 282 | channelId: channelIdServer2, |
289 | privacy: VideoPrivacy.PUBLIC | 283 | privacy: VideoPrivacy.PUBLIC |
290 | } | 284 | } |
291 | const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) | 285 | const { video } = await servers[1].importsCommand.importVideo({ attributes }) |
292 | const videoUUID = res.body.video.uuid | 286 | const videoUUID = video.uuid |
293 | 287 | ||
294 | await waitJobs(servers) | 288 | await waitJobs(servers) |
295 | 289 | ||
@@ -335,12 +329,12 @@ Ajouter un sous-titre est vraiment facile`) | |||
335 | 329 | ||
336 | const attributes = { | 330 | const attributes = { |
337 | name: 'hdr video', | 331 | name: 'hdr video', |
338 | targetUrl: getYoutubeHDRVideoUrl(), | 332 | targetUrl: ImportsCommand.getYoutubeHDRVideoUrl(), |
339 | channelId: channelIdServer1, | 333 | channelId: channelIdServer1, |
340 | privacy: VideoPrivacy.PUBLIC | 334 | privacy: VideoPrivacy.PUBLIC |
341 | } | 335 | } |
342 | const res1 = await importVideo(servers[0].url, servers[0].accessToken, attributes) | 336 | const { video: videoImported } = await servers[0].importsCommand.importVideo({ attributes }) |
343 | const videoUUID = res1.body.video.uuid | 337 | const videoUUID = videoImported.uuid |
344 | 338 | ||
345 | await waitJobs(servers) | 339 | await waitJobs(servers) |
346 | 340 | ||
diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts index 0a4f54ffa..64a93ebb5 100644 --- a/server/tests/cli/peertube.ts +++ b/server/tests/cli/peertube.ts | |||
@@ -15,6 +15,7 @@ import { | |||
15 | getLocalIdByUUID, | 15 | getLocalIdByUUID, |
16 | getVideo, | 16 | getVideo, |
17 | getVideosList, | 17 | getVideosList, |
18 | ImportsCommand, | ||
18 | removeVideo, | 19 | removeVideo, |
19 | ServerInfo, | 20 | ServerInfo, |
20 | setAccessTokensToServers, | 21 | setAccessTokensToServers, |
@@ -23,7 +24,6 @@ import { | |||
23 | userLogin, | 24 | userLogin, |
24 | waitJobs | 25 | waitJobs |
25 | } from '../../../shared/extra-utils' | 26 | } from '../../../shared/extra-utils' |
26 | import { getYoutubeVideoUrl } from '../../../shared/extra-utils/videos/video-imports' | ||
27 | 27 | ||
28 | describe('Test CLI wrapper', function () { | 28 | describe('Test CLI wrapper', function () { |
29 | let server: ServerInfo | 29 | let server: ServerInfo |
@@ -122,7 +122,7 @@ describe('Test CLI wrapper', function () { | |||
122 | 122 | ||
123 | this.timeout(60000) | 123 | this.timeout(60000) |
124 | 124 | ||
125 | const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel` | 125 | const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} --channel-name user_channel` |
126 | await cliCommand.execWithEnv(`${cmd} import ${params}`) | 126 | await cliCommand.execWithEnv(`${cmd} import ${params}`) |
127 | }) | 127 | }) |
128 | 128 | ||
@@ -155,7 +155,8 @@ describe('Test CLI wrapper', function () { | |||
155 | 155 | ||
156 | this.timeout(60000) | 156 | this.timeout(60000) |
157 | 157 | ||
158 | const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support` | 158 | const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} ` + |
159 | `--channel-name user_channel --video-name toto --nsfw --support support` | ||
159 | await cliCommand.execWithEnv(`${cmd} import ${params}`) | 160 | await cliCommand.execWithEnv(`${cmd} import ${params}`) |
160 | 161 | ||
161 | await waitJobs([ server ]) | 162 | await waitJobs([ server ]) |
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index 203642d8d..a3c3c0551 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts | |||
@@ -18,6 +18,7 @@ import { | |||
18 | getVideosListPagination, | 18 | getVideosListPagination, |
19 | getVideoThreadComments, | 19 | getVideoThreadComments, |
20 | getVideoWithToken, | 20 | getVideoWithToken, |
21 | ImportsCommand, | ||
21 | makeRawRequest, | 22 | makeRawRequest, |
22 | PluginsCommand, | 23 | PluginsCommand, |
23 | registerUser, | 24 | registerUser, |
@@ -30,16 +31,7 @@ import { | |||
30 | waitJobs, | 31 | waitJobs, |
31 | waitUntilLog | 32 | waitUntilLog |
32 | } from '@shared/extra-utils' | 33 | } from '@shared/extra-utils' |
33 | import { getGoodVideoUrl, getMyVideoImports, importVideo } from '@shared/extra-utils/videos/video-imports' | 34 | import { VideoCommentThreadTree, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' |
34 | import { | ||
35 | VideoCommentThreadTree, | ||
36 | VideoDetails, | ||
37 | VideoImport, | ||
38 | VideoImportState, | ||
39 | VideoPlaylist, | ||
40 | VideoPlaylistPrivacy, | ||
41 | VideoPrivacy | ||
42 | } from '@shared/models' | ||
43 | 35 | ||
44 | const expect = chai.expect | 36 | const expect = chai.expect |
45 | 37 | ||
@@ -157,23 +149,23 @@ describe('Test plugin filter hooks', function () { | |||
157 | }) | 149 | }) |
158 | 150 | ||
159 | it('Should run filter:api.video.pre-import-url.accept.result', async function () { | 151 | it('Should run filter:api.video.pre-import-url.accept.result', async function () { |
160 | const baseAttributes = { | 152 | const attributes = { |
161 | name: 'normal title', | 153 | name: 'normal title', |
162 | privacy: VideoPrivacy.PUBLIC, | 154 | privacy: VideoPrivacy.PUBLIC, |
163 | channelId: servers[0].videoChannel.id, | 155 | channelId: servers[0].videoChannel.id, |
164 | targetUrl: getGoodVideoUrl() + 'bad' | 156 | targetUrl: ImportsCommand.getGoodVideoUrl() + 'bad' |
165 | } | 157 | } |
166 | await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403) | 158 | await servers[0].importsCommand.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
167 | }) | 159 | }) |
168 | 160 | ||
169 | it('Should run filter:api.video.pre-import-torrent.accept.result', async function () { | 161 | it('Should run filter:api.video.pre-import-torrent.accept.result', async function () { |
170 | const baseAttributes = { | 162 | const attributes = { |
171 | name: 'bad torrent', | 163 | name: 'bad torrent', |
172 | privacy: VideoPrivacy.PUBLIC, | 164 | privacy: VideoPrivacy.PUBLIC, |
173 | channelId: servers[0].videoChannel.id, | 165 | channelId: servers[0].videoChannel.id, |
174 | torrentfile: 'video-720p.torrent' as any | 166 | torrentfile: 'video-720p.torrent' as any |
175 | } | 167 | } |
176 | await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403) | 168 | await servers[0].importsCommand.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
177 | }) | 169 | }) |
178 | 170 | ||
179 | it('Should run filter:api.video.post-import-url.accept.result', async function () { | 171 | it('Should run filter:api.video.post-import-url.accept.result', async function () { |
@@ -182,21 +174,21 @@ describe('Test plugin filter hooks', function () { | |||
182 | let videoImportId: number | 174 | let videoImportId: number |
183 | 175 | ||
184 | { | 176 | { |
185 | const baseAttributes = { | 177 | const attributes = { |
186 | name: 'title with bad word', | 178 | name: 'title with bad word', |
187 | privacy: VideoPrivacy.PUBLIC, | 179 | privacy: VideoPrivacy.PUBLIC, |
188 | channelId: servers[0].videoChannel.id, | 180 | channelId: servers[0].videoChannel.id, |
189 | targetUrl: getGoodVideoUrl() | 181 | targetUrl: ImportsCommand.getGoodVideoUrl() |
190 | } | 182 | } |
191 | const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) | 183 | const body = await servers[0].importsCommand.importVideo({ attributes }) |
192 | videoImportId = res.body.id | 184 | videoImportId = body.id |
193 | } | 185 | } |
194 | 186 | ||
195 | await waitJobs(servers) | 187 | await waitJobs(servers) |
196 | 188 | ||
197 | { | 189 | { |
198 | const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) | 190 | const body = await servers[0].importsCommand.getMyVideoImports() |
199 | const videoImports = res.body.data as VideoImport[] | 191 | const videoImports = body.data |
200 | 192 | ||
201 | const videoImport = videoImports.find(i => i.id === videoImportId) | 193 | const videoImport = videoImports.find(i => i.id === videoImportId) |
202 | 194 | ||
@@ -211,21 +203,20 @@ describe('Test plugin filter hooks', function () { | |||
211 | let videoImportId: number | 203 | let videoImportId: number |
212 | 204 | ||
213 | { | 205 | { |
214 | const baseAttributes = { | 206 | const attributes = { |
215 | name: 'title with bad word', | 207 | name: 'title with bad word', |
216 | privacy: VideoPrivacy.PUBLIC, | 208 | privacy: VideoPrivacy.PUBLIC, |
217 | channelId: servers[0].videoChannel.id, | 209 | channelId: servers[0].videoChannel.id, |
218 | torrentfile: 'video-720p.torrent' as any | 210 | torrentfile: 'video-720p.torrent' as any |
219 | } | 211 | } |
220 | const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) | 212 | const body = await servers[0].importsCommand.importVideo({ attributes }) |
221 | videoImportId = res.body.id | 213 | videoImportId = body.id |
222 | } | 214 | } |
223 | 215 | ||
224 | await waitJobs(servers) | 216 | await waitJobs(servers) |
225 | 217 | ||
226 | { | 218 | { |
227 | const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) | 219 | const { data: videoImports } = await servers[0].importsCommand.getMyVideoImports() |
228 | const videoImports = res.body.data as VideoImport[] | ||
229 | 220 | ||
230 | const videoImport = videoImports.find(i => i.id === videoImportId) | 221 | const videoImport = videoImports.find(i => i.id === videoImportId) |
231 | 222 | ||
@@ -278,17 +269,15 @@ describe('Test plugin filter hooks', function () { | |||
278 | 269 | ||
279 | describe('Should run filter:video.auto-blacklist.result', function () { | 270 | describe('Should run filter:video.auto-blacklist.result', function () { |
280 | 271 | ||
281 | async function checkIsBlacklisted (oldRes: any, value: boolean) { | 272 | async function checkIsBlacklisted (id: number | string, value: boolean) { |
282 | const videoId = oldRes.body.video.uuid | 273 | const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, id) |
283 | |||
284 | const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoId) | ||
285 | const video: VideoDetails = res.body | 274 | const video: VideoDetails = res.body |
286 | expect(video.blacklisted).to.equal(value) | 275 | expect(video.blacklisted).to.equal(value) |
287 | } | 276 | } |
288 | 277 | ||
289 | it('Should blacklist on upload', async function () { | 278 | it('Should blacklist on upload', async function () { |
290 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' }) | 279 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' }) |
291 | await checkIsBlacklisted(res, true) | 280 | await checkIsBlacklisted(res.body.video.uuid, true) |
292 | }) | 281 | }) |
293 | 282 | ||
294 | it('Should blacklist on import', async function () { | 283 | it('Should blacklist on import', async function () { |
@@ -296,20 +285,20 @@ describe('Test plugin filter hooks', function () { | |||
296 | 285 | ||
297 | const attributes = { | 286 | const attributes = { |
298 | name: 'video please blacklist me', | 287 | name: 'video please blacklist me', |
299 | targetUrl: getGoodVideoUrl(), | 288 | targetUrl: ImportsCommand.getGoodVideoUrl(), |
300 | channelId: servers[0].videoChannel.id | 289 | channelId: servers[0].videoChannel.id |
301 | } | 290 | } |
302 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | 291 | const body = await servers[0].importsCommand.importVideo({ attributes }) |
303 | await checkIsBlacklisted(res, true) | 292 | await checkIsBlacklisted(body.video.uuid, true) |
304 | }) | 293 | }) |
305 | 294 | ||
306 | it('Should blacklist on update', async function () { | 295 | it('Should blacklist on update', async function () { |
307 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) | 296 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) |
308 | const videoId = res.body.video.uuid | 297 | const videoId = res.body.video.uuid |
309 | await checkIsBlacklisted(res, false) | 298 | await checkIsBlacklisted(videoId, false) |
310 | 299 | ||
311 | await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' }) | 300 | await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' }) |
312 | await checkIsBlacklisted(res, true) | 301 | await checkIsBlacklisted(videoId, true) |
313 | }) | 302 | }) |
314 | 303 | ||
315 | it('Should blacklist on remote upload', async function () { | 304 | it('Should blacklist on remote upload', async function () { |
@@ -318,7 +307,7 @@ describe('Test plugin filter hooks', function () { | |||
318 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' }) | 307 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' }) |
319 | await waitJobs(servers) | 308 | await waitJobs(servers) |
320 | 309 | ||
321 | await checkIsBlacklisted(res, true) | 310 | await checkIsBlacklisted(res.body.video.uuid, true) |
322 | }) | 311 | }) |
323 | 312 | ||
324 | it('Should blacklist on remote update', async function () { | 313 | it('Should blacklist on remote update', async function () { |
@@ -328,12 +317,12 @@ describe('Test plugin filter hooks', function () { | |||
328 | await waitJobs(servers) | 317 | await waitJobs(servers) |
329 | 318 | ||
330 | const videoId = res.body.video.uuid | 319 | const videoId = res.body.video.uuid |
331 | await checkIsBlacklisted(res, false) | 320 | await checkIsBlacklisted(videoId, false) |
332 | 321 | ||
333 | await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' }) | 322 | await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' }) |
334 | await waitJobs(servers) | 323 | await waitJobs(servers) |
335 | 324 | ||
336 | await checkIsBlacklisted(res, true) | 325 | await checkIsBlacklisted(videoId, true) |
337 | }) | 326 | }) |
338 | }) | 327 | }) |
339 | 328 | ||
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index bd5c29e51..95c876110 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts | |||
@@ -18,7 +18,16 @@ import { makeGetRequest } from '../requests/requests' | |||
18 | import { SearchCommand } from '../search' | 18 | import { SearchCommand } from '../search' |
19 | import { SocketIOCommand } from '../socket' | 19 | import { SocketIOCommand } from '../socket' |
20 | import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' | 20 | import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' |
21 | import { BlacklistCommand, CaptionsCommand, ChangeOwnershipCommand, HistoryCommand, LiveCommand, PlaylistsCommand, ServicesCommand } from '../videos' | 21 | import { |
22 | BlacklistCommand, | ||
23 | CaptionsCommand, | ||
24 | ChangeOwnershipCommand, | ||
25 | HistoryCommand, | ||
26 | ImportsCommand, | ||
27 | LiveCommand, | ||
28 | PlaylistsCommand, | ||
29 | ServicesCommand | ||
30 | } from '../videos' | ||
22 | import { ConfigCommand } from './config-command' | 31 | import { ConfigCommand } from './config-command' |
23 | import { ContactFormCommand } from './contact-form-command' | 32 | import { ContactFormCommand } from './contact-form-command' |
24 | import { DebugCommand } from './debug-command' | 33 | import { DebugCommand } from './debug-command' |
@@ -107,6 +116,7 @@ interface ServerInfo { | |||
107 | changeOwnershipCommand?: ChangeOwnershipCommand | 116 | changeOwnershipCommand?: ChangeOwnershipCommand |
108 | playlistsCommand?: PlaylistsCommand | 117 | playlistsCommand?: PlaylistsCommand |
109 | historyCommand?: HistoryCommand | 118 | historyCommand?: HistoryCommand |
119 | importsCommand?: ImportsCommand | ||
110 | } | 120 | } |
111 | 121 | ||
112 | function parallelTests () { | 122 | function parallelTests () { |
@@ -339,6 +349,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] | |||
339 | server.changeOwnershipCommand = new ChangeOwnershipCommand(server) | 349 | server.changeOwnershipCommand = new ChangeOwnershipCommand(server) |
340 | server.playlistsCommand = new PlaylistsCommand(server) | 350 | server.playlistsCommand = new PlaylistsCommand(server) |
341 | server.historyCommand = new HistoryCommand(server) | 351 | server.historyCommand = new HistoryCommand(server) |
352 | server.importsCommand = new ImportsCommand(server) | ||
342 | 353 | ||
343 | res(server) | 354 | res(server) |
344 | }) | 355 | }) |
diff --git a/shared/extra-utils/videos/imports-command.ts b/shared/extra-utils/videos/imports-command.ts new file mode 100644 index 000000000..024aa363f --- /dev/null +++ b/shared/extra-utils/videos/imports-command.ts | |||
@@ -0,0 +1,86 @@ | |||
1 | |||
2 | import { ResultList } from '@shared/models' | ||
3 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
4 | import { VideoImport, VideoImportCreate } from '../../models/videos' | ||
5 | import { unwrapBody } from '../requests' | ||
6 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
7 | |||
8 | export class ImportsCommand extends AbstractCommand { | ||
9 | |||
10 | static getYoutubeVideoUrl () { | ||
11 | return 'https://www.youtube.com/watch?v=msX3jv1XdvM' | ||
12 | } | ||
13 | |||
14 | static getYoutubeHDRVideoUrl () { | ||
15 | /** | ||
16 | * The video is used to check format-selection correctness wrt. HDR, | ||
17 | * which brings its own set of oddities outside of a MediaSource. | ||
18 | * FIXME: refactor once HDR is supported at playback | ||
19 | * | ||
20 | * The video needs to have the following format_ids: | ||
21 | * (which you can check by using `youtube-dl <url> -F`): | ||
22 | * - 303 (1080p webm vp9) | ||
23 | * - 299 (1080p mp4 avc1) | ||
24 | * - 335 (1080p webm vp9.2 HDR) | ||
25 | * | ||
26 | * 15 jan. 2021: TEST VIDEO NOT CURRENTLY PROVIDING | ||
27 | * - 400 (1080p mp4 av01) | ||
28 | * - 315 (2160p webm vp9 HDR) | ||
29 | * - 337 (2160p webm vp9.2 HDR) | ||
30 | * - 401 (2160p mp4 av01 HDR) | ||
31 | */ | ||
32 | return 'https://www.youtube.com/watch?v=qR5vOXbZsI4' | ||
33 | } | ||
34 | |||
35 | static getMagnetURI () { | ||
36 | // eslint-disable-next-line max-len | ||
37 | return 'magnet:?xs=https%3A%2F%2Fpeertube2.cpy.re%2Fstatic%2Ftorrents%2Fb209ca00-c8bb-4b2b-b421-1ede169f3dbc-720.torrent&xt=urn:btih:0f498834733e8057ed5c6f2ee2b4efd8d84a76ee&dn=super+peertube2+video&tr=wss%3A%2F%2Fpeertube2.cpy.re%3A443%2Ftracker%2Fsocket&tr=https%3A%2F%2Fpeertube2.cpy.re%2Ftracker%2Fannounce&ws=https%3A%2F%2Fpeertube2.cpy.re%2Fstatic%2Fwebseed%2Fb209ca00-c8bb-4b2b-b421-1ede169f3dbc-720.mp4' | ||
38 | } | ||
39 | |||
40 | static getBadVideoUrl () { | ||
41 | return 'https://download.cpy.re/peertube/bad_video.mp4' | ||
42 | } | ||
43 | |||
44 | static getGoodVideoUrl () { | ||
45 | return 'https://download.cpy.re/peertube/good_video.mp4' | ||
46 | } | ||
47 | |||
48 | importVideo (options: OverrideCommandOptions & { | ||
49 | attributes: VideoImportCreate & { torrentfile?: string } | ||
50 | }) { | ||
51 | const { attributes } = options | ||
52 | const path = '/api/v1/videos/imports' | ||
53 | |||
54 | let attaches: any = {} | ||
55 | if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile } | ||
56 | |||
57 | return unwrapBody<VideoImport>(this.postUploadRequest({ | ||
58 | ...options, | ||
59 | |||
60 | path, | ||
61 | attaches, | ||
62 | fields: options.attributes, | ||
63 | implicitToken: true, | ||
64 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
65 | })) | ||
66 | } | ||
67 | |||
68 | getMyVideoImports (options: OverrideCommandOptions & { | ||
69 | sort?: string | ||
70 | } = {}) { | ||
71 | const { sort } = options | ||
72 | const path = '/api/v1/users/me/videos/imports' | ||
73 | |||
74 | const query = {} | ||
75 | if (sort) query['sort'] = sort | ||
76 | |||
77 | return this.getRequestBody<ResultList<VideoImport>>({ | ||
78 | ...options, | ||
79 | |||
80 | path, | ||
81 | query: { sort }, | ||
82 | implicitToken: true, | ||
83 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
84 | }) | ||
85 | } | ||
86 | } | ||
diff --git a/shared/extra-utils/videos/index.ts b/shared/extra-utils/videos/index.ts index 74667fc06..372cf7a90 100644 --- a/shared/extra-utils/videos/index.ts +++ b/shared/extra-utils/videos/index.ts | |||
@@ -3,6 +3,7 @@ export * from './captions' | |||
3 | export * from './captions-command' | 3 | export * from './captions-command' |
4 | export * from './change-ownership-command' | 4 | export * from './change-ownership-command' |
5 | export * from './history-command' | 5 | export * from './history-command' |
6 | export * from './imports-command' | ||
6 | export * from './live-command' | 7 | export * from './live-command' |
7 | export * from './live' | 8 | export * from './live' |
8 | export * from './playlists-command' | 9 | export * from './playlists-command' |
@@ -10,6 +11,5 @@ export * from './playlists' | |||
10 | export * from './services-command' | 11 | export * from './services-command' |
11 | export * from './video-channels' | 12 | export * from './video-channels' |
12 | export * from './video-comments' | 13 | export * from './video-comments' |
13 | export * from './video-imports' | ||
14 | export * from './video-streaming-playlists' | 14 | export * from './video-streaming-playlists' |
15 | export * from './videos' | 15 | export * from './videos' |
diff --git a/shared/extra-utils/videos/video-imports.ts b/shared/extra-utils/videos/video-imports.ts deleted file mode 100644 index 81c0163cb..000000000 --- a/shared/extra-utils/videos/video-imports.ts +++ /dev/null | |||
@@ -1,90 +0,0 @@ | |||
1 | |||
2 | import { VideoImportCreate } from '../../models/videos' | ||
3 | import { makeGetRequest, makeUploadRequest } from '../requests/requests' | ||
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
5 | |||
6 | function getYoutubeVideoUrl () { | ||
7 | return 'https://www.youtube.com/watch?v=msX3jv1XdvM' | ||
8 | } | ||
9 | |||
10 | function getYoutubeHDRVideoUrl () { | ||
11 | /** | ||
12 | * The video is used to check format-selection correctness wrt. HDR, | ||
13 | * which brings its own set of oddities outside of a MediaSource. | ||
14 | * FIXME: refactor once HDR is supported at playback | ||
15 | * | ||
16 | * The video needs to have the following format_ids: | ||
17 | * (which you can check by using `youtube-dl <url> -F`): | ||
18 | * - 303 (1080p webm vp9) | ||
19 | * - 299 (1080p mp4 avc1) | ||
20 | * - 335 (1080p webm vp9.2 HDR) | ||
21 | * | ||
22 | * 15 jan. 2021: TEST VIDEO NOT CURRENTLY PROVIDING | ||
23 | * - 400 (1080p mp4 av01) | ||
24 | * - 315 (2160p webm vp9 HDR) | ||
25 | * - 337 (2160p webm vp9.2 HDR) | ||
26 | * - 401 (2160p mp4 av01 HDR) | ||
27 | */ | ||
28 | return 'https://www.youtube.com/watch?v=qR5vOXbZsI4' | ||
29 | } | ||
30 | |||
31 | function getMagnetURI () { | ||
32 | // eslint-disable-next-line max-len | ||
33 | return 'magnet:?xs=https%3A%2F%2Fpeertube2.cpy.re%2Fstatic%2Ftorrents%2Fb209ca00-c8bb-4b2b-b421-1ede169f3dbc-720.torrent&xt=urn:btih:0f498834733e8057ed5c6f2ee2b4efd8d84a76ee&dn=super+peertube2+video&tr=wss%3A%2F%2Fpeertube2.cpy.re%3A443%2Ftracker%2Fsocket&tr=https%3A%2F%2Fpeertube2.cpy.re%2Ftracker%2Fannounce&ws=https%3A%2F%2Fpeertube2.cpy.re%2Fstatic%2Fwebseed%2Fb209ca00-c8bb-4b2b-b421-1ede169f3dbc-720.mp4' | ||
34 | } | ||
35 | |||
36 | function getBadVideoUrl () { | ||
37 | return 'https://download.cpy.re/peertube/bad_video.mp4' | ||
38 | } | ||
39 | |||
40 | function getGoodVideoUrl () { | ||
41 | return 'https://download.cpy.re/peertube/good_video.mp4' | ||
42 | } | ||
43 | |||
44 | function importVideo ( | ||
45 | url: string, | ||
46 | token: string, | ||
47 | attributes: VideoImportCreate & { torrentfile?: string }, | ||
48 | statusCodeExpected = HttpStatusCode.OK_200 | ||
49 | ) { | ||
50 | const path = '/api/v1/videos/imports' | ||
51 | |||
52 | let attaches: any = {} | ||
53 | if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile } | ||
54 | |||
55 | return makeUploadRequest({ | ||
56 | url, | ||
57 | path, | ||
58 | token, | ||
59 | attaches, | ||
60 | fields: attributes, | ||
61 | statusCodeExpected | ||
62 | }) | ||
63 | } | ||
64 | |||
65 | function getMyVideoImports (url: string, token: string, sort?: string) { | ||
66 | const path = '/api/v1/users/me/videos/imports' | ||
67 | |||
68 | const query = {} | ||
69 | if (sort) query['sort'] = sort | ||
70 | |||
71 | return makeGetRequest({ | ||
72 | url, | ||
73 | query, | ||
74 | path, | ||
75 | token, | ||
76 | statusCodeExpected: HttpStatusCode.OK_200 | ||
77 | }) | ||
78 | } | ||
79 | |||
80 | // --------------------------------------------------------------------------- | ||
81 | |||
82 | export { | ||
83 | getBadVideoUrl, | ||
84 | getYoutubeVideoUrl, | ||
85 | getYoutubeHDRVideoUrl, | ||
86 | importVideo, | ||
87 | getMagnetURI, | ||
88 | getMyVideoImports, | ||
89 | getGoodVideoUrl | ||
90 | } | ||