1 import { User } from '../'
2 import { PlaylistElement, 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 { durationToString, 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 originallyPublishedAt: Date | string
21 category: VideoConstant<number>
22 licence: VideoConstant<number>
23 language: VideoConstant<string>
24 privacy: VideoConstant<VideoPrivacy>
44 waitTranscoding?: boolean
45 state?: VideoConstant<VideoState>
46 scheduledUpdate?: VideoScheduleUpdate
48 blacklistedReason?: string
50 playlistElement?: PlaylistElement
76 static buildClientUrl (videoUUID: string) {
77 return '/videos/watch/' + videoUUID
80 constructor (hash: VideoServerModel, translations = {}) {
81 const absoluteAPIUrl = getAbsoluteAPIUrl()
83 this.createdAt = new Date(hash.createdAt.toString())
84 this.publishedAt = new Date(hash.publishedAt.toString())
85 this.category = hash.category
86 this.licence = hash.licence
87 this.language = hash.language
88 this.privacy = hash.privacy
89 this.waitTranscoding = hash.waitTranscoding
90 this.state = hash.state
91 this.description = hash.description
92 this.duration = hash.duration
93 this.durationLabel = durationToString(hash.duration)
96 this.isLocal = hash.isLocal
98 this.thumbnailPath = hash.thumbnailPath
99 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
100 this.previewPath = hash.previewPath
101 this.previewUrl = absoluteAPIUrl + hash.previewPath
102 this.embedPath = hash.embedPath
103 this.embedUrl = absoluteAPIUrl + hash.embedPath
104 this.views = hash.views
105 this.likes = hash.likes
106 this.dislikes = hash.dislikes
107 this.nsfw = hash.nsfw
108 this.account = hash.account
109 this.channel = hash.channel
111 this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
112 this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host)
113 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
114 this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel)
116 this.category.label = peertubeTranslate(this.category.label, translations)
117 this.licence.label = peertubeTranslate(this.licence.label, translations)
118 this.language.label = peertubeTranslate(this.language.label, translations)
119 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
121 this.scheduledUpdate = hash.scheduledUpdate
122 this.originallyPublishedAt = hash.originallyPublishedAt ? new Date(hash.originallyPublishedAt.toString()) : null
124 if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
126 this.blacklisted = hash.blacklisted
127 this.blacklistedReason = hash.blacklistedReason
129 this.userHistory = hash.userHistory
131 this.playlistElement = hash.playlistElement
134 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
135 // Video is not NSFW, skip
136 if (this.nsfw === false) return false
138 // Return user setting if logged in
139 if (user) return user.nsfwPolicy !== 'display'
141 // Return default instance config
142 return serverConfig.instance.defaultNSFWPolicy !== 'display'