"supertest": "^3.0.0",
"tslint": "^5.7.0",
"tslint-config-standard": "^7.0.0",
- "webtorrent": "^0.98.0"
+ "webtorrent": "^0.98.0",
+ "youtube-dl": "^1.12.2"
},
"scripty": {
"silent": true
+++ /dev/null
-import * as program from 'commander'
-
-import {
- getClient,
- serverLogin
-} from '../../utils'
-
-program
- .option('-u, --url <url>', 'Server url')
- .option('-n, --username <username>', 'Username')
- .option('-p, --password <token>', '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)
- })
+++ /dev/null
-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 <url>', 'Server url')
- .option('-U, --username <username>', 'Username')
- .option('-p, --password <token>', 'Password')
- .option('-i, --input <directory>', 'Videos directory absolute path')
- .option('-d, --description <description>', 'Video descriptions')
- .option('-c, --category <category>', 'Video categories')
- .option('-l, --licence <licence>', 'Video licences')
- .option('-t, --tags <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(',')
-}
+++ /dev/null
-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 <url>', 'Server url')
- .option('-a, --access-token <token>', 'Access token')
- .option('-n, --name <name>', 'Video name')
- .option('-N, --nsfw', 'Video is Not Safe For Work')
- .option('-c, --category <category number>', 'Category number')
- .option('-l, --licence <licence number>', 'Licence number')
- .option('-L, --language <language number>', 'Language number')
- .option('-d, --description <description>', 'Video description')
- .option('-t, --tags <tags>', 'Video tags', list)
- .option('-f, --file <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.`)
- })
-}
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.field('name', attributes.name)
- .field('category', attributes.category.toString())
- .field('licence', attributes.licence.toString())
.field('nsfw', JSON.stringify(attributes.nsfw))
.field('commentsEnabled', JSON.stringify(attributes.commentsEnabled))
.field('description', attributes.description)
if (attributes.language !== undefined) {
req.field('language', attributes.language.toString())
}
+ if (attributes.category !== undefined) {
+ req.field('category', attributes.category.toString())
+ }
+ if (attributes.licence !== undefined) {
+ req.field('licence', attributes.licence.toString())
+ }
for (let i = 0; i < attributes.tags.length; i++) {
req.field('tags[' + i + ']', attributes.tags[i])
--- /dev/null
+import * as program from 'commander'
+
+import {
+ getClient,
+ serverLogin
+} from '../tests/utils/index'
+
+program
+ .option('-u, --url <url>', 'Server url')
+ .option('-n, --username <username>', 'Username')
+ .option('-p, --password <token>', '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)
+ })
--- /dev/null
+import * as program from 'commander'
+import { createWriteStream } from 'fs'
+import { join } from 'path'
+import { cursorTo } from 'readline'
+import * as youtubeDL from 'youtube-dl'
+import { VideoPrivacy } from '../../shared/models/videos'
+import { unlinkPromise } from '../helpers/core-utils'
+import { getClient, getVideoCategories, login, searchVideo, uploadVideo } from '../tests/utils'
+
+program
+ .option('-u, --url <url>', 'Server url')
+ .option('-U, --username <username>', 'Username')
+ .option('-p, --password <token>', 'Password')
+ .option('-y, --youtube-url <directory>', 'Youtube URL')
+ .parse(process.argv)
+
+if (
+ !program['url'] ||
+ !program['username'] ||
+ !program['password'] ||
+ !program['youtubeUrl']
+) {
+ throw new Error('All arguments are required.')
+}
+
+run().catch(err => console.error(err))
+
+let accessToken: string
+
+async function run () {
+ const res = await getClient(program['url'])
+ const client = {
+ id: res.body.client_id,
+ secret: res.body.client_secret
+ }
+
+ const user = {
+ username: program['username'],
+ password: program['password']
+ }
+
+ const res2 = await login(program['url'], client, user)
+ accessToken = res2.body.access_token
+
+ youtubeDL.getInfo(program['youtubeUrl'], [ '-j', '--flat-playlist' ], async (err, info) => {
+ if (err) throw err
+
+ const videos = info.map(i => {
+ return { url: 'https://www.youtube.com/watch?v=' + i.id, name: i.title }
+ })
+
+ console.log('Will download and upload %d videos.\n', videos.length)
+
+ for (const video of videos) {
+ await processVideo(video)
+ }
+
+ console.log('I\'m finished!')
+ process.exit(0)
+ })
+}
+
+function processVideo (videoUrlName: { name: string, url: string }) {
+ return new Promise(async res => {
+ const result = await searchVideo(program['url'], videoUrlName.name)
+ if (result.body.total !== 0) {
+ console.log('Video "%s" already exist, don\'t reupload it.\n', videoUrlName.name)
+ return res()
+ }
+
+ const video = youtubeDL(videoUrlName.url)
+ let videoInfo
+ let videoPath: string
+
+ video.on('error', err => console.error(err))
+
+ let size = 0
+ video.on('info', info => {
+ videoInfo = info
+ size = info.size
+
+ videoPath = join(__dirname, size + '.mp4')
+ console.log('Creating "%s" of video "%s".', videoPath, videoInfo.title)
+
+ video.pipe(createWriteStream(videoPath))
+ })
+
+ let pos = 0
+ video.on('data', chunk => {
+ pos += chunk.length
+ // `size` should not be 0 here.
+ if (size) {
+ const percent = (pos / size * 100).toFixed(2)
+ writeWaitingPercent(percent)
+ }
+ })
+
+ video.on('end', async () => {
+ await uploadVideoOnPeerTube(videoInfo, videoPath)
+
+ return res()
+ })
+ })
+}
+
+function writeWaitingPercent (p: string) {
+ cursorTo(process.stdout, 0)
+ process.stdout.write(`waiting ... ${p}%`)
+}
+
+async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string) {
+ const category = await getCategory(videoInfo.categories)
+ const licence = getLicence(videoInfo.license)
+ const language = 13
+
+ const videoAttributes = {
+ name: videoInfo.title,
+ category,
+ licence,
+ language,
+ nsfw: false,
+ commentsEnabled: true,
+ description: videoInfo.description,
+ tags: videoInfo.tags.slice(0, 5),
+ privacy: VideoPrivacy.PUBLIC,
+ fixture: videoPath
+ }
+
+ console.log('\nUploading on PeerTube video "%s".', videoAttributes.name)
+ await uploadVideo(program['url'], accessToken, videoAttributes)
+ await unlinkPromise(videoPath)
+ console.log('Uploaded video "%s"!\n', videoAttributes.name)
+}
+
+async function getCategory (categories: string[]) {
+ const categoryString = categories[0]
+
+ if (categoryString === 'News & Politics') return 11
+
+ const res = await getVideoCategories(program['url'])
+ const categoriesServer = res.body
+
+ for (const key of Object.keys(categoriesServer)) {
+ const categoryServer = categoriesServer[key]
+ if (categoryString.toLowerCase() === categoryServer.toLowerCase()) return parseInt(key, 10)
+ }
+
+ return undefined
+}
+
+function getLicence (licence: string) {
+ if (licence.indexOf('Creative Commons Attribution licence') !== -1) return 1
+
+ return undefined
+}
--- /dev/null
+import * as program from 'commander'
+import * as Promise from 'bluebird'
+import { isAbsolute, join } from 'path'
+
+import { readdirPromise } from '../helpers/core-utils'
+import { execCLI } from '../tests/utils/index'
+
+program
+ .option('-u, --url <url>', 'Server url')
+ .option('-U, --username <username>', 'Username')
+ .option('-p, --password <token>', 'Password')
+ .option('-i, --input <directory>', 'Videos directory absolute path')
+ .option('-d, --description <description>', 'Video descriptions')
+ .option('-c, --category <category>', 'Video categories')
+ .option('-l, --licence <licence>', 'Video licences')
+ .option('-t, --tags <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(',')
+}
--- /dev/null
+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 '../tests/utils/index'
+
+program
+ .option('-u, --url <url>', 'Server url')
+ .option('-a, --access-token <token>', 'Access token')
+ .option('-n, --name <name>', 'Video name')
+ .option('-N, --nsfw', 'Video is Not Safe For Work')
+ .option('-c, --category <category number>', 'Category number')
+ .option('-l, --licence <licence number>', 'Licence number')
+ .option('-L, --language <language number>', 'Language number')
+ .option('-d, --description <description>', 'Video description')
+ .option('-t, --tags <tags>', 'Video tags', list)
+ .option('-f, --file <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.`)
+ })
+}
inherits "^2.0.3"
minimalistic-assert "^1.0.0"
+hashish@~0.0.4:
+ version "0.0.4"
+ resolved "https://registry.yarnpkg.com/hashish/-/hashish-0.0.4.tgz#6d60bc6ffaf711b6afd60e426d077988014e6554"
+ dependencies:
+ traverse ">=0.2.4"
+
hawk@3.1.3, hawk@~3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/hawk/-/hawk-3.1.3.tgz#078444bd7c1640b0fe540d2c9b73d59678e8e1c4"
version "1.1.1"
resolved "https://registry.yarnpkg.com/he/-/he-1.1.1.tgz#93410fd21b009735151f8868c2f271f3427e23fd"
+hh-mm-ss@^1.2.0:
+ version "1.2.0"
+ resolved "https://registry.yarnpkg.com/hh-mm-ss/-/hh-mm-ss-1.2.0.tgz#6d0f0b8280824a634cb1d1f20e0bc7bc8b689948"
+ dependencies:
+ zero-fill "^2.2.3"
+
highlight.js@^9.1.0:
version "9.12.0"
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.12.0.tgz#e6d9dbe57cbefe60751f02af336195870c90c01e"
dependencies:
once "^1.3.3"
+streamify@^0.2.9:
+ version "0.2.9"
+ resolved "https://registry.yarnpkg.com/streamify/-/streamify-0.2.9.tgz#8938b14db491e2b6be4f8d99cc4133c9f0384f0b"
+ dependencies:
+ hashish "~0.0.4"
+
streamsearch@0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-0.1.2.tgz#808b9d0e56fc273d809ba57338e929919a1a9f1a"
dependencies:
stack-chain "~1.3.1"
+traverse@>=0.2.4:
+ version "0.6.6"
+ resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.6.6.tgz#cbdf560fd7b9af632502fed40f918c157ea97137"
+
tree-kill@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.0.tgz#5846786237b4239014f05db156b643212d4c6f36"
version "2.0.0"
resolved "https://registry.yarnpkg.com/yn/-/yn-2.0.0.tgz#e5adabc8acf408f6385fc76495684c88e6af689a"
+youtube-dl@^1.12.2:
+ version "1.12.2"
+ resolved "https://registry.yarnpkg.com/youtube-dl/-/youtube-dl-1.12.2.tgz#11985268564c92b229f62b43d97374f86a605d1d"
+ dependencies:
+ hh-mm-ss "^1.2.0"
+ mkdirp "^0.5.1"
+ request "^2.83.0"
+ streamify "^0.2.9"
+
zero-fill@^2.2.3:
version "2.2.3"
resolved "https://registry.yarnpkg.com/zero-fill/-/zero-fill-2.2.3.tgz#a3def06ba5e39ae644850bb4ca2ad4112b4855e9"