PeerTube/client/src/app/shared/video/video-details.model.ts

65 lines
2.0 KiB
TypeScript
Raw Normal View History

import { VideoConstant, VideoDetails as VideoDetailsServerModel, VideoFile, VideoState } from '../../../../../shared'
2018-01-03 10:12:36 +01:00
import { Video } from '../../shared/video/video.model'
2018-05-25 09:57:16 +02:00
import { Account } from '@app/shared/account/account.model'
2018-08-21 16:18:59 +02:00
import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
2019-01-29 08:37:25 +01:00
import { VideoStreamingPlaylist } from '../../../../../shared/models/videos/video-streaming-playlist.model'
import { VideoStreamingPlaylistType } from '../../../../../shared/models/videos/video-streaming-playlist.type'
2017-10-25 16:43:19 +02:00
export class VideoDetails extends Video implements VideoDetailsServerModel {
descriptionPath: string
support: string
channel: VideoChannel
2017-10-25 16:43:19 +02:00
tags: string[]
files: VideoFile[]
2017-12-06 17:15:59 +01:00
account: Account
commentsEnabled: boolean
downloadEnabled: boolean
waitTranscoding: boolean
state: VideoConstant<VideoState>
2017-12-06 18:04:40 +01:00
likesPercent: number
dislikesPercent: number
2017-10-25 16:43:19 +02:00
2019-01-29 08:37:25 +01:00
trackerUrls: string[]
streamingPlaylists: VideoStreamingPlaylist[]
2018-06-06 16:46:42 +02:00
constructor (hash: VideoDetailsServerModel, translations = {}) {
super(hash, translations)
2017-10-25 16:43:19 +02:00
this.descriptionPath = hash.descriptionPath
2017-10-25 16:43:19 +02:00
this.files = hash.files
2018-08-21 16:18:59 +02:00
this.channel = new VideoChannel(hash.channel)
2018-05-25 09:57:16 +02:00
this.account = new Account(hash.account)
2017-12-14 10:07:57 +01:00
this.tags = hash.tags
2018-02-20 16:13:05 +01:00
this.support = hash.support
2018-01-03 10:12:36 +01:00
this.commentsEnabled = hash.commentsEnabled
this.downloadEnabled = hash.downloadEnabled
2017-12-06 18:04:40 +01:00
2019-01-29 08:37:25 +01:00
this.trackerUrls = hash.trackerUrls
this.streamingPlaylists = hash.streamingPlaylists
2018-02-28 09:49:40 +01:00
this.buildLikeAndDislikePercents()
2017-10-25 16:43:19 +02:00
}
2018-02-28 09:49:40 +01:00
buildLikeAndDislikePercents () {
this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100
this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100
}
2019-01-29 08:37:25 +01:00
getHlsPlaylist () {
return this.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
}
2019-05-14 11:35:54 +02:00
hasHlsPlaylist () {
return !!this.getHlsPlaylist()
}
2019-11-21 17:01:24 +01:00
getFiles () {
if (this.files.length === 0) return this.getHlsPlaylist().files
2019-11-22 17:27:46 +01:00
return this.files
2019-11-21 17:01:24 +01:00
}
2017-10-25 16:43:19 +02:00
}