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