]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/video/video-details.model.ts
Add hls support on server
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video-details.model.ts
1 import { UserRight, VideoConstant, VideoDetails as VideoDetailsServerModel, VideoFile, VideoState } from '../../../../../shared'
2 import { AuthUser } from '../../core'
3 import { Video } from '../../shared/video/video.model'
4 import { Account } from '@app/shared/account/account.model'
5 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
6 import { VideoStreamingPlaylist } from '../../../../../shared/models/videos/video-streaming-playlist.model'
7 import { VideoStreamingPlaylistType } from '../../../../../shared/models/videos/video-streaming-playlist.type'
8
9 export class VideoDetails extends Video implements VideoDetailsServerModel {
10 descriptionPath: string
11 support: string
12 channel: VideoChannel
13 tags: string[]
14 files: VideoFile[]
15 account: Account
16 commentsEnabled: boolean
17
18 waitTranscoding: boolean
19 state: VideoConstant<VideoState>
20
21 likesPercent: number
22 dislikesPercent: number
23
24 trackerUrls: string[]
25
26 streamingPlaylists: VideoStreamingPlaylist[]
27
28 constructor (hash: VideoDetailsServerModel, translations = {}) {
29 super(hash, translations)
30
31 this.descriptionPath = hash.descriptionPath
32 this.files = hash.files
33 this.channel = new VideoChannel(hash.channel)
34 this.account = new Account(hash.account)
35 this.tags = hash.tags
36 this.support = hash.support
37 this.commentsEnabled = hash.commentsEnabled
38
39 this.trackerUrls = hash.trackerUrls
40 this.streamingPlaylists = hash.streamingPlaylists
41
42 this.buildLikeAndDislikePercents()
43 }
44
45 isRemovableBy (user: AuthUser) {
46 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
47 }
48
49 isBlackistableBy (user: AuthUser) {
50 return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
51 }
52
53 isUnblacklistableBy (user: AuthUser) {
54 return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
55 }
56
57 isUpdatableBy (user: AuthUser) {
58 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
59 }
60
61 buildLikeAndDislikePercents () {
62 this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100
63 this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100
64 }
65
66 getHlsPlaylist () {
67 return this.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
68 }
69 }