]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/video/video.model.ts
Playlist videos component
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video.model.ts
1 import { User } from '../'
2 import { PlaylistElement, Video as VideoServerModel, VideoPrivacy, VideoState } from '../../../../../shared'
3 import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
4 import { VideoConstant } from '../../../../../shared/models/videos/video-constant.model'
5 import { durationToString, getAbsoluteAPIUrl } from '../misc/utils'
6 import { peertubeTranslate, ServerConfig } from '../../../../../shared/models'
7 import { Actor } from '@app/shared/actor/actor.model'
8 import { VideoScheduleUpdate } from '../../../../../shared/models/videos/video-schedule-update.model'
9
10 export class Video implements VideoServerModel {
11 byVideoChannel: string
12 byAccount: string
13
14 accountAvatarUrl: string
15 videoChannelAvatarUrl: string
16
17 createdAt: Date
18 updatedAt: Date
19 publishedAt: Date
20 originallyPublishedAt: Date | string
21 category: VideoConstant<number>
22 licence: VideoConstant<number>
23 language: VideoConstant<string>
24 privacy: VideoConstant<VideoPrivacy>
25 description: string
26 duration: number
27 durationLabel: string
28 id: number
29 uuid: string
30 isLocal: boolean
31 name: string
32 serverHost: string
33 thumbnailPath: string
34 thumbnailUrl: string
35 previewPath: string
36 previewUrl: string
37 embedPath: string
38 embedUrl: string
39 views: number
40 likes: number
41 dislikes: number
42 nsfw: boolean
43
44 waitTranscoding?: boolean
45 state?: VideoConstant<VideoState>
46 scheduledUpdate?: VideoScheduleUpdate
47 blacklisted?: boolean
48 blacklistedReason?: string
49
50 playlistElement?: PlaylistElement
51
52 account: {
53 id: number
54 uuid: string
55 name: string
56 displayName: string
57 url: string
58 host: string
59 avatar?: Avatar
60 }
61
62 channel: {
63 id: number
64 uuid: string
65 name: string
66 displayName: string
67 url: string
68 host: string
69 avatar?: Avatar
70 }
71
72 userHistory?: {
73 currentTime: number
74 }
75
76 static buildClientUrl (videoUUID: string) {
77 return '/videos/watch/' + videoUUID
78 }
79
80 constructor (hash: VideoServerModel, translations = {}) {
81 const absoluteAPIUrl = getAbsoluteAPIUrl()
82
83 this.createdAt = new Date(hash.createdAt.toString())
84 this.publishedAt = new Date(hash.publishedAt.toString())
85 this.category = hash.category
86 this.licence = hash.licence
87 this.language = hash.language
88 this.privacy = hash.privacy
89 this.waitTranscoding = hash.waitTranscoding
90 this.state = hash.state
91 this.description = hash.description
92 this.duration = hash.duration
93 this.durationLabel = durationToString(hash.duration)
94 this.id = hash.id
95 this.uuid = hash.uuid
96 this.isLocal = hash.isLocal
97 this.name = hash.name
98 this.thumbnailPath = hash.thumbnailPath
99 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
100 this.previewPath = hash.previewPath
101 this.previewUrl = absoluteAPIUrl + hash.previewPath
102 this.embedPath = hash.embedPath
103 this.embedUrl = absoluteAPIUrl + hash.embedPath
104 this.views = hash.views
105 this.likes = hash.likes
106 this.dislikes = hash.dislikes
107 this.nsfw = hash.nsfw
108 this.account = hash.account
109 this.channel = hash.channel
110
111 this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
112 this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host)
113 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
114 this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel)
115
116 this.category.label = peertubeTranslate(this.category.label, translations)
117 this.licence.label = peertubeTranslate(this.licence.label, translations)
118 this.language.label = peertubeTranslate(this.language.label, translations)
119 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
120
121 this.scheduledUpdate = hash.scheduledUpdate
122 this.originallyPublishedAt = hash.originallyPublishedAt ? new Date(hash.originallyPublishedAt.toString()) : null
123
124 if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
125
126 this.blacklisted = hash.blacklisted
127 this.blacklistedReason = hash.blacklistedReason
128
129 this.userHistory = hash.userHistory
130
131 this.playlistElement = hash.playlistElement
132 }
133
134 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
135 // Video is not NSFW, skip
136 if (this.nsfw === false) return false
137
138 // Return user setting if logged in
139 if (user) return user.nsfwPolicy !== 'display'
140
141 // Return default instance config
142 return serverConfig.instance.defaultNSFWPolicy !== 'display'
143 }
144 }