4 VideoDetails as VideoDetailsServerModel,
8 } from '../../../../../shared'
9 import { Account } from '../../../../../shared/models/actors'
10 import { VideoConstant } from '../../../../../shared/models/videos/video.model'
11 import { AuthUser } from '../../core'
12 import { Video } from '../../shared/video/video.model'
14 export class VideoDetails extends Video implements VideoDetailsServerModel {
15 privacy: VideoConstant<VideoPrivacy>
16 descriptionPath: string
22 commentsEnabled: boolean
25 dislikesPercent: number
27 constructor (hash: VideoDetailsServerModel) {
30 this.privacy = hash.privacy
31 this.descriptionPath = hash.descriptionPath
32 this.files = hash.files
33 this.channel = hash.channel
34 this.account = hash.account
36 this.support = hash.support
37 this.commentsEnabled = hash.commentsEnabled
39 this.buildLikeAndDislikePercents()
42 getAppropriateMagnetUri (actualDownloadSpeed = 0) {
43 if (this.files === undefined || this.files.length === 0) return ''
44 if (this.files.length === 1) return this.files[0].magnetUri
46 // Find first video that is good for our download speed (remember they are sorted)
47 let betterResolutionFile = this.files.find(f => actualDownloadSpeed > (f.size / this.duration))
49 // If the download speed is too bad, return the lowest resolution we have
50 if (betterResolutionFile === undefined) {
51 betterResolutionFile = this.files.find(f => f.resolution.id === VideoResolution.H_240P)
54 return betterResolutionFile.magnetUri
57 isRemovableBy (user: AuthUser) {
58 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
61 isBlackistableBy (user: AuthUser) {
62 return user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true && this.isLocal === false
65 isUpdatableBy (user: AuthUser) {
66 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
69 buildLikeAndDislikePercents () {
70 this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100
71 this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100