1 import { Account } from '@app/shared/account/account.model'
2 import { User } from '../'
3 import { Video as VideoServerModel } from '../../../../../shared'
4 import { getAbsoluteAPIUrl } from '../misc/utils'
6 export class Video implements VideoServerModel {
37 private static createDurationString (duration: number) {
38 const minutes = Math.floor(duration / 60)
39 const seconds = duration % 60
40 const minutesPadding = minutes >= 10 ? '' : '0'
41 const secondsPadding = seconds >= 10 ? '' : '0'
43 return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
46 constructor (hash: VideoServerModel) {
47 const absoluteAPIUrl = getAbsoluteAPIUrl()
49 this.accountName = hash.accountName
50 this.createdAt = new Date(hash.createdAt.toString())
51 this.categoryLabel = hash.categoryLabel
52 this.category = hash.category
53 this.licenceLabel = hash.licenceLabel
54 this.licence = hash.licence
55 this.languageLabel = hash.languageLabel
56 this.language = hash.language
57 this.description = hash.description
58 this.duration = hash.duration
59 this.durationLabel = Video.createDurationString(hash.duration)
62 this.isLocal = hash.isLocal
64 this.serverHost = hash.serverHost
65 this.thumbnailPath = hash.thumbnailPath
66 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
67 this.previewPath = hash.previewPath
68 this.previewUrl = absoluteAPIUrl + hash.previewPath
69 this.embedPath = hash.embedPath
70 this.embedUrl = absoluteAPIUrl + hash.embedPath
71 this.views = hash.views
72 this.likes = hash.likes
73 this.dislikes = hash.dislikes
76 this.by = Account.CREATE_BY_STRING(hash.accountName, hash.serverHost)
79 isVideoNSFWForUser (user: User) {
80 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
81 return (this.nsfw && (!user || user.displayNSFW === false))