mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Merge branch 'next' into develop
This commit is contained in:
@@ -1,82 +1,3 @@
|
||||
peertube(8) -- companion CLI for PeerTube
|
||||
=========================================
|
||||
# PeerTube CLI
|
||||
|
||||
SYNOPSIS
|
||||
--------
|
||||
|
||||
```
|
||||
peertube [command] [options]
|
||||
```
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
|
||||
`peertube` wraps various utilities around PeerTube that are used either on a running local, running remote, or cold local instance.
|
||||
|
||||
COMMANDS
|
||||
--------
|
||||
|
||||
Unless otherwise specified, every command can be queried for its own help or manual by passing its name to the `help` command, or by using the `--help` option.
|
||||
|
||||
`auth [action]`: stores credentials for your accounts on remote instances, so that you don't need to pass them at every command
|
||||
|
||||
`upload|up`: upload a video to a remote instance
|
||||
|
||||
$ peertube upload \
|
||||
-u "PEERTUBE_URL" \
|
||||
-U "PEERTUBE_USER" \
|
||||
--password "PEERTUBE_PASSWORD"
|
||||
|
||||
`import-videos|import`: import a video from a streaming platform to a remote instance
|
||||
|
||||
$ peertube import \
|
||||
-u "PEERTUBE_URL" \
|
||||
-U "PEERTUBE_USER" \
|
||||
--password "PEERTUBE_PASSWORD" \
|
||||
-t "TARGET_URL"
|
||||
|
||||
The target URL can be directly the video file, or any of the supported sites of youtube-dl. The video is downloaded locally and then uploaded. Already downloaded videos will not be uploaded twice, so you can run and re-run the script in case of crash, disconnection…
|
||||
|
||||
`watch|w`: watch a video in the terminal ✩°。⋆
|
||||
|
||||
-g, --gui <player> player type (default: ascii)
|
||||
-i, --invert invert colors (ascii player only)
|
||||
-r, --resolution <res> video resolution (default: 720)
|
||||
|
||||
It provides support for different players:
|
||||
|
||||
- ascii (default ; plays in ascii art in your terminal!)
|
||||
- mpv
|
||||
- mplayer
|
||||
- vlc
|
||||
- stdout
|
||||
- xbmc
|
||||
- airplay
|
||||
- chromecast
|
||||
|
||||
`repl`: interact with the application libraries and objects even when PeerTube is not running
|
||||
|
||||
Type .help to see the repl-only functions, or to see the available PeerTube core functions:
|
||||
|
||||
repl> lodash.keys(context)
|
||||
|
||||
`help [cmd]`: display help for [cmd]
|
||||
|
||||
EXAMPLES
|
||||
--------
|
||||
|
||||
$ peertube auth add -u "PEERTUBE_URL" -U "PEERTUBE_USER" --password "PEERTUBE_PASSWORD"
|
||||
$ peertube up <videoFile>
|
||||
$ peertube watch https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
|
||||
[PeerTube Tools Documentation](https://github.com/Chocobozzz/PeerTube/blob/develop/support/doc/tools.md)
|
||||
|
||||
[PeerTube Admin Documentation](https://docs.joinpeertube.org/lang/en/docs/)
|
||||
|
||||
REPORTING BUGS
|
||||
--------------
|
||||
|
||||
See [PeerTube repository](https://github.com/Chocobozzz/PeerTube).
|
||||
See https://docs.joinpeertube.org/maintain-tools?id=remote-tools
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
"dependencies": {
|
||||
"application-config": "^2.0.0",
|
||||
"cli-table3": "^0.6.0",
|
||||
"netrc-parser": "^3.1.6",
|
||||
"webtorrent-hybrid": "^4.0.3"
|
||||
"netrc-parser": "^3.1.6"
|
||||
},
|
||||
"devDependencies": {}
|
||||
}
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
import { registerTSPaths } from '../helpers/register-ts-paths'
|
||||
registerTSPaths()
|
||||
|
||||
import * as repl from 'repl'
|
||||
import * as path from 'path'
|
||||
import * as _ from 'lodash'
|
||||
import * as Sequelize from 'sequelize'
|
||||
import * as YoutubeDL from 'youtube-dl'
|
||||
import { initDatabaseModels, sequelizeTypescript } from '../initializers/database'
|
||||
import * as cli from '../tools/cli'
|
||||
import { logger } from '../helpers/logger'
|
||||
import * as constants from '../initializers/constants'
|
||||
import * as modelsUtils from '../models/utils'
|
||||
import * as coreUtils from '../helpers/core-utils'
|
||||
import * as ffmpegUtils from '../helpers/ffmpeg-utils'
|
||||
import * as peertubeCryptoUtils from '../helpers/peertube-crypto'
|
||||
import * as utils from '../helpers/utils'
|
||||
import * as YoutubeDLUtils from '../helpers/youtube-dl'
|
||||
|
||||
const start = async () => {
|
||||
await initDatabaseModels(true)
|
||||
|
||||
const versionCommitHash = await utils.getServerCommit()
|
||||
|
||||
const initContext = (replServer) => {
|
||||
return (context) => {
|
||||
const properties = {
|
||||
context,
|
||||
repl: replServer,
|
||||
env: process.env,
|
||||
lodash: _,
|
||||
path,
|
||||
cli,
|
||||
logger,
|
||||
constants,
|
||||
Sequelize,
|
||||
sequelizeTypescript,
|
||||
modelsUtils,
|
||||
models: sequelizeTypescript.models,
|
||||
transaction: sequelizeTypescript.transaction,
|
||||
query: sequelizeTypescript.query,
|
||||
queryInterface: sequelizeTypescript.getQueryInterface(),
|
||||
YoutubeDL,
|
||||
coreUtils,
|
||||
ffmpegUtils,
|
||||
peertubeCryptoUtils,
|
||||
utils,
|
||||
YoutubeDLUtils
|
||||
}
|
||||
|
||||
for (const prop in properties) {
|
||||
Object.defineProperty(context, prop, {
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
value: properties[prop]
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const replServer = repl.start({
|
||||
prompt: `PeerTube [${cli.version}] (${versionCommitHash})> `
|
||||
})
|
||||
|
||||
initContext(replServer)(replServer.context)
|
||||
replServer.on('reset', initContext(replServer))
|
||||
replServer.on('exit', () => process.exit())
|
||||
|
||||
const resetCommand = {
|
||||
help: 'Reset REPL',
|
||||
action () {
|
||||
this.write('.clear\n')
|
||||
this.displayPrompt()
|
||||
}
|
||||
}
|
||||
replServer.defineCommand('reset', resetCommand)
|
||||
replServer.defineCommand('r', resetCommand)
|
||||
}
|
||||
|
||||
start()
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
@@ -1,42 +0,0 @@
|
||||
import { registerTSPaths } from '../helpers/register-ts-paths'
|
||||
registerTSPaths()
|
||||
|
||||
import { program, Option, OptionValues } from 'commander'
|
||||
import { join } from 'path'
|
||||
import { execSync } from 'child_process'
|
||||
|
||||
program
|
||||
.name('watch')
|
||||
.arguments('<url>')
|
||||
.addOption(
|
||||
new Option('-g, --gui <player>', 'player type')
|
||||
.default('vlc')
|
||||
.choices([ 'airplay', 'stdout', 'chromecast', 'mpv', 'vlc', 'mplayer', 'xbmc' ])
|
||||
)
|
||||
.option('-r, --resolution <res>', 'video resolution', '480')
|
||||
.addHelpText('after', '\n\n Examples:\n\n' +
|
||||
' $ peertube watch -g mpv https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10\n' +
|
||||
' $ peertube watch --gui stdout https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10\n' +
|
||||
' $ peertube watch https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10\n'
|
||||
)
|
||||
.action((url, options) => run(url, options))
|
||||
.parse(process.argv)
|
||||
|
||||
function run (url: string, options: OptionValues) {
|
||||
if (!url) {
|
||||
console.error('<url> positional argument is required.')
|
||||
process.exit(-1)
|
||||
}
|
||||
|
||||
const cmd = 'node ' + join(__dirname, 'node_modules', 'webtorrent-hybrid', 'bin', 'cmd.js')
|
||||
const args = ` --${options.gui} ` +
|
||||
url.replace(/(\/videos\/watch\/)|\/w\//, '/download/torrents/') +
|
||||
`-${options.resolution}.torrent`
|
||||
|
||||
try {
|
||||
execSync(cmd + args)
|
||||
} catch (err) {
|
||||
console.error('Cannto exec command.', err)
|
||||
process.exit(-1)
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/* eslint-disable no-useless-escape */
|
||||
|
||||
import { registerTSPaths } from '../helpers/register-ts-paths'
|
||||
registerTSPaths()
|
||||
|
||||
@@ -18,8 +16,6 @@ program
|
||||
.command('upload', 'upload a video').alias('up')
|
||||
.command('import-videos', 'import a video from a streaming platform').alias('import')
|
||||
.command('get-access-token', 'get a peertube access token', { noHelp: true }).alias('token')
|
||||
.command('watch', 'watch a video in the terminal ✩°。⋆').alias('w')
|
||||
.command('repl', 'initiate a REPL to access internals')
|
||||
.command('plugins [action]', 'manage instance plugins/themes').alias('p')
|
||||
.command('redundancy [action]', 'manage instance redundancies').alias('r')
|
||||
|
||||
@@ -47,7 +43,7 @@ if (!process.argv.slice(2).length) {
|
||||
/ / -" _/"/
|
||||
/ | ._\\\\ |\\ |_.".-" /
|
||||
/ | __\\)|)|),/|_." _,."
|
||||
/ \_." " ") | ).-""---''--
|
||||
/ \\_." " ") | ).-""---''--
|
||||
( "/.""7__-""''
|
||||
| " ."._--._
|
||||
\\ \\ (_ __ "" ".,_
|
||||
@@ -72,8 +68,7 @@ getSettings()
|
||||
.addHelpText('after', '\n\n State: ' + state + '\n\n' +
|
||||
' Examples:\n\n' +
|
||||
' $ peertube auth add -u "PEERTUBE_URL" -U "PEERTUBE_USER" --password "PEERTUBE_PASSWORD"\n' +
|
||||
' $ peertube up <videoFile>\n' +
|
||||
' $ peertube watch https://peertube.cpy.re/videos/watch/e8a1af4e-414a-4d58-bfe6-2146eed06d10\n'
|
||||
' $ peertube up <videoFile>\n'
|
||||
)
|
||||
.parse(process.argv)
|
||||
})
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
import { program } from 'commander'
|
||||
import { LiveVideoCreate, VideoPrivacy } from '@shared/models'
|
||||
import {
|
||||
createSingleServer,
|
||||
killallServers,
|
||||
sendRTMPStream,
|
||||
PeerTubeServer,
|
||||
setAccessTokensToServers,
|
||||
setDefaultVideoChannel
|
||||
} from '../../shared/extra-utils'
|
||||
import { registerTSPaths } from '../helpers/register-ts-paths'
|
||||
|
||||
registerTSPaths()
|
||||
|
||||
type CommandType = 'live-mux' | 'live-transcoding'
|
||||
|
||||
registerTSPaths()
|
||||
|
||||
const command = program
|
||||
.name('test-live')
|
||||
.option('-t, --type <type>', 'live-muxing|live-transcoding')
|
||||
.parse(process.argv)
|
||||
|
||||
run()
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
process.exit(-1)
|
||||
})
|
||||
|
||||
async function run () {
|
||||
const commandType: CommandType = command['type']
|
||||
if (!commandType) {
|
||||
console.error('Miss command type')
|
||||
process.exit(-1)
|
||||
}
|
||||
|
||||
console.log('Starting server.')
|
||||
|
||||
const server = await createSingleServer(1, {}, { hideLogs: false, nodeArgs: [ '--inspect' ] })
|
||||
|
||||
const cleanup = async () => {
|
||||
console.log('Killing server')
|
||||
await killallServers([ server ])
|
||||
}
|
||||
|
||||
process.on('exit', cleanup)
|
||||
process.on('SIGINT', cleanup)
|
||||
|
||||
await setAccessTokensToServers([ server ])
|
||||
await setDefaultVideoChannel([ server ])
|
||||
|
||||
await buildConfig(server, commandType)
|
||||
|
||||
const attributes: LiveVideoCreate = {
|
||||
name: 'live',
|
||||
saveReplay: true,
|
||||
channelId: server.store.channel.id,
|
||||
privacy: VideoPrivacy.PUBLIC
|
||||
}
|
||||
|
||||
console.log('Creating live.')
|
||||
|
||||
const { uuid: liveVideoUUID } = await server.live.create({ fields: attributes })
|
||||
|
||||
const live = await server.live.get({ videoId: liveVideoUUID })
|
||||
|
||||
console.log('Sending RTMP stream.')
|
||||
|
||||
const ffmpegCommand = sendRTMPStream({ rtmpBaseUrl: live.rtmpUrl, streamKey: live.streamKey })
|
||||
|
||||
ffmpegCommand.on('error', err => {
|
||||
console.error(err)
|
||||
process.exit(-1)
|
||||
})
|
||||
|
||||
ffmpegCommand.on('end', () => {
|
||||
console.log('ffmpeg ended')
|
||||
process.exit(0)
|
||||
})
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
async function buildConfig (server: PeerTubeServer, commandType: CommandType) {
|
||||
await server.config.updateCustomSubConfig({
|
||||
newConfig: {
|
||||
instance: {
|
||||
customizations: {
|
||||
javascript: '',
|
||||
css: ''
|
||||
}
|
||||
},
|
||||
live: {
|
||||
enabled: true,
|
||||
allowReplay: true,
|
||||
transcoding: {
|
||||
enabled: commandType === 'live-transcoding'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user