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 {
12 category: VideoConstant<number>
13 licence: VideoConstant<number>
14 language: VideoConstant<number>
42 private static createDurationString (duration: number) {
43 const hours = Math.floor(duration / 3600)
44 const minutes = Math.floor(duration % 3600 / 60)
45 const seconds = duration % 60
47 const minutesPadding = minutes >= 10 ? '' : '0'
48 const secondsPadding = seconds >= 10 ? '' : '0'
49 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
51 return displayedHours + minutesPadding +
52 minutes.toString() + ':' + secondsPadding + seconds.toString()
55 constructor (hash: VideoServerModel) {
56 const absoluteAPIUrl = getAbsoluteAPIUrl()
58 this.createdAt = new Date(hash.createdAt.toString())
59 this.category = hash.category
60 this.licence = hash.licence
61 this.language = hash.language
62 this.description = hash.description
63 this.duration = hash.duration
64 this.durationLabel = Video.createDurationString(hash.duration)
67 this.isLocal = hash.isLocal
69 this.thumbnailPath = hash.thumbnailPath
70 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
71 this.previewPath = hash.previewPath
72 this.previewUrl = absoluteAPIUrl + hash.previewPath
73 this.embedPath = hash.embedPath
74 this.embedUrl = absoluteAPIUrl + hash.embedPath
75 this.views = hash.views
76 this.likes = hash.likes
77 this.dislikes = hash.dislikes
79 this.account = hash.account
81 this.by = Account.CREATE_BY_STRING(hash.account.name, hash.account.host)
84 isVideoNSFWForUser (user: User) {
85 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
86 return (this.nsfw && (!user || user.displayNSFW === false))