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 {
24 privacy: VideoConstant<VideoPlaylistPrivacy>
28 type: VideoConstant<VideoPlaylistType>
30 createdAt: Date | string
31 updatedAt: Date | string
33 ownerAccount: AccountSummary
34 videoChannel?: VideoChannelSummary
44 videoChannelBy?: string
46 static buildWatchUrl (playlist: Pick<VideoPlaylist, 'uuid' | 'shortUUID'>) {
47 return '/w/p/' + (playlist.shortUUID || playlist.uuid)
50 constructor (hash: ServerVideoPlaylist, translations: {}) {
51 const absoluteAPIUrl = getAbsoluteAPIUrl()
55 this.shortUUID = hash.shortUUID
58 this.isLocal = hash.isLocal
60 this.displayName = hash.displayName
62 this.description = hash.description
63 this.privacy = hash.privacy
65 this.thumbnailPath = hash.thumbnailPath
67 this.thumbnailUrl = this.thumbnailPath
68 ? hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath)
69 : absoluteAPIUrl + '/client/assets/images/default-playlist.jpg'
71 this.embedPath = hash.embedPath
72 this.embedUrl = hash.embedUrl || (getAbsoluteEmbedUrl() + hash.embedPath)
74 this.videosLength = hash.videosLength
78 this.createdAt = new Date(hash.createdAt)
79 this.updatedAt = new Date(hash.updatedAt)
81 this.ownerAccount = hash.ownerAccount
82 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
84 if (hash.videoChannel) {
85 this.videoChannel = hash.videoChannel
86 this.videoChannelBy = Actor.CREATE_BY_STRING(hash.videoChannel.name, hash.videoChannel.host)
89 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
91 if (this.type.id === VideoPlaylistType.WATCH_LATER) {
92 this.displayName = peertubeTranslate(this.displayName, translations)