1 import { Video as VideoServerModel, VideoFile } from '../../../../../shared'
2 import { User } from '../../shared'
4 export class Video implements VideoServerModel {
33 private static createByString (author: string, podHost: string) {
34 return author + '@' + podHost
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()
49 categoryLabel: string,
63 thumbnailPath: string,
71 this.author = hash.author
72 this.createdAt = new Date(hash.createdAt)
73 this.categoryLabel = hash.categoryLabel
74 this.category = hash.category
75 this.licenceLabel = hash.licenceLabel
76 this.licence = hash.licence
77 this.languageLabel = hash.languageLabel
78 this.language = hash.language
79 this.description = hash.description
80 this.duration = hash.duration
81 this.durationLabel = Video.createDurationString(hash.duration)
84 this.isLocal = hash.isLocal
86 this.podHost = hash.podHost
88 this.thumbnailPath = hash.thumbnailPath
89 this.thumbnailUrl = API_URL + hash.thumbnailPath
90 this.previewPath = hash.previewPath
91 this.previewUrl = API_URL + hash.previewPath
92 this.views = hash.views
93 this.likes = hash.likes
94 this.dislikes = hash.dislikes
96 this.files = hash.files
98 this.by = Video.createByString(hash.author, hash.podHost)
101 isRemovableBy (user) {
102 return user && this.isLocal === true && (this.author === user.username || user.isAdmin() === true)
105 isBlackistableBy (user) {
106 return user && user.isAdmin() === true && this.isLocal === false
109 isUpdatableBy (user) {
110 return user && this.isLocal === true && user.username === this.author
113 isVideoNSFWForUser (user: User) {
114 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
115 return (this.nsfw && (!user || user.displayNSFW === false))
118 getDefaultMagnetUri () {
119 if (this.files === undefined || this.files.length === 0) return ''
121 // TODO: choose the original file
122 return this.files[0].magnetUri
125 patch (values: Object) {
126 Object.keys(values).forEach((key) => {
127 this[key] = values[key]
134 createdAt: this.createdAt,
135 category: this.category,
136 licence: this.licence,
137 language: this.language,
138 description: this.description,
139 duration: this.duration,
141 isLocal: this.isLocal,
143 podHost: this.podHost,
145 thumbnailPath: this.thumbnailPath,
148 dislikes: this.dislikes,