1 import { Video as VideoServerModel, VideoFile } from '../../../../../shared'
2 import { User } from '../../shared'
4 export class Video implements VideoServerModel {
34 private static createByString (author: string, podHost: string) {
35 return author + '@' + podHost
38 private static createDurationString (duration: number) {
39 const minutes = Math.floor(duration / 60)
40 const seconds = duration % 60
41 const minutesPadding = minutes >= 10 ? '' : '0'
42 const secondsPadding = seconds >= 10 ? '' : '0'
44 return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
50 categoryLabel: string,
64 thumbnailPath: string,
72 this.author = hash.author
73 this.createdAt = new Date(hash.createdAt)
74 this.categoryLabel = hash.categoryLabel
75 this.category = hash.category
76 this.licenceLabel = hash.licenceLabel
77 this.licence = hash.licence
78 this.languageLabel = hash.languageLabel
79 this.language = hash.language
80 this.description = hash.description
81 this.duration = hash.duration
82 this.durationLabel = Video.createDurationString(hash.duration)
85 this.isLocal = hash.isLocal
87 this.podHost = hash.podHost
89 this.thumbnailPath = hash.thumbnailPath
90 this.thumbnailUrl = API_URL + hash.thumbnailPath
91 this.previewPath = hash.previewPath
92 this.previewUrl = API_URL + hash.previewPath
93 this.views = hash.views
94 this.likes = hash.likes
95 this.dislikes = hash.dislikes
97 this.files = hash.files
99 this.by = Video.createByString(hash.author, hash.podHost)
102 isRemovableBy (user) {
103 return user && this.isLocal === true && (this.author === user.username || user.isAdmin() === true)
106 isBlackistableBy (user) {
107 return user && user.isAdmin() === true && this.isLocal === false
110 isUpdatableBy (user) {
111 return user && this.isLocal === true && user.username === this.author
114 isVideoNSFWForUser (user: User) {
115 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
116 return (this.nsfw && (!user || user.displayNSFW === false))
119 getDefaultMagnetUri () {
120 if (this.files === undefined || this.files.length === 0) return ''
122 // TODO: choose the original file
123 return this.files[0].magnetUri
126 patch (values: Object) {
127 Object.keys(values).forEach((key) => {
128 this[key] = values[key]
135 createdAt: this.createdAt,
136 category: this.category,
137 licence: this.licence,
138 language: this.language,
139 description: this.description,
140 duration: this.duration,
142 isLocal: this.isLocal,
144 podHost: this.podHost,
146 thumbnailPath: this.thumbnailPath,
149 dislikes: this.dislikes,