1 import { getAbsoluteAPIUrl } from '@app/helpers'
2 import { Actor } from '@app/shared/shared-main'
8 VideoPlaylist as ServerVideoPlaylist,
11 } from '@shared/models'
13 export class VideoPlaylist implements ServerVideoPlaylist {
20 privacy: VideoConstant<VideoPlaylistPrivacy>
26 type: VideoConstant<VideoPlaylistType>
28 createdAt: Date | string
29 updatedAt: Date | string
31 ownerAccount: AccountSummary
32 videoChannel?: VideoChannelSummary
37 ownerAvatarUrl: string
39 videoChannelBy?: string
40 videoChannelAvatarUrl?: string
42 private thumbnailVersion: number
43 private originThumbnailUrl: string
45 constructor (hash: ServerVideoPlaylist, translations: {}) {
46 const absoluteAPIUrl = getAbsoluteAPIUrl()
50 this.isLocal = hash.isLocal
52 this.displayName = hash.displayName
54 this.description = hash.description
55 this.privacy = hash.privacy
57 this.thumbnailPath = hash.thumbnailPath
59 if (this.thumbnailPath) {
60 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
61 this.originThumbnailUrl = this.thumbnailUrl
63 this.thumbnailUrl = window.location.origin + '/client/assets/images/default-playlist.jpg'
66 this.videosLength = hash.videosLength
70 this.createdAt = new Date(hash.createdAt)
71 this.updatedAt = new Date(hash.updatedAt)
73 this.ownerAccount = hash.ownerAccount
74 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
75 this.ownerAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.ownerAccount)
77 if (hash.videoChannel) {
78 this.videoChannel = hash.videoChannel
79 this.videoChannelBy = Actor.CREATE_BY_STRING(hash.videoChannel.name, hash.videoChannel.host)
80 this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.videoChannel)
83 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
85 if (this.type.id === VideoPlaylistType.WATCH_LATER) {
86 this.displayName = peertubeTranslate(this.displayName, translations)
91 if (!this.originThumbnailUrl) return
93 if (!this.thumbnailVersion) this.thumbnailVersion = 0
94 this.thumbnailVersion++
96 this.thumbnailUrl = this.originThumbnailUrl + '?v' + this.thumbnailVersion