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 {
40 descriptionPath: string
47 dislikesPercent: number
48 commentsEnabled: boolean
50 constructor (hash: VideoDetailsServerModel) {
53 this.privacy = hash.privacy
54 this.privacyLabel = hash.privacyLabel
55 this.descriptionPath = hash.descriptionPath
56 this.files = hash.files
57 this.channel = hash.channel
58 this.account = hash.account
60 this.support = hash.support
61 this.commentsEnabled = hash.commentsEnabled
63 this.buildLikeAndDislikePercents()
66 getAppropriateMagnetUri (actualDownloadSpeed = 0) {
67 if (this.files === undefined || this.files.length === 0) return ''
68 if (this.files.length === 1) return this.files[0].magnetUri
70 // Find first video that is good for our download speed (remember they are sorted)
71 let betterResolutionFile = this.files.find(f => actualDownloadSpeed > (f.size / this.duration))
73 // If the download speed is too bad, return the lowest resolution we have
74 if (betterResolutionFile === undefined) {
75 betterResolutionFile = this.files.find(f => f.resolution === VideoResolution.H_240P)
78 return betterResolutionFile.magnetUri
81 isRemovableBy (user: AuthUser) {
82 return user && this.isLocal === true && (this.accountName === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
85 isBlackistableBy (user: AuthUser) {
86 return user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true && this.isLocal === false
89 isUpdatableBy (user: AuthUser) {
90 return user && this.isLocal === true && (this.accountName === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
93 buildLikeAndDislikePercents () {
94 this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100
95 this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100