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