]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-video-playlist/video-playlist.model.ts
d67f372f41e7b101bd1dfb6f656770e98c159cfa
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-video-playlist / video-playlist.model.ts
1 import { getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers'
2 import { Actor } from '@app/shared/shared-main'
3 import { peertubeTranslate } from '@shared/core-utils/i18n'
4 import {
5 AccountSummary,
6 VideoChannelSummary,
7 VideoConstant,
8 VideoPlaylist as ServerVideoPlaylist,
9 VideoPlaylistPrivacy,
10 VideoPlaylistType
11 } from '@shared/models'
12
13 export class VideoPlaylist implements ServerVideoPlaylist {
14 id: number
15 uuid: string
16 isLocal: boolean
17
18 url: string
19
20 displayName: string
21 description: string
22 privacy: VideoConstant<VideoPlaylistPrivacy>
23
24 videosLength: number
25
26 type: VideoConstant<VideoPlaylistType>
27
28 createdAt: Date | string
29 updatedAt: Date | string
30
31 ownerAccount: AccountSummary
32 videoChannel?: VideoChannelSummary
33
34 thumbnailPath: string
35 thumbnailUrl: string
36
37 embedPath: string
38 embedUrl: string
39
40 ownerBy: string
41
42 videoChannelBy?: string
43
44 constructor (hash: ServerVideoPlaylist, translations: {}) {
45 const absoluteAPIUrl = getAbsoluteAPIUrl()
46
47 this.id = hash.id
48 this.uuid = hash.uuid
49 this.url = hash.url
50 this.isLocal = hash.isLocal
51
52 this.displayName = hash.displayName
53
54 this.description = hash.description
55 this.privacy = hash.privacy
56
57 this.thumbnailPath = hash.thumbnailPath
58
59 this.thumbnailUrl = this.thumbnailPath
60 ? hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath)
61 : absoluteAPIUrl + '/client/assets/images/default-playlist.jpg'
62
63 this.embedPath = hash.embedPath
64 this.embedUrl = hash.embedUrl || (getAbsoluteEmbedUrl() + hash.embedPath)
65
66 this.videosLength = hash.videosLength
67
68 this.type = hash.type
69
70 this.createdAt = new Date(hash.createdAt)
71 this.updatedAt = new Date(hash.updatedAt)
72
73 this.ownerAccount = hash.ownerAccount
74 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
75
76 if (hash.videoChannel) {
77 this.videoChannel = hash.videoChannel
78 this.videoChannelBy = Actor.CREATE_BY_STRING(hash.videoChannel.name, hash.videoChannel.host)
79 }
80
81 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
82
83 if (this.type.id === VideoPlaylistType.WATCH_LATER) {
84 this.displayName = peertubeTranslate(this.displayName, translations)
85 }
86 }
87 }