1 import { getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers'
2 import { Actor } from '@app/shared/shared-main'
3 import { buildPlaylistWatchPath } from '@shared/core-utils'
4 import { peertubeTranslate } from '@shared/core-utils/i18n'
9 VideoPlaylist as ServerVideoPlaylist,
12 } from '@shared/models'
14 export class VideoPlaylist implements ServerVideoPlaylist {
25 privacy: VideoConstant<VideoPlaylistPrivacy>
29 type: VideoConstant<VideoPlaylistType>
31 createdAt: Date | string
32 updatedAt: Date | string
34 ownerAccount: AccountSummary
35 videoChannel?: VideoChannelSummary
45 videoChannelBy?: string
47 static buildWatchUrl (playlist: Pick<VideoPlaylist, 'uuid' | 'shortUUID'>) {
48 return buildPlaylistWatchPath({ shortUUID: playlist.shortUUID || playlist.uuid })
51 constructor (hash: ServerVideoPlaylist, translations: {}) {
52 const absoluteAPIUrl = getAbsoluteAPIUrl()
56 this.shortUUID = hash.shortUUID
59 this.isLocal = hash.isLocal
61 this.displayName = hash.displayName
63 this.description = hash.description
64 this.privacy = hash.privacy
66 this.thumbnailPath = hash.thumbnailPath
68 this.thumbnailUrl = this.thumbnailPath
69 ? hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath)
70 : absoluteAPIUrl + '/client/assets/images/default-playlist.jpg'
72 this.embedPath = hash.embedPath
73 this.embedUrl = hash.embedUrl || (getAbsoluteEmbedUrl() + hash.embedPath)
75 this.videosLength = hash.videosLength
79 this.createdAt = new Date(hash.createdAt)
80 this.updatedAt = new Date(hash.updatedAt)
82 this.ownerAccount = hash.ownerAccount
83 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
85 if (hash.videoChannel) {
86 this.videoChannel = hash.videoChannel
87 this.videoChannelBy = Actor.CREATE_BY_STRING(hash.videoChannel.name, hash.videoChannel.host)
90 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
92 if (this.type.id === VideoPlaylistType.WATCH_LATER) {
93 this.displayName = peertubeTranslate(this.displayName, translations)