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 { peertubeTranslate, ServerConfig } from '../../../../../shared/models'
7 import { Actor } from '@app/shared/actor/actor.model'
8 import { VideoScheduleUpdate } from '../../../../../shared/models/videos/video-schedule-update.model'
10 export class Video implements VideoServerModel {
11 byVideoChannel: string
14 accountAvatarUrl: string
15 videoChannelAvatarUrl: string
20 category: VideoConstant<number>
21 licence: VideoConstant<number>
22 language: VideoConstant<string>
23 privacy: VideoConstant<VideoPrivacy>
43 waitTranscoding?: boolean
44 state?: VideoConstant<VideoState>
45 scheduledUpdate?: VideoScheduleUpdate
47 blacklistedReason?: string
69 static buildClientUrl (videoUUID: string) {
70 return '/videos/watch/' + videoUUID
73 private static createDurationString (duration: number) {
74 const hours = Math.floor(duration / 3600)
75 const minutes = Math.floor((duration % 3600) / 60)
76 const seconds = duration % 60
78 const minutesPadding = minutes >= 10 ? '' : '0'
79 const secondsPadding = seconds >= 10 ? '' : '0'
80 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
82 return displayedHours + minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
85 constructor (hash: VideoServerModel, translations = {}) {
86 const absoluteAPIUrl = getAbsoluteAPIUrl()
88 this.createdAt = new Date(hash.createdAt.toString())
89 this.publishedAt = new Date(hash.publishedAt.toString())
90 this.category = hash.category
91 this.licence = hash.licence
92 this.language = hash.language
93 this.privacy = hash.privacy
94 this.waitTranscoding = hash.waitTranscoding
95 this.state = hash.state
96 this.description = hash.description
97 this.duration = hash.duration
98 this.durationLabel = Video.createDurationString(hash.duration)
100 this.uuid = hash.uuid
101 this.isLocal = hash.isLocal
102 this.name = hash.name
103 this.thumbnailPath = hash.thumbnailPath
104 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
105 this.previewPath = hash.previewPath
106 this.previewUrl = absoluteAPIUrl + hash.previewPath
107 this.embedPath = hash.embedPath
108 this.embedUrl = absoluteAPIUrl + hash.embedPath
109 this.views = hash.views
110 this.likes = hash.likes
111 this.dislikes = hash.dislikes
112 this.nsfw = hash.nsfw
113 this.account = hash.account
114 this.channel = hash.channel
116 this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
117 this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host)
118 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
119 this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel)
121 this.category.label = peertubeTranslate(this.category.label, translations)
122 this.licence.label = peertubeTranslate(this.licence.label, translations)
123 this.language.label = peertubeTranslate(this.language.label, translations)
124 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
126 this.scheduledUpdate = hash.scheduledUpdate
127 if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
129 this.blacklisted = hash.blacklisted
130 this.blacklistedReason = hash.blacklistedReason
133 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
134 // Video is not NSFW, skip
135 if (this.nsfw === false) return false
137 // Return user setting if logged in
138 if (user) return user.nsfwPolicy !== 'display'
140 // Return default instance config
141 return serverConfig.instance.defaultNSFWPolicy !== 'display'