]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-main/video/video-details.model.ts
Merge branch 'next' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / video / video-details.model.ts
1 import { Account } from '@app/shared/shared-main/account/account.model'
2 import { VideoChannel } from '@app/shared/shared-main/video-channel/video-channel.model'
3 import {
4 VideoConstant,
5 VideoDetails as VideoDetailsServerModel,
6 VideoFile,
7 VideoState,
8 VideoStreamingPlaylist,
9 VideoStreamingPlaylistType
10 } from '@shared/models'
11 import { Video } from './video.model'
12
13 export class VideoDetails extends Video implements VideoDetailsServerModel {
14 descriptionPath: string
15 support: string
16 channel: VideoChannel
17 tags: string[]
18 files: VideoFile[]
19 account: Account
20 commentsEnabled: boolean
21 downloadEnabled: boolean
22
23 waitTranscoding: boolean
24 state: VideoConstant<VideoState>
25
26 likesPercent: number
27 dislikesPercent: number
28
29 trackerUrls: string[]
30
31 streamingPlaylists: VideoStreamingPlaylist[]
32
33 constructor (hash: VideoDetailsServerModel, translations = {}) {
34 super(hash, translations)
35
36 this.descriptionPath = hash.descriptionPath
37 this.files = hash.files
38 this.channel = new VideoChannel(hash.channel)
39 this.account = new Account(hash.account)
40 this.tags = hash.tags
41 this.support = hash.support
42 this.commentsEnabled = hash.commentsEnabled
43 this.downloadEnabled = hash.downloadEnabled
44
45 this.trackerUrls = hash.trackerUrls
46 this.streamingPlaylists = hash.streamingPlaylists
47
48 this.buildLikeAndDislikePercents()
49 }
50
51 buildLikeAndDislikePercents () {
52 this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100
53 this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100
54 }
55
56 getHlsPlaylist () {
57 return this.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
58 }
59
60 hasHlsPlaylist () {
61 return !!this.getHlsPlaylist()
62 }
63
64 getFiles () {
65 if (this.files.length !== 0) return this.files
66
67 const hls = this.getHlsPlaylist()
68 if (hls) return hls.files
69
70 return []
71 }
72 }