/* tslint:disable:no-unused-expression */
import { expect } from 'chai'
-import { existsSync, readdir, readFile } from 'fs-extra'
+import { pathExists, readdir, readFile } from 'fs-extra'
import * as parseTorrent from 'parse-torrent'
import { extname, join } from 'path'
import * as request from 'supertest'
ServerInfo,
testImage
} from '../'
-
+import * as validator from 'validator'
import { VideoDetails, VideoPrivacy } from '../../models/videos'
-import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants'
+import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, loadLanguages, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants'
import { dateIsValid, webtorrentAdd } from '../miscs/miscs'
+loadLanguages()
+
type VideoAttributes = {
name?: string
category?: number
})
}
+function getPlaylistVideos (
+ url: string,
+ accessToken: string,
+ playlistId: number | string,
+ start: number,
+ count: number,
+ query: { nsfw?: boolean } = {}
+) {
+ const path = '/api/v1/video-playlists/' + playlistId + '/videos'
+
+ return makeGetRequest({
+ url,
+ path,
+ query: immutableAssign(query, {
+ start,
+ count
+ }),
+ token: accessToken,
+ statusCodeExpected: 200
+ })
+}
+
function getVideosListPagination (url: string, start: number, count: number, sort?: string) {
const path = '/api/v1/videos'
for (const directory of directories) {
const directoryPath = join(root(), testDirectory, directory)
- const directoryExists = existsSync(directoryPath)
- if (!directoryExists) continue
+ const directoryExists = await pathExists(directoryPath)
+ if (directoryExists === false) continue
const files = await readdir(directoryPath)
for (const file of files) {
}
}
+async function videoUUIDToId (url: string, id: number | string) {
+ if (validator.isUUID('' + id) === false) return id
+
+ const res = await getVideo(url, id)
+ return res.body.id
+}
+
+async function uploadVideoAndGetId (options: { server: ServerInfo, videoName: string, nsfw?: boolean, token?: string }) {
+ const videoAttrs: any = { name: options.videoName }
+ if (options.nsfw) videoAttrs.nsfw = options.nsfw
+
+ const res = await uploadVideo(options.server.url, options.token || options.server.accessToken, videoAttrs)
+
+ return { id: res.body.video.id, uuid: res.body.video.uuid }
+}
+
// ---------------------------------------------------------------------------
export {
getVideoDescription,
getVideoCategories,
getVideoLicences,
+ videoUUIDToId,
getVideoPrivacies,
getVideoLanguages,
getMyVideos,
parseTorrentVideo,
getLocalVideos,
completeVideoCheck,
- checkVideoFilesWereRemoved
+ checkVideoFilesWereRemoved,
+ getPlaylistVideos,
+ uploadVideoAndGetId
}