1 import { Account } from '@app/shared/account/account.model'
2 import { User } from '../'
3 import { Video as VideoServerModel } from '../../../../../shared'
4 import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
5 import { VideoConstant } from '../../../../../shared/models/videos/video.model'
6 import { getAbsoluteAPIUrl } from '../misc/utils'
8 export class Video implements VideoServerModel {
13 category: VideoConstant<number>
14 licence: VideoConstant<number>
15 language: VideoConstant<number>
43 private static createDurationString (duration: number) {
44 const hours = Math.floor(duration / 3600)
45 const minutes = Math.floor(duration % 3600 / 60)
46 const seconds = duration % 60
48 const minutesPadding = minutes >= 10 ? '' : '0'
49 const secondsPadding = seconds >= 10 ? '' : '0'
50 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
52 return displayedHours + minutesPadding +
53 minutes.toString() + ':' + secondsPadding + seconds.toString()
56 constructor (hash: VideoServerModel) {
57 const absoluteAPIUrl = getAbsoluteAPIUrl()
59 this.createdAt = new Date(hash.createdAt.toString())
60 this.publishedAt = new Date(hash.publishedAt.toString())
61 this.category = hash.category
62 this.licence = hash.licence
63 this.language = hash.language
64 this.description = hash.description
65 this.duration = hash.duration
66 this.durationLabel = Video.createDurationString(hash.duration)
69 this.isLocal = hash.isLocal
71 this.thumbnailPath = hash.thumbnailPath
72 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
73 this.previewPath = hash.previewPath
74 this.previewUrl = absoluteAPIUrl + hash.previewPath
75 this.embedPath = hash.embedPath
76 this.embedUrl = absoluteAPIUrl + hash.embedPath
77 this.views = hash.views
78 this.likes = hash.likes
79 this.dislikes = hash.dislikes
81 this.account = hash.account
83 this.by = Account.CREATE_BY_STRING(hash.account.name, hash.account.host)
86 isVideoNSFWForUser (user: User) {
87 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
88 return (this.nsfw && (!user || user.displayNSFW === false))