]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/shared/video-details.model.ts
Rename Pod -> Server
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / shared / video-details.model.ts
CommitLineData
404b54e1 1import { Video } from './video.model'
954605a8 2import { AuthUser } from '../../core'
404b54e1
C
3import {
4 VideoDetails as VideoDetailsServerModel,
5 VideoFile,
6 VideoChannel,
954605a8 7 VideoResolution,
fd45e8f4
C
8 UserRight,
9 VideoPrivacy
404b54e1
C
10} from '../../../../../shared'
11
12export class VideoDetails extends Video implements VideoDetailsServerModel {
1e1265b3 13 account: string
404b54e1
C
14 by: string
15 createdAt: Date
16 updatedAt: Date
17 categoryLabel: string
18 category: number
19 licenceLabel: string
20 licence: number
21 languageLabel: string
22 language: number
23 description: string
24 duration: number
25 durationLabel: string
26 id: number
27 uuid: string
28 isLocal: boolean
29 name: string
60862425 30 serverHost: string
404b54e1
C
31 tags: string[]
32 thumbnailPath: string
33 thumbnailUrl: string
34 previewPath: string
35 previewUrl: string
36 embedPath: string
37 embedUrl: string
38 views: number
39 likes: number
40 dislikes: number
41 nsfw: boolean
2de96f4d 42 descriptionPath: string
404b54e1
C
43 files: VideoFile[]
44 channel: VideoChannel
fd45e8f4
C
45 privacy: VideoPrivacy
46 privacyLabel: string
404b54e1
C
47
48 constructor (hash: VideoDetailsServerModel) {
49 super(hash)
50
fd45e8f4
C
51 this.privacy = hash.privacy
52 this.privacyLabel = hash.privacyLabel
2de96f4d 53 this.descriptionPath = hash.descriptionPath
404b54e1
C
54 this.files = hash.files
55 this.channel = hash.channel
56 }
57
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
61
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))
64
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)
68 }
69
70 return betterResolutionFile.magnetUri
71 }
72
954605a8 73 isRemovableBy (user: AuthUser) {
1e1265b3 74 return user && this.isLocal === true && (this.account === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
404b54e1
C
75 }
76
954605a8
C
77 isBlackistableBy (user: AuthUser) {
78 return user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true && this.isLocal === false
404b54e1
C
79 }
80
954605a8 81 isUpdatableBy (user: AuthUser) {
1e1265b3 82 return user && this.isLocal === true && user.username === this.account
404b54e1
C
83 }
84}