1 import { Video } from './video.model'
2 import { AuthUser } from '../../core'
4 VideoDetails as VideoDetailsServerModel,
10 } from '../../../../../shared'
12 export class VideoDetails extends Video implements VideoDetailsServerModel {
42 descriptionPath: string
48 constructor (hash: VideoDetailsServerModel) {
51 this.privacy = hash.privacy
52 this.privacyLabel = hash.privacyLabel
53 this.descriptionPath = hash.descriptionPath
54 this.files = hash.files
55 this.channel = hash.channel
58 getAppropriateMagnetUri (actualDownloadSpeed = 0) {
59 if (this.files === undefined || this.files.length === 0) return ''
60 if (this.files.length === 1) return this.files[0].magnetUri
62 // Find first video that is good for our download speed (remember they are sorted)
63 let betterResolutionFile = this.files.find(f => actualDownloadSpeed > (f.size / this.duration))
65 // If the download speed is too bad, return the lowest resolution we have
66 if (betterResolutionFile === undefined) {
67 betterResolutionFile = this.files.find(f => f.resolution === VideoResolution.H_240P)
70 return betterResolutionFile.magnetUri
73 isRemovableBy (user: AuthUser) {
74 return user && this.isLocal === true && (this.author === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
77 isBlackistableBy (user: AuthUser) {
78 return user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true && this.isLocal === false
81 isUpdatableBy (user: AuthUser) {
82 return user && this.isLocal === true && user.username === this.author