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 hours = Math.floor(duration / 3600)
46 const minutes = Math.floor(duration % 3600 / 60)
47 const seconds = duration % 60
49 const minutesPadding = minutes >= 10 ? '' : '0'
50 const secondsPadding = seconds >= 10 ? '' : '0'
51 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
53 return displayedHours + minutesPadding +
54 minutes.toString() + ':' + secondsPadding + seconds.toString()
57 constructor (hash: VideoServerModel) {
58 const absoluteAPIUrl = getAbsoluteAPIUrl()
60 this.createdAt = new Date(hash.createdAt.toString())
61 this.categoryLabel = hash.categoryLabel
62 this.category = hash.category
63 this.licenceLabel = hash.licenceLabel
64 this.licence = hash.licence
65 this.languageLabel = hash.languageLabel
66 this.language = hash.language
67 this.description = hash.description
68 this.duration = hash.duration
69 this.durationLabel = Video.createDurationString(hash.duration)
72 this.isLocal = hash.isLocal
74 this.thumbnailPath = hash.thumbnailPath
75 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
76 this.previewPath = hash.previewPath
77 this.previewUrl = absoluteAPIUrl + hash.previewPath
78 this.embedPath = hash.embedPath
79 this.embedUrl = absoluteAPIUrl + hash.embedPath
80 this.views = hash.views
81 this.likes = hash.likes
82 this.dislikes = hash.dislikes
84 this.account = hash.account
86 this.by = Account.CREATE_BY_STRING(hash.account.name, hash.account.host)
89 isVideoNSFWForUser (user: User) {
90 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
91 return (this.nsfw && (!user || user.displayNSFW === false))