1 import { getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers'
2 import { Account, Actor, VideoChannel } 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
41 videoChannelBy?: string
43 private thumbnailVersion: number
44 private originThumbnailUrl: string
46 constructor (hash: ServerVideoPlaylist, translations: {}) {
47 const absoluteAPIUrl = getAbsoluteAPIUrl()
51 this.isLocal = hash.isLocal
53 this.displayName = hash.displayName
55 this.description = hash.description
56 this.privacy = hash.privacy
58 this.thumbnailPath = hash.thumbnailPath
60 if (this.thumbnailPath) {
61 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
62 this.originThumbnailUrl = this.thumbnailUrl
64 this.thumbnailUrl = window.location.origin + '/client/assets/images/default-playlist.jpg'
67 this.embedPath = hash.embedPath
68 this.embedUrl = getAbsoluteEmbedUrl() + hash.embedPath
70 this.videosLength = hash.videosLength
74 this.createdAt = new Date(hash.createdAt)
75 this.updatedAt = new Date(hash.updatedAt)
77 this.ownerAccount = hash.ownerAccount
78 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
80 if (hash.videoChannel) {
81 this.videoChannel = hash.videoChannel
82 this.videoChannelBy = Actor.CREATE_BY_STRING(hash.videoChannel.name, hash.videoChannel.host)
85 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
87 if (this.type.id === VideoPlaylistType.WATCH_LATER) {
88 this.displayName = peertubeTranslate(this.displayName, translations)
93 if (!this.originThumbnailUrl) return
95 if (!this.thumbnailVersion) this.thumbnailVersion = 0
96 this.thumbnailVersion++
98 this.thumbnailUrl = this.originThumbnailUrl + '?v' + this.thumbnailVersion