]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/video/video.model.ts
Live streaming implementation first step
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / video / video.model.ts
CommitLineData
3a0fb65c 1import { AuthUser } from '@app/core'
67ed6552 2import { User } from '@app/core/users/user.model'
72493e44 3import { durationToString, getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers'
bd45d503 4import { peertubeTranslate } from '@shared/core-utils/i18n'
67ed6552
C
5import {
6 Avatar,
67ed6552
C
7 ServerConfig,
8 UserRight,
9 Video as VideoServerModel,
10 VideoConstant,
11 VideoPrivacy,
12 VideoScheduleUpdate,
13 VideoState
14} from '@shared/models'
67ed6552 15import { Actor } from '../account/actor.model'
92fb909c 16
69f616ab 17export class Video implements VideoServerModel {
22a16e36
C
18 byVideoChannel: string
19 byAccount: string
20
d3e91a5f 21 accountAvatarUrl: string
52d9f792 22 videoChannelAvatarUrl: string
22a16e36 23
df98563e 24 createdAt: Date
6d33593a 25 updatedAt: Date
2922e048 26 publishedAt: Date
c8034165 27 originallyPublishedAt: Date | string
09700934
C
28 category: VideoConstant<number>
29 licence: VideoConstant<number>
9d3ef9fe 30 language: VideoConstant<string>
2243730c 31 privacy: VideoConstant<VideoPrivacy>
df98563e
C
32 description: string
33 duration: number
34 durationLabel: string
0a6658fd
C
35 id: number
36 uuid: string
df98563e 37 isLocal: boolean
df98563e 38 name: string
60862425 39 serverHost: string
df98563e
C
40 thumbnailPath: string
41 thumbnailUrl: string
5fb2e288 42
c6c0fa6c
C
43 isLive: boolean
44
43f61d26
C
45 previewPath: string
46 previewUrl: string
5fb2e288 47
d8755eed
C
48 embedPath: string
49 embedUrl: string
5fb2e288
C
50
51 url?: string
52
df98563e
C
53 views: number
54 likes: number
55 dislikes: number
56 nsfw: boolean
b64c950a 57
c910f667
C
58 originInstanceUrl: string
59 originInstanceHost: string
60
2186386c
C
61 waitTranscoding?: boolean
62 state?: VideoConstant<VideoState>
bbe0f064 63 scheduledUpdate?: VideoScheduleUpdate
191764f3 64 blacklisted?: boolean
5baee5fc 65 blockedReason?: string
2186386c 66
b64c950a 67 account: {
03e12d7c 68 id: number
b64c950a
C
69 name: string
70 displayName: string
71 url: string
0f320037 72 host: string
457bb213 73 avatar?: Avatar
0f320037
C
74 }
75
76 channel: {
77 id: number
0f320037
C
78 name: string
79 displayName: string
80 url: string
b64c950a 81 host: string
457bb213 82 avatar?: Avatar
b64c950a 83 }
aff038cd 84
6e46de09
C
85 userHistory?: {
86 currentTime: number
87 }
88
7294aab0
C
89 pluginData?: any
90
191764f3
C
91 static buildClientUrl (videoUUID: string) {
92 return '/videos/watch/' + videoUUID
93 }
94
7ce44a74 95 constructor (hash: VideoServerModel, translations = {}) {
c5911fd3 96 const absoluteAPIUrl = getAbsoluteAPIUrl()
c6e0bfbf 97
d592e0a9 98 this.createdAt = new Date(hash.createdAt.toString())
2922e048 99 this.publishedAt = new Date(hash.publishedAt.toString())
df98563e 100 this.category = hash.category
df98563e 101 this.licence = hash.licence
df98563e 102 this.language = hash.language
2243730c 103 this.privacy = hash.privacy
2186386c
C
104 this.waitTranscoding = hash.waitTranscoding
105 this.state = hash.state
df98563e 106 this.description = hash.description
c910f667 107
c6c0fa6c
C
108 this.isLive = hash.isLive
109
df98563e 110 this.duration = hash.duration
11b8762f 111 this.durationLabel = durationToString(hash.duration)
c910f667 112
df98563e 113 this.id = hash.id
0a6658fd 114 this.uuid = hash.uuid
c910f667 115
df98563e 116 this.isLocal = hash.isLocal
df98563e 117 this.name = hash.name
c910f667 118
df98563e 119 this.thumbnailPath = hash.thumbnailPath
c6c0fa6c
C
120 this.thumbnailUrl = this.thumbnailPath
121 ? hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath)
122 : null
c910f667 123
43f61d26 124 this.previewPath = hash.previewPath
c6c0fa6c
C
125 this.previewUrl = this.previewPath
126 ? hash.previewUrl || (absoluteAPIUrl + hash.previewPath)
127 : null
c910f667 128
d8755eed 129 this.embedPath = hash.embedPath
72493e44 130 this.embedUrl = hash.embedUrl || (getAbsoluteEmbedUrl() + hash.embedPath)
5fb2e288
C
131
132 this.url = hash.url
c910f667 133
df98563e
C
134 this.views = hash.views
135 this.likes = hash.likes
136 this.dislikes = hash.dislikes
c910f667 137
df98563e 138 this.nsfw = hash.nsfw
c910f667 139
b64c950a 140 this.account = hash.account
52d9f792 141 this.channel = hash.channel
4fd8aa32 142
22a16e36
C
143 this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
144 this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host)
d3e91a5f 145 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
52d9f792 146 this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel)
7ce44a74
C
147
148 this.category.label = peertubeTranslate(this.category.label, translations)
149 this.licence.label = peertubeTranslate(this.licence.label, translations)
150 this.language.label = peertubeTranslate(this.language.label, translations)
151 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
2186386c 152
bbe0f064 153 this.scheduledUpdate = hash.scheduledUpdate
830b4faf
C
154 this.originallyPublishedAt = hash.originallyPublishedAt ? new Date(hash.originallyPublishedAt.toString()) : null
155
2186386c 156 if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
191764f3
C
157
158 this.blacklisted = hash.blacklisted
5baee5fc 159 this.blockedReason = hash.blacklistedReason
6e46de09
C
160
161 this.userHistory = hash.userHistory
c910f667
C
162
163 this.originInstanceHost = this.account.host
164 this.originInstanceUrl = 'https://' + this.originInstanceHost
7294aab0
C
165
166 this.pluginData = hash.pluginData
501bc6c2
C
167 }
168
0883b324
C
169 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
170 // Video is not NSFW, skip
171 if (this.nsfw === false) return false
172
173 // Return user setting if logged in
174 if (user) return user.nsfwPolicy !== 'display'
175
176 // Return default instance config
177 return serverConfig.instance.defaultNSFWPolicy !== 'display'
92fb909c 178 }
3a0fb65c
C
179
180 isRemovableBy (user: AuthUser) {
181 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
182 }
183
5baee5fc 184 isBlockableBy (user: AuthUser) {
3487330d 185 return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
3a0fb65c
C
186 }
187
5baee5fc 188 isUnblockableBy (user: AuthUser) {
3487330d 189 return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
3a0fb65c
C
190 }
191
192 isUpdatableBy (user: AuthUser) {
193 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
194 }
b764380a
C
195
196 canBeDuplicatedBy (user: AuthUser) {
197 return user && this.isLocal === false && user.hasRight(UserRight.MANAGE_VIDEOS_REDUNDANCIES)
198 }
501bc6c2 199}