]>
Commit | Line | Data |
---|---|---|
1 | import { VideoConstant, VideoDetails as VideoDetailsServerModel, VideoFile, VideoState } from '../../../../../shared' | |
2 | import { Video } from '../../shared/video/video.model' | |
3 | import { Account } from '@app/shared/account/account.model' | |
4 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' | |
5 | import { VideoStreamingPlaylist } from '../../../../../shared/models/videos/video-streaming-playlist.model' | |
6 | import { VideoStreamingPlaylistType } from '../../../../../shared/models/videos/video-streaming-playlist.type' | |
7 | ||
8 | export class VideoDetails extends Video implements VideoDetailsServerModel { | |
9 | descriptionPath: string | |
10 | support: string | |
11 | channel: VideoChannel | |
12 | tags: string[] | |
13 | files: VideoFile[] | |
14 | account: Account | |
15 | commentsEnabled: boolean | |
16 | downloadEnabled: 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 | this.downloadEnabled = hash.downloadEnabled | |
39 | ||
40 | this.trackerUrls = hash.trackerUrls | |
41 | this.streamingPlaylists = hash.streamingPlaylists | |
42 | ||
43 | this.buildLikeAndDislikePercents() | |
44 | } | |
45 | ||
46 | buildLikeAndDislikePercents () { | |
47 | this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100 | |
48 | this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100 | |
49 | } | |
50 | ||
51 | getHlsPlaylist () { | |
52 | return this.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS) | |
53 | } | |
54 | ||
55 | hasHlsPlaylist () { | |
56 | return !!this.getHlsPlaylist() | |
57 | } | |
58 | ||
59 | getFiles () { | |
60 | if (this.files.length === 0) return this.getHlsPlaylist().files | |
61 | ||
62 | return this.files | |
63 | } | |
64 | } |