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, apiURL: string) {
39 const thisHost = new URL(apiURL).host
40 if (serverHost.trim() === thisHost)
42 return account + '@' + serverHost
45 private static createDurationString (duration: number) {
46 const minutes = Math.floor(duration / 60)
47 const seconds = duration % 60
48 const minutesPadding = minutes >= 10 ? '' : '0'
49 const secondsPadding = seconds >= 10 ? '' : '0'
51 return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
54 constructor (hash: VideoServerModel) {
55 const absoluteAPIUrl = getAbsoluteAPIUrl()
57 this.accountName = hash.accountName
58 this.createdAt = new Date(hash.createdAt.toString())
59 this.categoryLabel = hash.categoryLabel
60 this.category = hash.category
61 this.licenceLabel = hash.licenceLabel
62 this.licence = hash.licence
63 this.languageLabel = hash.languageLabel
64 this.language = hash.language
65 this.description = hash.description
66 this.duration = hash.duration
67 this.durationLabel = Video.createDurationString(hash.duration)
70 this.isLocal = hash.isLocal
72 this.serverHost = hash.serverHost
73 this.thumbnailPath = hash.thumbnailPath
74 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
75 this.previewPath = hash.previewPath
76 this.previewUrl = absoluteAPIUrl + hash.previewPath
77 this.embedPath = hash.embedPath
78 this.embedUrl = absoluteAPIUrl + hash.embedPath
79 this.views = hash.views
80 this.likes = hash.likes
81 this.dislikes = hash.dislikes
84 this.by = Video.createByString(hash.accountName, hash.serverHost, absoluteAPIUrl)
87 isVideoNSFWForUser (user: User) {
88 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
89 return (this.nsfw && (!user || user.displayNSFW === false))