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.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
17 category: VideoConstant<number>
18 licence: VideoConstant<number>
19 language: VideoConstant<string>
20 privacy: VideoConstant<VideoPrivacy>
40 waitTranscoding?: boolean
41 state?: VideoConstant<VideoState>
42 scheduledUpdate?: VideoScheduleUpdate
64 private static createDurationString (duration: number) {
65 const hours = Math.floor(duration / 3600)
66 const minutes = Math.floor((duration % 3600) / 60)
67 const seconds = duration % 60
69 const minutesPadding = minutes >= 10 ? '' : '0'
70 const secondsPadding = seconds >= 10 ? '' : '0'
71 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
73 return displayedHours + minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
76 constructor (hash: VideoServerModel, translations = {}) {
77 const absoluteAPIUrl = getAbsoluteAPIUrl()
79 this.createdAt = new Date(hash.createdAt.toString())
80 this.publishedAt = new Date(hash.publishedAt.toString())
81 this.category = hash.category
82 this.licence = hash.licence
83 this.language = hash.language
84 this.privacy = hash.privacy
85 this.waitTranscoding = hash.waitTranscoding
86 this.state = hash.state
87 this.description = hash.description
88 this.duration = hash.duration
89 this.durationLabel = Video.createDurationString(hash.duration)
92 this.isLocal = hash.isLocal
94 this.thumbnailPath = hash.thumbnailPath
95 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
96 this.previewPath = hash.previewPath
97 this.previewUrl = absoluteAPIUrl + hash.previewPath
98 this.embedPath = hash.embedPath
99 this.embedUrl = absoluteAPIUrl + hash.embedPath
100 this.views = hash.views
101 this.likes = hash.likes
102 this.dislikes = hash.dislikes
103 this.nsfw = hash.nsfw
104 this.account = hash.account
106 this.by = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
107 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
109 this.category.label = peertubeTranslate(this.category.label, translations)
110 this.licence.label = peertubeTranslate(this.licence.label, translations)
111 this.language.label = peertubeTranslate(this.language.label, translations)
112 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
114 this.scheduledUpdate = hash.scheduledUpdate
115 if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
118 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
119 // Video is not NSFW, skip
120 if (this.nsfw === false) return false
122 // Return user setting if logged in
123 if (user) return user.nsfwPolicy !== 'display'
125 // Return default instance config
126 return serverConfig.instance.defaultNSFWPolicy !== 'display'