From a7fea183f0f69104b209e7bfdd6435be28165f22 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Feb 2018 16:47:06 +0100 Subject: Begin import script with youtube-dl --- server/tests/real-world/tools/get-access-token.ts | 48 ------------- server/tests/real-world/tools/upload-directory.ts | 82 ---------------------- server/tests/real-world/tools/upload.ts | 85 ----------------------- 3 files changed, 215 deletions(-) delete mode 100644 server/tests/real-world/tools/get-access-token.ts delete mode 100644 server/tests/real-world/tools/upload-directory.ts delete mode 100644 server/tests/real-world/tools/upload.ts (limited to 'server/tests/real-world') diff --git a/server/tests/real-world/tools/get-access-token.ts b/server/tests/real-world/tools/get-access-token.ts deleted file mode 100644 index ee14733e3..000000000 --- a/server/tests/real-world/tools/get-access-token.ts +++ /dev/null @@ -1,48 +0,0 @@ -import * as program from 'commander' - -import { - getClient, - serverLogin -} from '../../utils' - -program - .option('-u, --url ', 'Server url') - .option('-n, --username ', 'Username') - .option('-p, --password ', 'Password') - .parse(process.argv) - -if ( - !program['url'] || - !program['username'] || - !program['password'] -) { - throw new Error('All arguments are required.') -} - -const server = { - url: program['url'], - user: { - username: program['username'], - password: program['password'] - }, - client: { - id: null, - secret: null - } -} - -getClient(program.url) - .then(res => { - server.client.id = res.body.client_id - server.client.secret = res.body.client_secret - - return serverLogin(server) - }) - .then(accessToken => { - console.log(accessToken) - process.exit(0) - }) - .catch(err => { - console.error(err) - process.exit(-1) - }) diff --git a/server/tests/real-world/tools/upload-directory.ts b/server/tests/real-world/tools/upload-directory.ts deleted file mode 100644 index fdd56857a..000000000 --- a/server/tests/real-world/tools/upload-directory.ts +++ /dev/null @@ -1,82 +0,0 @@ -import * as program from 'commander' -import * as Promise from 'bluebird' -import { isAbsolute, join } from 'path' - -import { readdirPromise } from '../../../helpers/core-utils' -import { execCLI } from '../../utils' - -program - .option('-u, --url ', 'Server url') - .option('-U, --username ', 'Username') - .option('-p, --password ', 'Password') - .option('-i, --input ', 'Videos directory absolute path') - .option('-d, --description ', 'Video descriptions') - .option('-c, --category ', 'Video categories') - .option('-l, --licence ', 'Video licences') - .option('-t, --tags ', 'Video tags', list) - .parse(process.argv) - -if ( - !program['url'] || - !program['username'] || - !program['password'] || - !program['input'] || - !program['description'] || - !program['category'] || - !program['licence'] || - !program['tags'] -) { - throw new Error('All arguments are required.') -} - -if (isAbsolute(program['input']) === false) { - throw new Error('Input path should be absolute.') -} - -let command = `npm run ts-node -- ${__dirname}/get-access-token.ts` -command += ` -u "${program['url']}"` -command += ` -n "${program['username']}"` -command += ` -p "${program['password']}"` - -execCLI(command) - .then(stdout => { - const accessToken = stdout.replace('\n', '') - - console.log(accessToken) - - return readdirPromise(program['input']).then(files => ({ accessToken, files })) - }) - .then(({ accessToken, files }) => { - return Promise.each(files, file => { - const video = { - tags: program['tags'], - name: file, - description: program['description'], - category: program['category'], - licence: program['licence'] - } - - let command = `npm run ts-node -- ${__dirname}/upload.ts` - command += ` -u "${program['url']}"` - command += ` -a "${accessToken}"` - command += ` -n "${video.name}"` - command += ` -d "${video.description}"` - command += ` -c "${video.category}"` - command += ` -l "${video.licence}"` - command += ` -t "${video.tags.join(',')}"` - command += ` -f "${join(program['input'], file)}"` - - return execCLI(command).then(stdout => console.log(stdout)) - }) - }) - .then(() => process.exit(0)) - .catch(err => { - console.error(err) - process.exit(-1) - }) - -// ---------------------------------------------------------------------------- - -function list (val) { - return val.split(',') -} diff --git a/server/tests/real-world/tools/upload.ts b/server/tests/real-world/tools/upload.ts deleted file mode 100644 index 81bc0d415..000000000 --- a/server/tests/real-world/tools/upload.ts +++ /dev/null @@ -1,85 +0,0 @@ -import * as program from 'commander' -import { access, constants } from 'fs' -import { isAbsolute } from 'path' -import { promisify } from 'util' - -const accessPromise = promisify(access) - -import { uploadVideo } from '../../utils' - -program - .option('-u, --url ', 'Server url') - .option('-a, --access-token ', 'Access token') - .option('-n, --name ', 'Video name') - .option('-N, --nsfw', 'Video is Not Safe For Work') - .option('-c, --category ', 'Category number') - .option('-l, --licence ', 'Licence number') - .option('-L, --language ', 'Language number') - .option('-d, --description ', 'Video description') - .option('-t, --tags ', 'Video tags', list) - .option('-f, --file ', 'Video absolute file path') - .parse(process.argv) - -if (!program['tags']) program['tags'] = [] -if (!program['nsfw']) program['nsfw'] = false - -if ( - !program['url'] || - !program['accessToken'] || - !program['name'] || - !program['category'] || - !program['licence'] || - !program['description'] || - !program['file'] -) { - throw new Error('All arguments but tags, language and nsfw are required.') -} - -if (isAbsolute(program['file']) === false) { - throw new Error('File path should be absolute.') -} - -accessPromise(program['file'], constants.F_OK) - .then(() => { - return upload( - program['url'], - program['accessToken'], - program['name'], - program['category'], - program['licence'], - program['language'], - program['nsfw'], - program['description'], - program['tags'], - program['file'] - ) - }) - .then(() => process.exit(0)) - .catch(err => { - console.error(err) - process.exit(-1) - }) - -// ---------------------------------------------------------------------------- - -function list (val) { - return val.split(',') -} - -function upload (url, accessToken, name, category, licence, language, nsfw, description, tags, fixture) { - console.log('Uploading %s video...', program['name']) - - const videoAttributes = { - name, - category, - licence, - language, - nsfw, - description, - tags, - fixture - } - return uploadVideo(url, accessToken, videoAttributes).then(() => { - console.log(`Video ${name} uploaded.`) - }) -} -- cgit v1.2.3