]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - support/doc/tools.md
Improve responsive on medium destkop screens
[github/Chocobozzz/PeerTube.git] / support / doc / tools.md
CommitLineData
c141f68b
RK
1# CLI tools guide
2
76ad705e
C
3[[toc]]
4
5## Remote PeerTube CLI
d639c3bf
C
6
7You need at least 512MB RAM to run the script.
8Scripts can be launched directly from a PeerTube server, or from a separate server, even a desktop PC.
9You need to follow all the following steps even if you are on a PeerTube server (including cloning the git repository in a different directory than your production installation because the scripts utilize non-production dependencies).
10
11### Dependencies
12
1ab94472 13Install the [PeerTube dependencies](/support/doc/dependencies.md) except PostgreSQL and Redis.
d639c3bf
C
14
15### Installation
16
17Clone the PeerTube repo to get the latest version (even if you are on your PeerTube server):
18
c83af8f9 19```bash
00ee545c
C
20git clone https://github.com/Chocobozzz/PeerTube.git
21CLONE="$(pwd)/PeerTube"
22cd ${CLONE}
d639c3bf
C
23```
24
7e9d3f25
C
25Install dependencies and build CLI tools:
26
c83af8f9 27```bash
00ee545c
C
28NOCLIENT=1 yarn install --pure-lockfile
29npm run setup:cli
d639c3bf
C
30```
31
32### CLI wrapper
8704acf4 33
bb8f7872
C
34The wrapper provides a convenient interface to the following scripts.
35You can access it as `peertube` via an alias in your `.bashrc` like `alias peertube="cd /your/peertube/directory/ && node ./dist/server/tools/peertube.js"` (you have to keep the `cd` command):
8704acf4
RK
36
37```
38 Usage: peertube [command] [options]
39
40 Options:
41
42 -v, --version output the version number
43 -h, --help output usage information
44
45 Commands:
46
47 auth [action] register your accounts on remote instances to use them with other commands
48 upload|up upload a video
49 import-videos|import import a video from a streaming platform
e669ff58
C
50 plugins|p [action] manage instance plugins
51 redundancy|r [action] manage video redundancies
8704acf4
RK
52 help [cmd] display help for [cmd]
53```
54
55The wrapper can keep track of instances you have an account on. We limit to one account per instance for now.
56
57```bash
00ee545c
C
58peertube auth add -u 'PEERTUBE_URL' -U 'PEERTUBE_USER' --password 'PEERTUBE_PASSWORD'
59peertube auth list
8704acf4
RK
60┌──────────────────────────────┬──────────────────────────────┐
61│ instance │ login │
62├──────────────────────────────┼──────────────────────────────┤
5b036b8e 63│ 'PEERTUBE_URL' │ 'PEERTUBE_USER' │
8704acf4
RK
64└──────────────────────────────┴──────────────────────────────┘
65```
66
67You can now use that account to upload videos without feeding the same parameters again.
68
69```bash
00ee545c 70peertube up <videoFile>
8704acf4
RK
71```
72
9b474844
C
73To list, install, uninstall dynamically plugins/themes of an instance:
74
75```bash
00ee545c
C
76peertube plugins list
77peertube plugins install --path /local/plugin/path
78peertube plugins install --npm-name peertube-plugin-myplugin
79peertube plugins uninstall --npm-name peertube-plugin-myplugin
9b474844
C
80```
81
d639c3bf 82#### peertube-import-videos.js
358770db 83
1f8ac024 84You can use this script to import videos from all [supported sites of youtube-dl](https://rg3.github.io/youtube-dl/supportedsites.html) into PeerTube.
358770db 85Be sure you own the videos or have the author's authorization to do so.
2519d9fe 86
a5f0521f 87```sh
00ee545c 88node dist/server/tools/peertube-import-videos.js \
5b036b8e
C
89 -u 'PEERTUBE_URL' \
90 -U 'PEERTUBE_USER' \
9024bece 91 --password 'PEERTUBE_PASSWORD' \
8a08bc1e 92 --target-url 'TARGET_URL'
2519d9fe
L
93```
94
a5f0521f
RK
95* `PEERTUBE_URL` : the full URL of your PeerTube server where you want to import, eg: https://peertube.cpy.re
96* `PEERTUBE_USER` : your PeerTube account where videos will be uploaded
e8a739e8 97* `PEERTUBE_PASSWORD` : password of your PeerTube account (if `--password PEERTUBE_PASSWORD` is omitted, you will be prompted for it)
a5f0521f
RK
98* `TARGET_URL` : the target url you want to import. Examples:
99 * YouTube:
100 * Channel: https://www.youtube.com/channel/ChannelId
101 * User https://www.youtube.com/c/UserName or https://www.youtube.com/user/UserName
102 * Video https://www.youtube.com/watch?v=blabla
103 * Vimeo: https://vimeo.com/xxxxxx
104 * Dailymotion: https://www.dailymotion.com/xxxxx
2519d9fe 105
2186386c
C
106The script will get all public videos from Youtube, download them and upload to PeerTube.
107Already downloaded videos will not be uploaded twice, so you can run and re-run the script in case of crash, disconnection...
108
109Videos will be publicly available after transcoding (you can see them before that in your account on the web interface).
110
1f8ac024
F
111**NB**: If you want to synchronize a Youtube channel to your PeerTube instance (ensure you have the agreement from the author),
112you can add a [crontab rule](https://help.ubuntu.com/community/CronHowto) (or an equivalent of your OS) and insert
113these rules (ensure to customize them to your needs):
114
115```
116# Update youtube-dl every day at midnight
1170 0 * * * /usr/bin/npm rebuild youtube-dl --prefix /PATH/TO/PEERTUBE/
118
119# Synchronize the YT channel every sunday at 22:00 all the videos published since last monday included
927d14bd 1200 22 * * 0 /usr/bin/node /PATH/TO/PEERTUBE/dist/server/tools/peertube-import-videos.js -u '__PEERTUBE_URL__' -U '__USER__' --password '__PASSWORD__' --target-url 'https://www.youtube.com/channel/___CHANNEL__' --since $(date --date="-6 days" +\%Y-\%m-\%d)
1f8ac024
F
121```
122
123Also you may want to subscribe to the PeerTube channel in order to manually check the synchronization is successful.
358770db 124
d639c3bf 125#### peertube-upload.js
358770db
C
126
127You can use this script to import videos directly from the CLI.
128
2186386c
C
129Videos will be publicly available after transcoding (you can see them before that in your account on the web interface).
130
c83af8f9 131```bash
00ee545c
C
132cd ${CLONE}
133node dist/server/tools/peertube-upload.js --help
358770db 134```
a5f0521f 135
8dd2d050
C
136#### peertube-plugins.js
137
138Install/update/uninstall or list local or NPM PeerTube plugins:
139
c83af8f9 140```bash
00ee545c
C
141cd ${CLONE}
142node dist/server/tools/peertube-plugins.js --help
143node dist/server/tools/peertube-plugins.js list --help
144node dist/server/tools/peertube-plugins.js install --help
145node dist/server/tools/peertube-plugins.js update --help
146node dist/server/tools/peertube-plugins.js uninstall --help
147
148node dist/server/tools/peertube-plugins.js install --path /my/plugin/path
149node dist/server/tools/peertube-plugins.js install --npm-name peertube-theme-example
8dd2d050
C
150```
151
e669ff58
C
152#### peertube-redundancy.js
153
154Manage (list/add/remove) video redundancies:
155
156To list your videos that are duplicated by remote instances:
157
c83af8f9 158```bash
00ee545c 159node dist/server/tools/peertube.js redundancy list-remote-redundancies
e669ff58
C
160```
161
162To list remote videos that your instance duplicated:
163
c83af8f9 164```bash
00ee545c 165node dist/server/tools/peertube.js redundancy list-my-redundancies
e669ff58
C
166```
167
168To duplicate a specific video in your redundancy system:
169
c83af8f9 170```bash
00ee545c 171node dist/server/tools/peertube.js redundancy add --video 823
e669ff58
C
172```
173
174To remove a video redundancy:
175
c83af8f9 176```bash
00ee545c 177node dist/server/tools/peertube.js redundancy remove --video 823
e669ff58
C
178```
179
54a3a12e
C
180## Server tools
181
182These scripts should be run on the server, in `peertube-latest` directory.
a5f0521f 183
0ee02734
C
184### parse-log
185
186To parse PeerTube last log file:
187
c83af8f9 188```bash
00ee545c
C
189# Basic installation
190cd /var/www/peertube/peertube-latest
191sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run parse-log -- --level info
cb6a78c2 192
00ee545c
C
193# Docker installation
194cd /var/www/peertube-docker
195docker-compose exec -u peertube peertube npm run parse-log -- --level info
0ee02734
C
196```
197
198`--level` is optional and could be `info`/`warn`/`error`
199
cb6a78c2 200You can also remove SQL or HTTP logs using `--not-tags` (PeerTube >= 3.2):
7992c9e1 201
cb6a78c2 202```bash
00ee545c
C
203# Basic installation
204cd /var/www/peertube/peertube-latest
205sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run parse-log -- --level debug --not-tags http sql
cb6a78c2 206
00ee545c
C
207# Docker installation
208cd /var/www/peertube-docker
209docker-compose exec -u peertube peertube npm run parse-log -- --level debug --not-tags http sql
7992c9e1
C
210```
211
c2bd7a6f
C
212### regenerate-thumbnails.js
213
cb6a78c2
C
214**PeerTube >= 3.2**
215
c2bd7a6f
C
216Regenerating local video thumbnails could be useful because new PeerTube releases may increase thumbnail sizes:
217
cb6a78c2 218```bash
00ee545c
C
219# Basic installation
220cd /var/www/peertube/peertube-latest
221sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run regenerate-thumbnails
cb6a78c2 222
00ee545c
C
223# Docker installation
224cd /var/www/peertube-docker
225docker-compose exec -u peertube peertube npm run regenerate-thumbnails
c2bd7a6f
C
226```
227
a5f0521f
RK
228### create-import-video-file-job.js
229
221ee1ad 230You can use this script to import a video file to replace an already uploaded file or to add a new webtorrent resolution to a video. PeerTube needs to be running.
b708c9e4 231You can then create a transcoding job using the web interface if you need to optimize your file or create an HLS version of it.
a5f0521f 232
c83af8f9 233```bash
00ee545c
C
234# Basic installation
235cd /var/www/peertube/peertube-latest
236sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run create-import-video-file-job -- -v [videoUUID] -i [videoFile]
cb6a78c2 237
00ee545c
C
238# Docker installation
239cd /var/www/peertube-docker
240docker-compose exec -u peertube peertube npm run create-import-video-file-job -- -v [videoUUID] -i [videoFile]
54a3a12e
C
241```
242
e1ab52d7 243### create-move-video-storage-job.js
244
9c391612
C
245**PeerTube >= 4.0**
246
e1ab52d7 247Use this script to move all video files or a specific video file to object storage.
248
249```bash
00ee545c
C
250# Basic installation
251cd /var/www/peertube/peertube-latest
252sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run create-move-video-storage-job -- --to-object-storage -v [videoUUID]
e1ab52d7 253
00ee545c
C
254# Docker installation
255cd /var/www/peertube-docker
256docker-compose exec -u peertube peertube npm run create-move-video-storage-job -- --to-object-storage -v [videoUUID]
e1ab52d7 257```
258
259The script can also move all video files that are not already in object storage:
260
261```bash
00ee545c
C
262# Basic installation
263cd /var/www/peertube/peertube-latest
264sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run create-move-video-storage-job -- --to-object-storage --all-videos
e1ab52d7 265
00ee545c
C
266# Docker installation
267cd /var/www/peertube-docker
268docker-compose exec -u peertube peertube npm run create-move-video-storage-job -- --to-object-storage --all-videos
e1ab52d7 269```
270
271
54a3a12e
C
272### prune-storage.js
273
274Some transcoded videos or shutdown at a bad time can leave some unused files on your storage.
7089e7b4 275Stop PeerTube and delete these files (a confirmation will be demanded first):
54a3a12e 276
c83af8f9 277```bash
00ee545c
C
278cd /var/www/peertube/peertube-latest
279sudo systemctl stop peertube && sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run prune-storage
23687332
C
280```
281
edb4ffc7 282
23687332
C
283### update-host.js
284
fffc7c08 285**Changing the hostname is unsupported and may be a risky operation, especially if you have already federated.**
12b119c0
RK
286If you started PeerTube with a domain, and then changed it you will have
287invalid torrent files and invalid URLs in your database. To fix this, you have
fffc7c08 288to run the command below (keep in mind your follower instances will NOT update their URLs).
23687332 289
c83af8f9 290```bash
00ee545c
C
291# Basic installation
292cd /var/www/peertube/peertube-latest
293sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run update-host
cb6a78c2 294
00ee545c
C
295# Docker installation
296cd /var/www/peertube-docker
297docker-compose exec -u peertube peertube npm run update-host
ecf06378 298```
1e59ca3b 299
31b48aad
C
300### reset-password.js
301
302To reset a user password from CLI, run:
303
c83af8f9 304```bash
00ee545c
C
305# Basic installation
306cd /var/www/peertube/peertube-latest
307sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run reset-password -- -u target_username
cb6a78c2 308
00ee545c
C
309# Docker installation
310cd /var/www/peertube-docker
311docker-compose exec -u peertube peertube npm run reset-password -- -u target_username
31b48aad
C
312```
313
9b474844
C
314
315### plugin install/uninstall
316
317The difference with `peertube plugins` CLI is that these scripts can be used even if PeerTube is not running.
318If PeerTube is running, you need to restart it for the changes to take effect (whereas with `peertube plugins` CLI, plugins/themes are dynamically loaded on the server).
319
8dd2d050 320To install/update a plugin or a theme from the disk:
9b474844 321
c83af8f9 322```bash
00ee545c
C
323cd /var/www/peertube/peertube-latest
324sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run plugin:install -- --plugin-path /local/plugin/path
cb6a78c2 325
00ee545c
C
326# Docker installation
327cd /var/www/peertube-docker
328docker-compose exec -u peertube peertube npm run plugin:install -- --plugin-path /local/plugin/path
9b474844
C
329```
330
331From NPM:
332
c83af8f9 333```bash
00ee545c
C
334cd /var/www/peertube/peertube-latest
335sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run plugin:install -- --npm-name peertube-plugin-myplugin
cb6a78c2 336
00ee545c
C
337# Docker installation
338cd /var/www/peertube-docker
339docker-compose exec -u peertube peertube npm run plugin:install -- --npm-name peertube-plugin-myplugin
9b474844
C
340```
341
342To uninstall a plugin or a theme:
343
c83af8f9 344```bash
00ee545c
C
345cd /var/www/peertube/peertube-latest
346sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run plugin:uninstall -- --npm-name peertube-plugin-myplugin
cb6a78c2 347
00ee545c
C
348# Docker installation
349cd /var/www/peertube-docker
350docker-compose exec -u peertube peertube npm run plugin:uninstall -- --npm-name peertube-plugin-myplugin
9b474844 351```
76ad705e
C
352
353## PeerTube runner
354
355PeerTube >= 5.2 supports VOD or Live transcoding by a remote PeerTube runner.
356
357
358### Installation
359
360```bash
361sudo npm install -g @peertube/peertube-runner
362```
363
364### Configuration
365
366The runner uses env paths like `~/.config`, `~/.cache` and `~/.local/share` directories to store runner configuration or temporary files.
367
368Multiple PeerTube runners can run on the same OS by using the `--id` CLI option (each runner uses its own config/tmp directories):
369
370```bash
371peertube-runner [commands] --id instance-1
372peertube-runner [commands] --id instance-2
373peertube-runner [commands] --id instance-3
374```
375
ca91a74b 376You can change the runner configuration (jobs concurrency, ffmpeg threads/nice etc) by editing `~/.config/peertube-runner-nodejs/[id]/config.toml`.
76ad705e
C
377
378### Run the server
379
0d6a8289 380You need to run the runner in server mode first so it can run transcoding jobs of registered PeerTube instances:
76ad705e
C
381
382```bash
383peertube-runner server
384```
385
386### Register
387
0d6a8289 388Then, you can register the runner on a new PeerTube instance so the runner can process its transcoding job:
76ad705e
C
389
390```bash
391peertube-runner register --url http://peertube.example.com --registration-token ptrrt-... --runner-name my-runner-name
392```
393
394The runner will then use a websocket connection with the PeerTube instance to be notified about new available transcoding jobs.
395
396### Unregister
397
398To unregister a PeerTube instance:
399
400```bash
f474a519 401peertube-runner unregister --url http://peertube.example.com --runner-name my-runner-name
76ad705e
C
402```
403
404### List registered instances
405
406```bash
407peertube-runner list-registered
408```