Browse Source

Add ability for plugins to add metadata

tags/v5.1.0
Chocobozzz 3 weeks ago
parent
commit
4265d90b00
No known key found for this signature in database GPG Key ID: 583A612D890159BE
4 changed files with 48 additions and 2 deletions
  1. +7
    -0
      client/src/app/+videos/+video-watch/shared/metadata/video-attributes.component.html
  2. +30
    -2
      client/src/app/+videos/+video-watch/shared/metadata/video-attributes.component.ts
  3. +9
    -0
      client/src/app/core/plugins/hooks.service.ts
  4. +2
    -0
      shared/models/plugins/client/client-hook.model.ts

+ 7
- 0
client/src/app/+videos/+video-watch/shared/metadata/video-attributes.component.html View File

@@ -62,3 +62,10 @@
<span i18n class="attribute-label">Duration</span>
<span class="attribute-value">{{ video.duration | myDurationFormatter }}</span>
</div>

<div class="attribute attribute-plugin" *ngFor="let metadata of pluginMetadata">
<span class="attribute-label">{{ metadata.label }}</span>

<span *ngIf="metadata.value" class="attribute-value">{{ metadata.value }}</span>
<span *ngIf="metadata.safeHTML" class="attribute-value" [innerHTML]="metadata.safeHTML"></span>
</div>

+ 30
- 2
client/src/app/+videos/+video-watch/shared/metadata/video-attributes.component.ts View File

@@ -1,14 +1,35 @@
import { Component, Input } from '@angular/core'
import { Component, Input, OnInit } from '@angular/core'
import { HooksService } from '@app/core'
import { VideoDetails } from '@app/shared/shared-main'

type PluginMetadata = {
label: string

value?: string
safeHTML?: string
}

@Component({
selector: 'my-video-attributes',
templateUrl: './video-attributes.component.html',
styleUrls: [ './video-attributes.component.scss' ]
})
export class VideoAttributesComponent {
export class VideoAttributesComponent implements OnInit {
@Input() video: VideoDetails

pluginMetadata: PluginMetadata[] = []

constructor (private hooks: HooksService) { }

async ngOnInit () {
this.pluginMetadata = await this.hooks.wrapFunResult(
this.buildPluginMetadata.bind(this),
{ video: this.video },
'video-watch',
'filter:video-watch.video-plugin-metadata.result'
)
}

getVideoHost () {
return this.video.channel.host
}
@@ -18,4 +39,11 @@ export class VideoAttributesComponent {

return this.video.tags
}

// Used for plugin hooks
private buildPluginMetadata (_options: {
video: VideoDetails
}): PluginMetadata[] {
return []
}
}

+ 9
- 0
client/src/app/core/plugins/hooks.service.ts View File

@@ -48,6 +48,15 @@ export class HooksService {
return this.pluginService.runHook(hookResultName, result, params)
}

async wrapFunResult <P, R, H extends ClientFilterHookName>
(fun: RawFunction<P, R>, params: P, scope: PluginClientScope, hookResultName: H) {
await this.pluginService.ensurePluginsAreLoaded(scope)

const result = fun(params)

return this.pluginService.runHook(hookResultName, result, params)
}

runAction<T, U extends ClientActionHookName> (hookName: U, scope: PluginClientScope, params?: T) {
// Use setTimeout to give priority to Angular change detector
setTimeout(() => {


+ 2
- 0
shared/models/plugins/client/client-hook.model.ts View File

@@ -87,6 +87,8 @@ export const clientFilterHookObject = {
'filter:share.video-playlist-url.build.params': true,
'filter:share.video-playlist-url.build.result': true,

'filter:video-watch.video-plugin-metadata.result': true,

// Filter videojs options built for PeerTube player
'filter:internal.player.videojs.options.result': true,



Loading…
Cancel
Save