]>
Commit | Line | Data |
---|---|---|
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 | account: Account | |
19 | commentsEnabled: boolean | |
20 | downloadEnabled: boolean | |
21 | ||
22 | waitTranscoding: boolean | |
23 | state: VideoConstant<VideoState> | |
24 | ||
25 | likesPercent: number | |
26 | dislikesPercent: number | |
27 | ||
28 | trackerUrls: string[] | |
29 | ||
30 | files: VideoFile[] | |
31 | streamingPlaylists: VideoStreamingPlaylist[] | |
32 | ||
33 | constructor (hash: VideoDetailsServerModel, translations = {}) { | |
34 | super(hash, translations) | |
35 | ||
36 | this.descriptionPath = hash.descriptionPath | |
37 | this.channel = new VideoChannel(hash.channel) | |
38 | this.account = new Account(hash.account) | |
39 | this.tags = hash.tags | |
40 | this.support = hash.support | |
41 | this.commentsEnabled = hash.commentsEnabled | |
42 | this.downloadEnabled = hash.downloadEnabled | |
43 | ||
44 | this.trackerUrls = hash.trackerUrls | |
45 | ||
46 | this.buildLikeAndDislikePercents() | |
47 | } | |
48 | ||
49 | buildLikeAndDislikePercents () { | |
50 | this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100 | |
51 | this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100 | |
52 | } | |
53 | ||
54 | getHlsPlaylist () { | |
55 | return this.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS) | |
56 | } | |
57 | ||
58 | hasHlsPlaylist () { | |
59 | return !!this.getHlsPlaylist() | |
60 | } | |
61 | ||
62 | getFiles () { | |
63 | if (this.files.length !== 0) return this.files | |
64 | ||
65 | const hls = this.getHlsPlaylist() | |
66 | if (hls) return hls.files | |
67 | ||
68 | return [] | |
69 | } | |
70 | } |