1 import { User } from '../'
2 import { Video as VideoServerModel, VideoPrivacy } 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'
10 export class Video implements VideoServerModel {
12 accountAvatarUrl: string
16 category: VideoConstant<number>
17 licence: VideoConstant<number>
18 language: VideoConstant<string>
19 privacy: VideoConstant<VideoPrivacy>
59 private static createDurationString (duration: number) {
60 const hours = Math.floor(duration / 3600)
61 const minutes = Math.floor(duration % 3600 / 60)
62 const seconds = duration % 60
64 const minutesPadding = minutes >= 10 ? '' : '0'
65 const secondsPadding = seconds >= 10 ? '' : '0'
66 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
68 return displayedHours + minutesPadding +
69 minutes.toString() + ':' + secondsPadding + seconds.toString()
72 constructor (hash: VideoServerModel, translations = {}) {
73 const absoluteAPIUrl = getAbsoluteAPIUrl()
75 this.createdAt = new Date(hash.createdAt.toString())
76 this.publishedAt = new Date(hash.publishedAt.toString())
77 this.category = hash.category
78 this.licence = hash.licence
79 this.language = hash.language
80 this.privacy = hash.privacy
81 this.description = hash.description
82 this.duration = hash.duration
83 this.durationLabel = Video.createDurationString(hash.duration)
86 this.isLocal = hash.isLocal
88 this.thumbnailPath = hash.thumbnailPath
89 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
90 this.previewPath = hash.previewPath
91 this.previewUrl = absoluteAPIUrl + hash.previewPath
92 this.embedPath = hash.embedPath
93 this.embedUrl = absoluteAPIUrl + hash.embedPath
94 this.views = hash.views
95 this.likes = hash.likes
96 this.dislikes = hash.dislikes
98 this.account = hash.account
100 this.by = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
101 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
103 this.category.label = peertubeTranslate(this.category.label, translations)
104 this.licence.label = peertubeTranslate(this.licence.label, translations)
105 this.language.label = peertubeTranslate(this.language.label, translations)
106 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
109 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
110 // Video is not NSFW, skip
111 if (this.nsfw === false) return false
113 // Return user setting if logged in
114 if (user) return user.nsfwPolicy !== 'display'
116 // Return default instance config
117 return serverConfig.instance.defaultNSFWPolicy !== 'display'