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 { getAbsoluteAPIUrl } from '../misc/utils'
7 export class Video implements VideoServerModel {
44 private static createDurationString (duration: number) {
45 const minutes = Math.floor(duration / 60)
46 const seconds = duration % 60
47 const minutesPadding = minutes >= 10 ? '' : '0'
48 const secondsPadding = seconds >= 10 ? '' : '0'
50 return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
53 constructor (hash: VideoServerModel) {
54 const absoluteAPIUrl = getAbsoluteAPIUrl()
56 this.createdAt = new Date(hash.createdAt.toString())
57 this.categoryLabel = hash.categoryLabel
58 this.category = hash.category
59 this.licenceLabel = hash.licenceLabel
60 this.licence = hash.licence
61 this.languageLabel = hash.languageLabel
62 this.language = hash.language
63 this.description = hash.description
64 this.duration = hash.duration
65 this.durationLabel = Video.createDurationString(hash.duration)
68 this.isLocal = hash.isLocal
70 this.thumbnailPath = hash.thumbnailPath
71 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
72 this.previewPath = hash.previewPath
73 this.previewUrl = absoluteAPIUrl + hash.previewPath
74 this.embedPath = hash.embedPath
75 this.embedUrl = absoluteAPIUrl + hash.embedPath
76 this.views = hash.views
77 this.likes = hash.likes
78 this.dislikes = hash.dislikes
80 this.account = hash.account
82 this.by = Account.CREATE_BY_STRING(hash.account.name, hash.account.host)
85 isVideoNSFWForUser (user: User) {
86 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
87 return (this.nsfw && (!user || user.displayNSFW === false))