1 import { UserRight, VideoConstant, VideoDetails as VideoDetailsServerModel, VideoFile, VideoState } from '../../../../../shared'
2 import { AuthUser } from '../../core'
3 import { Video } from '../../shared/video/video.model'
4 import { Account } from '@app/shared/account/account.model'
5 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
6 import { VideoStreamingPlaylist } from '../../../../../shared/models/videos/video-streaming-playlist.model'
7 import { VideoStreamingPlaylistType } from '../../../../../shared/models/videos/video-streaming-playlist.type'
9 export class VideoDetails extends Video implements VideoDetailsServerModel {
10 descriptionPath: string
16 commentsEnabled: boolean
18 waitTranscoding: boolean
19 state: VideoConstant<VideoState>
22 dislikesPercent: number
26 streamingPlaylists: VideoStreamingPlaylist[]
28 constructor (hash: VideoDetailsServerModel, translations = {}) {
29 super(hash, translations)
31 this.descriptionPath = hash.descriptionPath
32 this.files = hash.files
33 this.channel = new VideoChannel(hash.channel)
34 this.account = new Account(hash.account)
36 this.support = hash.support
37 this.commentsEnabled = hash.commentsEnabled
39 this.trackerUrls = hash.trackerUrls
40 this.streamingPlaylists = hash.streamingPlaylists
42 this.buildLikeAndDislikePercents()
45 isRemovableBy (user: AuthUser) {
46 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
49 isBlackistableBy (user: AuthUser) {
50 return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
53 isUnblacklistableBy (user: AuthUser) {
54 return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
57 isUpdatableBy (user: AuthUser) {
58 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
61 buildLikeAndDislikePercents () {
62 this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100
63 this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100
67 return this.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)