2 UserRight, VideoChannel, VideoDetails as VideoDetailsServerModel, VideoFile, VideoPrivacy,
4 } from '../../../../../shared'
5 import { Account } from '../../../../../shared/models/actors'
6 import { AuthUser } from '../../core'
7 import { Video } from '../../shared/video/video.model'
9 export class VideoDetails extends Video implements VideoDetailsServerModel {
39 descriptionPath: string
46 dislikesPercent: number
47 commentsEnabled: boolean
49 constructor (hash: VideoDetailsServerModel) {
52 this.privacy = hash.privacy
53 this.privacyLabel = hash.privacyLabel
54 this.descriptionPath = hash.descriptionPath
55 this.files = hash.files
56 this.channel = hash.channel
57 this.account = hash.account
59 this.commentsEnabled = hash.commentsEnabled
61 this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100
62 this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100
65 getAppropriateMagnetUri (actualDownloadSpeed = 0) {
66 if (this.files === undefined || this.files.length === 0) return ''
67 if (this.files.length === 1) return this.files[0].magnetUri
69 // Find first video that is good for our download speed (remember they are sorted)
70 let betterResolutionFile = this.files.find(f => actualDownloadSpeed > (f.size / this.duration))
72 // If the download speed is too bad, return the lowest resolution we have
73 if (betterResolutionFile === undefined) {
74 betterResolutionFile = this.files.find(f => f.resolution === VideoResolution.H_240P)
77 return betterResolutionFile.magnetUri
80 isRemovableBy (user: AuthUser) {
81 return user && this.isLocal === true && (this.accountName === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
84 isBlackistableBy (user: AuthUser) {
85 return user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true && this.isLocal === false
88 isUpdatableBy (user: AuthUser) {
89 return user && this.isLocal === true && user.username === this.accountName