1 import { Account } from '../../../../../shared/models/accounts'
2 import { Video } from '../../shared/video/video.model'
3 import { AuthUser } from '../../core'
5 VideoDetails as VideoDetailsServerModel,
11 } from '../../../../../shared'
13 export class VideoDetails extends Video implements VideoDetailsServerModel {
43 descriptionPath: string
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
61 getAppropriateMagnetUri (actualDownloadSpeed = 0) {
62 if (this.files === undefined || this.files.length === 0) return ''
63 if (this.files.length === 1) return this.files[0].magnetUri
65 // Find first video that is good for our download speed (remember they are sorted)
66 let betterResolutionFile = this.files.find(f => actualDownloadSpeed > (f.size / this.duration))
68 // If the download speed is too bad, return the lowest resolution we have
69 if (betterResolutionFile === undefined) {
70 betterResolutionFile = this.files.find(f => f.resolution === VideoResolution.H_240P)
73 return betterResolutionFile.magnetUri
76 isRemovableBy (user: AuthUser) {
77 return user && this.isLocal === true && (this.accountName === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
80 isBlackistableBy (user: AuthUser) {
81 return user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true && this.isLocal === false
84 isUpdatableBy (user: AuthUser) {
85 return user && this.isLocal === true && user.username === this.accountName