Introduce import command

This commit is contained in:
Chocobozzz 2021-07-08 16:49:51 +02:00
parent 313228e9c3
commit 6910f20f11
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
11 changed files with 192 additions and 207 deletions

View File

@ -3,13 +3,12 @@
import 'mocha'
import { expect } from 'chai'
import { HttpStatusCode, randomInt } from '@shared/core-utils'
import { getGoodVideoUrl, getMagnetURI, getMyVideoImports, importVideo } from '@shared/extra-utils/videos/video-imports'
import { MyUser, VideoImport, VideoImportState, VideoPrivacy } from '@shared/models'
import { MyUser, VideoImportState, VideoPrivacy } from '@shared/models'
import {
cleanupTests,
flushAndRunServer,
getMyUserInformation,
immutableAssign,
ImportsCommand,
registerUser,
ServerInfo,
setAccessTokensToServers,
@ -83,16 +82,15 @@ describe('Test upload quota', function () {
channelId: server.videoChannel.id,
privacy: VideoPrivacy.PUBLIC
}
await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getGoodVideoUrl() }))
await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() }))
await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' as any }))
await server.importsCommand.importVideo({ attributes: { ...baseAttributes, targetUrl: ImportsCommand.getGoodVideoUrl() } })
await server.importsCommand.importVideo({ attributes: { ...baseAttributes, magnetUri: ImportsCommand.getMagnetURI() } })
await server.importsCommand.importVideo({ attributes: { ...baseAttributes, torrentfile: 'video-720p.torrent' as any } })
await waitJobs([ server ])
const res = await getMyVideoImports(server.url, server.accessToken)
const { total, data: videoImports } = await server.importsCommand.getMyVideoImports()
expect(total).to.equal(3)
expect(res.body.total).to.equal(3)
const videoImports: VideoImport[] = res.body.data
expect(videoImports).to.have.lengthOf(3)
for (const videoImport of videoImports) {

View File

@ -13,6 +13,7 @@ import {
flushAndRunServer,
getMyUserInformation,
immutableAssign,
ImportsCommand,
makeGetRequest,
makePostBodyRequest,
makeUploadRequest,
@ -20,7 +21,6 @@ import {
setAccessTokensToServers,
userLogin
} from '@shared/extra-utils'
import { getGoodVideoUrl, getMagnetURI } from '@shared/extra-utils/videos/video-imports'
import { VideoPrivacy } from '@shared/models'
describe('Test video imports API validator', function () {
@ -74,7 +74,7 @@ describe('Test video imports API validator', function () {
before(function () {
baseCorrectParams = {
targetUrl: getGoodVideoUrl(),
targetUrl: ImportsCommand.getGoodVideoUrl(),
name: 'my super name',
category: 5,
licence: 1,
@ -301,7 +301,7 @@ describe('Test video imports API validator', function () {
})
let fields = omit(baseCorrectParams, 'targetUrl')
fields = immutableAssign(fields, { magnetUri: getMagnetURI() })
fields = immutableAssign(fields, { magnetUri: ImportsCommand.getMagnetURI() })
await makePostBodyRequest({
url: server.url,

View File

@ -12,6 +12,7 @@ import {
getMyUserInformation,
getMyVideos,
getVideosList,
ImportsCommand,
killallServers,
reRunServer,
ServerInfo,
@ -21,7 +22,6 @@ import {
userLogin,
waitJobs
} from '@shared/extra-utils'
import { getGoodVideoUrl, getMagnetURI, importVideo } from '@shared/extra-utils/videos/video-imports'
import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models'
const expect = chai.expect
@ -402,11 +402,11 @@ describe('Test video blacklist', function () {
this.timeout(15000)
const attributes = {
targetUrl: getGoodVideoUrl(),
targetUrl: ImportsCommand.getGoodVideoUrl(),
name: 'URL import',
channelId: channelOfUserWithoutFlag
}
await importVideo(servers[0].url, userWithoutFlag, attributes)
await servers[0].importsCommand.importVideo({ token: userWithoutFlag, attributes })
const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
expect(body.total).to.equal(2)
@ -415,11 +415,11 @@ describe('Test video blacklist', function () {
it('Should auto blacklist a video on torrent import', async function () {
const attributes = {
magnetUri: getMagnetURI(),
magnetUri: ImportsCommand.getMagnetURI(),
name: 'Torrent import',
channelId: channelOfUserWithoutFlag
}
await importVideo(servers[0].url, userWithoutFlag, attributes)
await servers[0].importsCommand.importVideo({ token: userWithoutFlag, attributes })
const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
expect(body.total).to.equal(3)

View File

@ -11,6 +11,7 @@ import {
checkVideoIsPublished,
cleanupTests,
getLastNotification,
ImportsCommand,
MockSmtpServer,
prepareNotificationsTest,
ServerInfo,
@ -21,7 +22,6 @@ import {
wait,
waitJobs
} from '@shared/extra-utils'
import { getBadVideoUrl, getGoodVideoUrl, importVideo } from '@shared/extra-utils/videos/video-imports'
import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models'
const expect = chai.expect
@ -209,14 +209,13 @@ describe('Test user notifications', function () {
name,
channelId,
privacy: VideoPrivacy.PUBLIC,
targetUrl: getGoodVideoUrl()
targetUrl: ImportsCommand.getGoodVideoUrl()
}
const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
const uuid = res.body.video.uuid
const { video } = await servers[0].importsCommand.importVideo({ attributes })
await waitJobs(servers)
await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
await checkNewVideoFromSubscription(baseParams, name, video.uuid, 'presence')
})
})
@ -280,14 +279,13 @@ describe('Test user notifications', function () {
name,
channelId,
privacy: VideoPrivacy.PUBLIC,
targetUrl: getGoodVideoUrl(),
targetUrl: ImportsCommand.getGoodVideoUrl(),
waitTranscoding: true
}
const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
const uuid = res.body.video.uuid
const { video } = await servers[1].importsCommand.importVideo({ attributes })
await waitJobs(servers)
await checkVideoIsPublished(baseParams, name, uuid, 'presence')
await checkVideoIsPublished(baseParams, name, video.uuid, 'presence')
})
it('Should send a notification when the scheduled update has been proceeded', async function () {
@ -349,13 +347,12 @@ describe('Test user notifications', function () {
name,
channelId,
privacy: VideoPrivacy.PRIVATE,
targetUrl: getBadVideoUrl()
targetUrl: ImportsCommand.getBadVideoUrl()
}
const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
const uuid = res.body.video.uuid
const { video } = await servers[0].importsCommand.importVideo({ attributes })
await waitJobs(servers)
await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getBadVideoUrl(), false, 'presence')
})
it('Should send a notification when the video import succeeded', async function () {
@ -367,13 +364,12 @@ describe('Test user notifications', function () {
name,
channelId,
privacy: VideoPrivacy.PRIVATE,
targetUrl: getGoodVideoUrl()
targetUrl: ImportsCommand.getGoodVideoUrl()
}
const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
const uuid = res.body.video.uuid
const { video } = await servers[0].importsCommand.importVideo({ attributes })
await waitJobs(servers)
await checkMyVideoImportIsFinished(baseParams, name, uuid, getGoodVideoUrl(), true, 'presence')
await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getGoodVideoUrl(), true, 'presence')
})
})

View File

@ -3,6 +3,7 @@
import 'mocha'
import * as chai from 'chai'
import {
areHttpImportTestsDisabled,
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
@ -11,20 +12,14 @@ import {
getVideo,
getVideosList,
immutableAssign,
ImportsCommand,
ServerInfo,
setAccessTokensToServers,
testCaptionFile
} from '../../../../shared/extra-utils'
import { areHttpImportTestsDisabled, testImage } from '../../../../shared/extra-utils/miscs/miscs'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import {
getMagnetURI,
getMyVideoImports,
getYoutubeHDRVideoUrl,
getYoutubeVideoUrl,
importVideo
} from '../../../../shared/extra-utils/videos/video-imports'
import { VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos'
testCaptionFile,
testImage,
waitJobs
} from '@shared/extra-utils'
import { VideoDetails, VideoPrivacy, VideoResolution } from '@shared/models'
const expect = chai.expect
@ -124,17 +119,17 @@ describe('Test video imports', function () {
}
{
const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() })
const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
expect(res.body.video.name).to.equal('small video - youtube')
const attributes = immutableAssign(baseAttributes, { targetUrl: ImportsCommand.getYoutubeVideoUrl() })
const { video } = await servers[0].importsCommand.importVideo({ attributes })
expect(video.name).to.equal('small video - youtube')
expect(res.body.video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`))
expect(res.body.video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`))
expect(video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`))
expect(video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`))
await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath)
await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath)
await testImage(servers[0].url, 'video_import_thumbnail', video.thumbnailPath)
await testImage(servers[0].url, 'video_import_preview', video.previewPath)
const bodyCaptions = await servers[0].captionsCommand.listVideoCaptions({ videoId: res.body.video.id })
const bodyCaptions = await servers[0].captionsCommand.listVideoCaptions({ videoId: video.id })
const videoCaptions = bodyCaptions.data
expect(videoCaptions).to.have.lengthOf(2)
@ -175,12 +170,12 @@ Ajouter un sous-titre est vraiment facile`)
{
const attributes = immutableAssign(baseAttributes, {
magnetUri: getMagnetURI(),
magnetUri: ImportsCommand.getMagnetURI(),
description: 'this is a super torrent description',
tags: [ 'tag_torrent1', 'tag_torrent2' ]
})
const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
expect(res.body.video.name).to.equal('super peertube2 video')
const { video } = await servers[0].importsCommand.importVideo({ attributes })
expect(video.name).to.equal('super peertube2 video')
}
{
@ -189,8 +184,8 @@ Ajouter un sous-titre est vraiment facile`)
description: 'this is a super torrent description',
tags: [ 'tag_torrent1', 'tag_torrent2' ]
})
const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
expect(res.body.video.name).to.equal('你好 世界 720p.mp4')
const { video } = await servers[0].importsCommand.importVideo({ attributes })
expect(video.name).to.equal('你好 世界 720p.mp4')
}
})
@ -207,19 +202,18 @@ Ajouter un sous-titre est vraiment facile`)
})
it('Should list the videos to import in my imports on server 1', async function () {
const res = await getMyVideoImports(servers[0].url, servers[0].accessToken, '-createdAt')
const { total, data: videoImports } = await servers[0].importsCommand.getMyVideoImports({ sort: '-createdAt' })
expect(total).to.equal(3)
expect(res.body.total).to.equal(3)
const videoImports: VideoImport[] = res.body.data
expect(videoImports).to.have.lengthOf(3)
expect(videoImports[2].targetUrl).to.equal(getYoutubeVideoUrl())
expect(videoImports[2].targetUrl).to.equal(ImportsCommand.getYoutubeVideoUrl())
expect(videoImports[2].magnetUri).to.be.null
expect(videoImports[2].torrentName).to.be.null
expect(videoImports[2].video.name).to.equal('small video - youtube')
expect(videoImports[1].targetUrl).to.be.null
expect(videoImports[1].magnetUri).to.equal(getMagnetURI())
expect(videoImports[1].magnetUri).to.equal(ImportsCommand.getMagnetURI())
expect(videoImports[1].torrentName).to.be.null
expect(videoImports[1].video.name).to.equal('super peertube2 video')
@ -248,7 +242,7 @@ Ajouter un sous-titre est vraiment facile`)
this.timeout(60_000)
const attributes = {
targetUrl: getYoutubeVideoUrl(),
targetUrl: ImportsCommand.getYoutubeVideoUrl(),
channelId: channelIdServer2,
privacy: VideoPrivacy.PUBLIC,
category: 10,
@ -258,8 +252,8 @@ Ajouter un sous-titre est vraiment facile`)
description: 'my super description',
tags: [ 'supertag1', 'supertag2' ]
}
const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
expect(res.body.video.name).to.equal('my super name')
const { video } = await servers[1].importsCommand.importVideo({ attributes })
expect(video.name).to.equal('my super name')
})
it('Should have the videos listed on the two instances', async function () {
@ -284,12 +278,12 @@ Ajouter un sous-titre est vraiment facile`)
const attributes = {
name: 'transcoded video',
magnetUri: getMagnetURI(),
magnetUri: ImportsCommand.getMagnetURI(),
channelId: channelIdServer2,
privacy: VideoPrivacy.PUBLIC
}
const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
const videoUUID = res.body.video.uuid
const { video } = await servers[1].importsCommand.importVideo({ attributes })
const videoUUID = video.uuid
await waitJobs(servers)
@ -335,12 +329,12 @@ Ajouter un sous-titre est vraiment facile`)
const attributes = {
name: 'hdr video',
targetUrl: getYoutubeHDRVideoUrl(),
targetUrl: ImportsCommand.getYoutubeHDRVideoUrl(),
channelId: channelIdServer1,
privacy: VideoPrivacy.PUBLIC
}
const res1 = await importVideo(servers[0].url, servers[0].accessToken, attributes)
const videoUUID = res1.body.video.uuid
const { video: videoImported } = await servers[0].importsCommand.importVideo({ attributes })
const videoUUID = videoImported.uuid
await waitJobs(servers)

View File

@ -15,6 +15,7 @@ import {
getLocalIdByUUID,
getVideo,
getVideosList,
ImportsCommand,
removeVideo,
ServerInfo,
setAccessTokensToServers,
@ -23,7 +24,6 @@ import {
userLogin,
waitJobs
} from '../../../shared/extra-utils'
import { getYoutubeVideoUrl } from '../../../shared/extra-utils/videos/video-imports'
describe('Test CLI wrapper', function () {
let server: ServerInfo
@ -122,7 +122,7 @@ describe('Test CLI wrapper', function () {
this.timeout(60000)
const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel`
const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} --channel-name user_channel`
await cliCommand.execWithEnv(`${cmd} import ${params}`)
})
@ -155,7 +155,8 @@ describe('Test CLI wrapper', function () {
this.timeout(60000)
const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support`
const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} ` +
`--channel-name user_channel --video-name toto --nsfw --support support`
await cliCommand.execWithEnv(`${cmd} import ${params}`)
await waitJobs([ server ])

View File

@ -18,6 +18,7 @@ import {
getVideosListPagination,
getVideoThreadComments,
getVideoWithToken,
ImportsCommand,
makeRawRequest,
PluginsCommand,
registerUser,
@ -30,16 +31,7 @@ import {
waitJobs,
waitUntilLog
} from '@shared/extra-utils'
import { getGoodVideoUrl, getMyVideoImports, importVideo } from '@shared/extra-utils/videos/video-imports'
import {
VideoCommentThreadTree,
VideoDetails,
VideoImport,
VideoImportState,
VideoPlaylist,
VideoPlaylistPrivacy,
VideoPrivacy
} from '@shared/models'
import { VideoCommentThreadTree, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
const expect = chai.expect
@ -157,23 +149,23 @@ describe('Test plugin filter hooks', function () {
})
it('Should run filter:api.video.pre-import-url.accept.result', async function () {
const baseAttributes = {
const attributes = {
name: 'normal title',
privacy: VideoPrivacy.PUBLIC,
channelId: servers[0].videoChannel.id,
targetUrl: getGoodVideoUrl() + 'bad'
targetUrl: ImportsCommand.getGoodVideoUrl() + 'bad'
}
await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403)
await servers[0].importsCommand.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
})
it('Should run filter:api.video.pre-import-torrent.accept.result', async function () {
const baseAttributes = {
const attributes = {
name: 'bad torrent',
privacy: VideoPrivacy.PUBLIC,
channelId: servers[0].videoChannel.id,
torrentfile: 'video-720p.torrent' as any
}
await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403)
await servers[0].importsCommand.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
})
it('Should run filter:api.video.post-import-url.accept.result', async function () {
@ -182,21 +174,21 @@ describe('Test plugin filter hooks', function () {
let videoImportId: number
{
const baseAttributes = {
const attributes = {
name: 'title with bad word',
privacy: VideoPrivacy.PUBLIC,
channelId: servers[0].videoChannel.id,
targetUrl: getGoodVideoUrl()
targetUrl: ImportsCommand.getGoodVideoUrl()
}
const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes)
videoImportId = res.body.id
const body = await servers[0].importsCommand.importVideo({ attributes })
videoImportId = body.id
}
await waitJobs(servers)
{
const res = await getMyVideoImports(servers[0].url, servers[0].accessToken)
const videoImports = res.body.data as VideoImport[]
const body = await servers[0].importsCommand.getMyVideoImports()
const videoImports = body.data
const videoImport = videoImports.find(i => i.id === videoImportId)
@ -211,21 +203,20 @@ describe('Test plugin filter hooks', function () {
let videoImportId: number
{
const baseAttributes = {
const attributes = {
name: 'title with bad word',
privacy: VideoPrivacy.PUBLIC,
channelId: servers[0].videoChannel.id,
torrentfile: 'video-720p.torrent' as any
}
const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes)
videoImportId = res.body.id
const body = await servers[0].importsCommand.importVideo({ attributes })
videoImportId = body.id
}
await waitJobs(servers)
{
const res = await getMyVideoImports(servers[0].url, servers[0].accessToken)
const videoImports = res.body.data as VideoImport[]
const { data: videoImports } = await servers[0].importsCommand.getMyVideoImports()
const videoImport = videoImports.find(i => i.id === videoImportId)
@ -278,17 +269,15 @@ describe('Test plugin filter hooks', function () {
describe('Should run filter:video.auto-blacklist.result', function () {
async function checkIsBlacklisted (oldRes: any, value: boolean) {
const videoId = oldRes.body.video.uuid
const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoId)
async function checkIsBlacklisted (id: number | string, value: boolean) {
const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, id)
const video: VideoDetails = res.body
expect(video.blacklisted).to.equal(value)
}
it('Should blacklist on upload', async function () {
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' })
await checkIsBlacklisted(res, true)
await checkIsBlacklisted(res.body.video.uuid, true)
})
it('Should blacklist on import', async function () {
@ -296,20 +285,20 @@ describe('Test plugin filter hooks', function () {
const attributes = {
name: 'video please blacklist me',
targetUrl: getGoodVideoUrl(),
targetUrl: ImportsCommand.getGoodVideoUrl(),
channelId: servers[0].videoChannel.id
}
const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
await checkIsBlacklisted(res, true)
const body = await servers[0].importsCommand.importVideo({ attributes })
await checkIsBlacklisted(body.video.uuid, true)
})
it('Should blacklist on update', async function () {
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
const videoId = res.body.video.uuid
await checkIsBlacklisted(res, false)
await checkIsBlacklisted(videoId, false)
await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' })
await checkIsBlacklisted(res, true)
await checkIsBlacklisted(videoId, true)
})
it('Should blacklist on remote upload', async function () {
@ -318,7 +307,7 @@ describe('Test plugin filter hooks', function () {
const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' })
await waitJobs(servers)
await checkIsBlacklisted(res, true)
await checkIsBlacklisted(res.body.video.uuid, true)
})
it('Should blacklist on remote update', async function () {
@ -328,12 +317,12 @@ describe('Test plugin filter hooks', function () {
await waitJobs(servers)
const videoId = res.body.video.uuid
await checkIsBlacklisted(res, false)
await checkIsBlacklisted(videoId, false)
await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' })
await waitJobs(servers)
await checkIsBlacklisted(res, true)
await checkIsBlacklisted(videoId, true)
})
})

View File

@ -18,7 +18,16 @@ import { makeGetRequest } from '../requests/requests'
import { SearchCommand } from '../search'
import { SocketIOCommand } from '../socket'
import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users'
import { BlacklistCommand, CaptionsCommand, ChangeOwnershipCommand, HistoryCommand, LiveCommand, PlaylistsCommand, ServicesCommand } from '../videos'
import {
BlacklistCommand,
CaptionsCommand,
ChangeOwnershipCommand,
HistoryCommand,
ImportsCommand,
LiveCommand,
PlaylistsCommand,
ServicesCommand
} from '../videos'
import { ConfigCommand } from './config-command'
import { ContactFormCommand } from './contact-form-command'
import { DebugCommand } from './debug-command'
@ -107,6 +116,7 @@ interface ServerInfo {
changeOwnershipCommand?: ChangeOwnershipCommand
playlistsCommand?: PlaylistsCommand
historyCommand?: HistoryCommand
importsCommand?: ImportsCommand
}
function parallelTests () {
@ -339,6 +349,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
server.changeOwnershipCommand = new ChangeOwnershipCommand(server)
server.playlistsCommand = new PlaylistsCommand(server)
server.historyCommand = new HistoryCommand(server)
server.importsCommand = new ImportsCommand(server)
res(server)
})

View File

@ -0,0 +1,86 @@
import { ResultList } from '@shared/models'
import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
import { VideoImport, VideoImportCreate } from '../../models/videos'
import { unwrapBody } from '../requests'
import { AbstractCommand, OverrideCommandOptions } from '../shared'
export class ImportsCommand extends AbstractCommand {
static getYoutubeVideoUrl () {
return 'https://www.youtube.com/watch?v=msX3jv1XdvM'
}
static getYoutubeHDRVideoUrl () {
/**
* The video is used to check format-selection correctness wrt. HDR,
* which brings its own set of oddities outside of a MediaSource.
* FIXME: refactor once HDR is supported at playback
*
* The video needs to have the following format_ids:
* (which you can check by using `youtube-dl <url> -F`):
* - 303 (1080p webm vp9)
* - 299 (1080p mp4 avc1)
* - 335 (1080p webm vp9.2 HDR)
*
* 15 jan. 2021: TEST VIDEO NOT CURRENTLY PROVIDING
* - 400 (1080p mp4 av01)
* - 315 (2160p webm vp9 HDR)
* - 337 (2160p webm vp9.2 HDR)
* - 401 (2160p mp4 av01 HDR)
*/
return 'https://www.youtube.com/watch?v=qR5vOXbZsI4'
}
static getMagnetURI () {
// eslint-disable-next-line max-len
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'
}
static getBadVideoUrl () {
return 'https://download.cpy.re/peertube/bad_video.mp4'
}
static getGoodVideoUrl () {
return 'https://download.cpy.re/peertube/good_video.mp4'
}
importVideo (options: OverrideCommandOptions & {
attributes: VideoImportCreate & { torrentfile?: string }
}) {
const { attributes } = options
const path = '/api/v1/videos/imports'
let attaches: any = {}
if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile }
return unwrapBody<VideoImport>(this.postUploadRequest({
...options,
path,
attaches,
fields: options.attributes,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
}))
}
getMyVideoImports (options: OverrideCommandOptions & {
sort?: string
} = {}) {
const { sort } = options
const path = '/api/v1/users/me/videos/imports'
const query = {}
if (sort) query['sort'] = sort
return this.getRequestBody<ResultList<VideoImport>>({
...options,
path,
query: { sort },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
}

View File

@ -3,6 +3,7 @@ export * from './captions'
export * from './captions-command'
export * from './change-ownership-command'
export * from './history-command'
export * from './imports-command'
export * from './live-command'
export * from './live'
export * from './playlists-command'
@ -10,6 +11,5 @@ export * from './playlists'
export * from './services-command'
export * from './video-channels'
export * from './video-comments'
export * from './video-imports'
export * from './video-streaming-playlists'
export * from './videos'

View File

@ -1,90 +0,0 @@
import { VideoImportCreate } from '../../models/videos'
import { makeGetRequest, makeUploadRequest } from '../requests/requests'
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
function getYoutubeVideoUrl () {
return 'https://www.youtube.com/watch?v=msX3jv1XdvM'
}
function getYoutubeHDRVideoUrl () {
/**
* The video is used to check format-selection correctness wrt. HDR,
* which brings its own set of oddities outside of a MediaSource.
* FIXME: refactor once HDR is supported at playback
*
* The video needs to have the following format_ids:
* (which you can check by using `youtube-dl <url> -F`):
* - 303 (1080p webm vp9)
* - 299 (1080p mp4 avc1)
* - 335 (1080p webm vp9.2 HDR)
*
* 15 jan. 2021: TEST VIDEO NOT CURRENTLY PROVIDING
* - 400 (1080p mp4 av01)
* - 315 (2160p webm vp9 HDR)
* - 337 (2160p webm vp9.2 HDR)
* - 401 (2160p mp4 av01 HDR)
*/
return 'https://www.youtube.com/watch?v=qR5vOXbZsI4'
}
function getMagnetURI () {
// eslint-disable-next-line max-len
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'
}
function getBadVideoUrl () {
return 'https://download.cpy.re/peertube/bad_video.mp4'
}
function getGoodVideoUrl () {
return 'https://download.cpy.re/peertube/good_video.mp4'
}
function importVideo (
url: string,
token: string,
attributes: VideoImportCreate & { torrentfile?: string },
statusCodeExpected = HttpStatusCode.OK_200
) {
const path = '/api/v1/videos/imports'
let attaches: any = {}
if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile }
return makeUploadRequest({
url,
path,
token,
attaches,
fields: attributes,
statusCodeExpected
})
}
function getMyVideoImports (url: string, token: string, sort?: string) {
const path = '/api/v1/users/me/videos/imports'
const query = {}
if (sort) query['sort'] = sort
return makeGetRequest({
url,
query,
path,
token,
statusCodeExpected: HttpStatusCode.OK_200
})
}
// ---------------------------------------------------------------------------
export {
getBadVideoUrl,
getYoutubeVideoUrl,
getYoutubeHDRVideoUrl,
importVideo,
getMagnetURI,
getMyVideoImports,
getGoodVideoUrl
}