1 import { Video as VideoServerModel } from '../../../../../shared';
2 import { User } from '../../shared';
4 export class Video implements VideoServerModel {
12 languageLabel: string;
16 durationLabel: string;
23 thumbnailPath: string;
29 private static createByString(author: string, podHost: string) {
30 return author + '@' + podHost;
33 private static createDurationString(duration: number) {
34 const minutes = Math.floor(duration / 60);
35 const seconds = duration % 60;
36 const minutes_padding = minutes >= 10 ? '' : '0';
37 const seconds_padding = seconds >= 10 ? '' : '0';
39 return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString();
45 categoryLabel: string,
49 languageLabel: string;
59 thumbnailPath: string,
65 this.author = hash.author;
66 this.createdAt = new Date(hash.createdAt);
67 this.categoryLabel = hash.categoryLabel;
68 this.category = hash.category;
69 this.licenceLabel = hash.licenceLabel;
70 this.licence = hash.licence;
71 this.languageLabel = hash.languageLabel;
72 this.language = hash.language;
73 this.description = hash.description;
74 this.duration = hash.duration;
75 this.durationLabel = Video.createDurationString(hash.duration);
77 this.isLocal = hash.isLocal;
78 this.magnetUri = hash.magnetUri;
79 this.name = hash.name;
80 this.podHost = hash.podHost;
81 this.tags = hash.tags;
82 this.thumbnailPath = hash.thumbnailPath;
83 this.views = hash.views;
84 this.likes = hash.likes;
85 this.dislikes = hash.dislikes;
86 this.nsfw = hash.nsfw;
88 this.by = Video.createByString(hash.author, hash.podHost);
92 return user && this.isLocal === true && (this.author === user.username || user.isAdmin() === true);
95 isBlackistableBy(user) {
96 return user && user.isAdmin() === true && this.isLocal === false;
100 return user && this.isLocal === true && user.username === this.author;
103 isVideoNSFWForUser(user: User) {
104 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
105 return (this.nsfw && (!user || user.displayNSFW === false));
108 patch(values: Object) {
109 Object.keys(values).forEach((key) => {
110 this[key] = values[key];
117 createdAt: this.createdAt,
118 category: this.category,
119 licence: this.licence,
120 language: this.language,
121 description: this.description,
122 duration: this.duration,
124 isLocal: this.isLocal,
125 magnetUri: this.magnetUri,
127 podHost: this.podHost,
129 thumbnailPath: this.thumbnailPath,
132 dislikes: this.dislikes,