1 import { User } from '../'
2 import { Video as VideoServerModel } from '../../../../../shared'
3 import { Account } from '../../../../../shared/models/actors'
4 import { environment } from '../../../environments/environment'
5 import { getAbsoluteAPIUrl } from '../misc/utils'
7 export class Video implements VideoServerModel {
38 private static createByString (account: string, serverHost: string) {
39 return account + '@' + serverHost
42 private static createDurationString (duration: number) {
43 const minutes = Math.floor(duration / 60)
44 const seconds = duration % 60
45 const minutesPadding = minutes >= 10 ? '' : '0'
46 const secondsPadding = seconds >= 10 ? '' : '0'
48 return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
51 constructor (hash: VideoServerModel) {
52 const absoluteAPIUrl = getAbsoluteAPIUrl()
54 this.accountName = hash.accountName
55 this.createdAt = new Date(hash.createdAt.toString())
56 this.categoryLabel = hash.categoryLabel
57 this.category = hash.category
58 this.licenceLabel = hash.licenceLabel
59 this.licence = hash.licence
60 this.languageLabel = hash.languageLabel
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.serverHost = hash.serverHost
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
81 this.by = Video.createByString(hash.accountName, hash.serverHost)
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))