+#### Add external auth methods
+
+If you want to add a classic username/email and password auth method (like [LDAP](https://framagit.org/framasoft/peertube/official-plugins/-/tree/master/peertube-plugin-auth-ldap) for example):
+
+```js
+function register (...) {
+
+ registerIdAndPassAuth({
+ authName: 'my-auth-method',
+
+ // PeerTube will try all id and pass plugins in the weight DESC order
+ // Exposing this value in the plugin settings could be interesting
+ getWeight: () => 60,
+
+ // Optional function called by PeerTube when the user clicked on the logout button
+ onLogout: user => {
+ console.log('User %s logged out.', user.username')
+ },
+
+ // Optional function called by PeerTube when the access token or refresh token are generated/refreshed
+ hookTokenValidity: ({ token, type }) => {
+ if (type === 'access') return { valid: true }
+ if (type === 'refresh') return { valid: false }
+ },
+
+ // Used by PeerTube when the user tries to authenticate
+ login: ({ id, password }) => {
+ if (id === 'user' && password === 'super password') {
+ return {
+ username: 'user'
+ email: 'user@example.com'
+ role: 2
+ displayName: 'User display name'
+ }
+ }
+
+ // Auth failed
+ return null
+ }
+ })
+
+ // Unregister this auth method
+ unregisterIdAndPassAuth('my-auth-method')
+}
+```
+
+You can also add an external auth method (like [OpenID](https://framagit.org/framasoft/peertube/official-plugins/-/tree/master/peertube-plugin-auth-openid-connect), [SAML2](https://framagit.org/framasoft/peertube/official-plugins/-/tree/master/peertube-plugin-auth-saml2) etc):
+
+```js
+function register (...) {
+
+ // result contains the userAuthenticated auth method you can call to authenticate a user
+ const result = registerExternalAuth({
+ authName: 'my-auth-method',
+
+ // Will be displayed in a button next to the login form
+ authDisplayName: () => 'Auth method'
+
+ // If the user click on the auth button, PeerTube will forward the request in this function
+ onAuthRequest: (req, res) => {
+ res.redirect('https://external-auth.example.com/auth')
+ },
+
+ // Same than registerIdAndPassAuth option
+ // onLogout: ...
+
+ // Same than registerIdAndPassAuth option
+ // hookTokenValidity: ...
+ })
+
+ router.use('/external-auth-callback', (req, res) => {
+ // Forward the request to PeerTube
+ result.userAuthenticated({
+ req,
+ res,
+ username: 'user'
+ email: 'user@example.com'
+ role: 2
+ displayName: 'User display name'
+ })
+ })
+
+ // Unregister this external auth method
+ unregisterExternalAuth('my-auth-method)
+}
+```
+
+#### Add new transcoding profiles
+
+Adding transcoding profiles allow admins to change ffmpeg encoding parameters and/or encoders.
+A transcoding profile has to be chosen by the admin of the instance using the admin configuration.
+
+```js
+async function register ({
+ transcodingManager
+}) {
+
+ // Adapt bitrate when using libx264 encoder
+ {
+ const builder = (options) => {
+ const { input, resolution, fps, streamNum } = options
+
+ const streamString = streamNum ? ':' + streamNum : ''
+
+ // You can also return a promise
+ // All these options are optional
+ return {
+ scaleFilter: {
+ // Used to define an alternative scale filter, needed by some encoders
+ // Default to 'scale'
+ name: 'scale_vaapi'
+ },
+ // Default to []
+ inputOptions: [],
+ // Default to []
+ outputOptions: [
+ // Use a custom bitrate
+ '-b' + streamString + ' 10K'
+ ]
+ }
+ }
+
+ const encoder = 'libx264'
+ const profileName = 'low-quality'
+
+ // Support this profile for VOD transcoding
+ transcodingManager.addVODProfile(encoder, profileName, builder)
+
+ // And/Or support this profile for live transcoding
+ transcodingManager.addLiveProfile(encoder, profileName, builder)
+ }
+
+ {
+ const builder = (options) => {
+ const { streamNum } = options
+
+ const streamString = streamNum ? ':' + streamNum : ''
+
+ // Always copy stream when PeerTube use libfdk_aac or aac encoders
+ return {
+ copy: true
+ }
+ }
+
+ const profileName = 'copy-audio'
+
+ for (const encoder of [ 'libfdk_aac', 'aac' ]) {
+ transcodingManager.addVODProfile(encoder, profileName, builder)
+ }
+ }
+```
+
+PeerTube will try different encoders depending on their priority.
+If the encoder is not available in the current transcoding profile or in ffmpeg, it tries the next one.
+Plugins can change the order of these encoders and add their custom encoders:
+
+```js
+async function register ({
+ transcodingManager
+}) {
+
+ // Adapt bitrate when using libx264 encoder
+ {
+ const builder = () => {
+ return {
+ inputOptions: [],
+ outputOptions: []
+ }
+ }
+
+ // Support libopus and libvpx-vp9 encoders (these codecs could be incompatible with the player)
+ transcodingManager.addVODProfile('libopus', 'test-vod-profile', builder)
+
+ // Default priorities are ~100
+ // Lowest priority = 1
+ transcodingManager.addVODEncoderPriority('audio', 'libopus', 1000)
+
+ transcodingManager.addVODProfile('libvpx-vp9', 'test-vod-profile', builder)
+ transcodingManager.addVODEncoderPriority('video', 'libvpx-vp9', 1000)
+
+ transcodingManager.addLiveProfile('libopus', 'test-live-profile', builder)
+ transcodingManager.addLiveEncoderPriority('audio', 'libopus', 1000)
+ }
+```
+
+During live transcode input options are applied once for each target resolution.
+Plugins are responsible for detecting such situation and applying input options only once if necessary.
+
+#### Server helpers
+
+PeerTube provides your plugin some helpers. For example:
+
+```js
+async function register ({
+ peertubeHelpers
+}) {
+ // Block a server
+ {
+ const serverActor = await peertubeHelpers.server.getServerActor()
+
+ await peertubeHelpers.moderation.blockServer({ byAccountId: serverActor.Account.id, hostToBlock: '...' })
+ }
+
+ // Load a video
+ {
+ const video = await peertubeHelpers.videos.loadByUrl('...')
+ }
+}
+```
+
+See the [plugin API reference](https://docs.joinpeertube.org/api-plugins) to see the complete helpers list.
+
+### Client API (themes & plugins)