1 import { Video } from './video.model'
3 VideoDetails as VideoDetailsServerModel,
7 } from '../../../../../shared'
9 export class VideoDetails extends Video implements VideoDetailsServerModel {
42 constructor (hash: VideoDetailsServerModel) {
45 this.files = hash.files
46 this.channel = hash.channel
49 getAppropriateMagnetUri (actualDownloadSpeed = 0) {
50 if (this.files === undefined || this.files.length === 0) return ''
51 if (this.files.length === 1) return this.files[0].magnetUri
53 // Find first video that is good for our download speed (remember they are sorted)
54 let betterResolutionFile = this.files.find(f => actualDownloadSpeed > (f.size / this.duration))
56 // If the download speed is too bad, return the lowest resolution we have
57 if (betterResolutionFile === undefined) {
58 betterResolutionFile = this.files.find(f => f.resolution === VideoResolution.H_240P)
61 return betterResolutionFile.magnetUri
64 isRemovableBy (user) {
65 return user && this.isLocal === true && (this.author === user.username || user.isAdmin() === true)
68 isBlackistableBy (user) {
69 return user && user.isAdmin() === true && this.isLocal === false
72 isUpdatableBy (user) {
73 return user && this.isLocal === true && user.username === this.author