1 import { User } from '../'
2 import { Video as VideoServerModel, VideoPrivacy, VideoState } from '../../../../../shared'
3 import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
4 import { VideoConstant } from '../../../../../shared/models/videos/video-constant.model'
5 import { getAbsoluteAPIUrl } from '../misc/utils'
6 import { ServerConfig } from '../../../../../shared/models'
7 import { Actor } from '@app/shared/actor/actor.model'
8 import { peertubeTranslate } from '@app/shared/i18n/i18n-utils'
9 import { VideoScheduleUpdate } from '../../../../../shared/models/videos/video-schedule-update.model'
11 export class Video implements VideoServerModel {
13 accountAvatarUrl: string
14 videoChannelAvatarUrl: string
18 category: VideoConstant<number>
19 licence: VideoConstant<number>
20 language: VideoConstant<string>
21 privacy: VideoConstant<VideoPrivacy>
41 waitTranscoding?: boolean
42 state?: VideoConstant<VideoState>
43 scheduledUpdate?: VideoScheduleUpdate
45 blacklistedReason?: string
67 static buildClientUrl (videoUUID: string) {
68 return '/videos/watch/' + videoUUID
71 private static createDurationString (duration: number) {
72 const hours = Math.floor(duration / 3600)
73 const minutes = Math.floor((duration % 3600) / 60)
74 const seconds = duration % 60
76 const minutesPadding = minutes >= 10 ? '' : '0'
77 const secondsPadding = seconds >= 10 ? '' : '0'
78 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
80 return displayedHours + minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
83 constructor (hash: VideoServerModel, translations = {}) {
84 const absoluteAPIUrl = getAbsoluteAPIUrl()
86 this.createdAt = new Date(hash.createdAt.toString())
87 this.publishedAt = new Date(hash.publishedAt.toString())
88 this.category = hash.category
89 this.licence = hash.licence
90 this.language = hash.language
91 this.privacy = hash.privacy
92 this.waitTranscoding = hash.waitTranscoding
93 this.state = hash.state
94 this.description = hash.description
95 this.duration = hash.duration
96 this.durationLabel = Video.createDurationString(hash.duration)
99 this.isLocal = hash.isLocal
100 this.name = hash.name
101 this.thumbnailPath = hash.thumbnailPath
102 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
103 this.previewPath = hash.previewPath
104 this.previewUrl = absoluteAPIUrl + hash.previewPath
105 this.embedPath = hash.embedPath
106 this.embedUrl = absoluteAPIUrl + hash.embedPath
107 this.views = hash.views
108 this.likes = hash.likes
109 this.dislikes = hash.dislikes
110 this.nsfw = hash.nsfw
111 this.account = hash.account
112 this.channel = hash.channel
114 this.by = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
115 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
116 this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel)
118 this.category.label = peertubeTranslate(this.category.label, translations)
119 this.licence.label = peertubeTranslate(this.licence.label, translations)
120 this.language.label = peertubeTranslate(this.language.label, translations)
121 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
123 this.scheduledUpdate = hash.scheduledUpdate
124 if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
126 this.blacklisted = hash.blacklisted
127 this.blacklistedReason = hash.blacklistedReason
130 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
131 // Video is not NSFW, skip
132 if (this.nsfw === false) return false
134 // Return user setting if logged in
135 if (user) return user.nsfwPolicy !== 'display'
137 // Return default instance config
138 return serverConfig.instance.defaultNSFWPolicy !== 'display'