]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/shared/video-details.model.ts
Change video spinner
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / shared / video-details.model.ts
1 import { Video } from './video.model'
2 import { AuthUser } from '../../core'
3 import {
4 VideoDetails as VideoDetailsServerModel,
5 VideoFile,
6 VideoChannel,
7 VideoResolution,
8 UserRight
9 } from '../../../../../shared'
10
11 export class VideoDetails extends Video implements VideoDetailsServerModel {
12 author: string
13 by: string
14 createdAt: Date
15 updatedAt: Date
16 categoryLabel: string
17 category: number
18 licenceLabel: string
19 licence: number
20 languageLabel: string
21 language: number
22 description: string
23 duration: number
24 durationLabel: string
25 id: number
26 uuid: string
27 isLocal: boolean
28 name: string
29 podHost: string
30 tags: string[]
31 thumbnailPath: string
32 thumbnailUrl: string
33 previewPath: string
34 previewUrl: string
35 embedPath: string
36 embedUrl: string
37 views: number
38 likes: number
39 dislikes: number
40 nsfw: boolean
41 descriptionPath: string
42 files: VideoFile[]
43 channel: VideoChannel
44
45 constructor (hash: VideoDetailsServerModel) {
46 super(hash)
47
48 this.descriptionPath = hash.descriptionPath
49 this.files = hash.files
50 this.channel = hash.channel
51 }
52
53 getAppropriateMagnetUri (actualDownloadSpeed = 0) {
54 if (this.files === undefined || this.files.length === 0) return ''
55 if (this.files.length === 1) return this.files[0].magnetUri
56
57 // Find first video that is good for our download speed (remember they are sorted)
58 let betterResolutionFile = this.files.find(f => actualDownloadSpeed > (f.size / this.duration))
59
60 // If the download speed is too bad, return the lowest resolution we have
61 if (betterResolutionFile === undefined) {
62 betterResolutionFile = this.files.find(f => f.resolution === VideoResolution.H_240P)
63 }
64
65 return betterResolutionFile.magnetUri
66 }
67
68 isRemovableBy (user: AuthUser) {
69 return user && this.isLocal === true && (this.author === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
70 }
71
72 isBlackistableBy (user: AuthUser) {
73 return user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true && this.isLocal === false
74 }
75
76 isUpdatableBy (user: AuthUser) {
77 return user && this.isLocal === true && user.username === this.author
78 }
79 }