1 import { getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers'
2 import { Actor } from '@app/shared/shared-main'
3 import { peertubeTranslate } from '@shared/core-utils/i18n'
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
40 ownerAvatarUrl: string
42 videoChannelBy?: string
43 videoChannelAvatarUrl?: string
45 private thumbnailVersion: number
46 private originThumbnailUrl: string
48 constructor (hash: ServerVideoPlaylist, translations: {}) {
49 const absoluteAPIUrl = getAbsoluteAPIUrl()
53 this.isLocal = hash.isLocal
55 this.displayName = hash.displayName
57 this.description = hash.description
58 this.privacy = hash.privacy
60 this.thumbnailPath = hash.thumbnailPath
62 if (this.thumbnailPath) {
63 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
64 this.originThumbnailUrl = this.thumbnailUrl
66 this.thumbnailUrl = window.location.origin + '/client/assets/images/default-playlist.jpg'
69 this.embedPath = hash.embedPath
70 this.embedUrl = getAbsoluteEmbedUrl() + hash.embedPath
72 this.videosLength = hash.videosLength
76 this.createdAt = new Date(hash.createdAt)
77 this.updatedAt = new Date(hash.updatedAt)
79 this.ownerAccount = hash.ownerAccount
80 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
81 this.ownerAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.ownerAccount)
83 if (hash.videoChannel) {
84 this.videoChannel = hash.videoChannel
85 this.videoChannelBy = Actor.CREATE_BY_STRING(hash.videoChannel.name, hash.videoChannel.host)
86 this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.videoChannel)
89 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
91 if (this.type.id === VideoPlaylistType.WATCH_LATER) {
92 this.displayName = peertubeTranslate(this.displayName, translations)
97 if (!this.originThumbnailUrl) return
99 if (!this.thumbnailVersion) this.thumbnailVersion = 0
100 this.thumbnailVersion++
102 this.thumbnailUrl = this.originThumbnailUrl + '?v' + this.thumbnailVersion