]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/shared/video-details.model.ts
e99a5ce2e53deb3b82097f612a347718b1ebc8cc
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / shared / video-details.model.ts
1 import { Video } from './video.model'
2 import {
3 VideoDetails as VideoDetailsServerModel,
4 VideoFile,
5 VideoChannel,
6 VideoResolution
7 } from '../../../../../shared'
8
9 export class VideoDetails extends Video implements VideoDetailsServerModel {
10 author: string
11 by: string
12 createdAt: Date
13 updatedAt: Date
14 categoryLabel: string
15 category: number
16 licenceLabel: string
17 licence: number
18 languageLabel: string
19 language: number
20 description: string
21 duration: number
22 durationLabel: string
23 id: number
24 uuid: string
25 isLocal: boolean
26 name: string
27 podHost: string
28 tags: string[]
29 thumbnailPath: string
30 thumbnailUrl: string
31 previewPath: string
32 previewUrl: string
33 embedPath: string
34 embedUrl: string
35 views: number
36 likes: number
37 dislikes: number
38 nsfw: boolean
39 files: VideoFile[]
40 channel: VideoChannel
41
42 constructor (hash: VideoDetailsServerModel) {
43 super(hash)
44
45 this.files = hash.files
46 this.channel = hash.channel
47 }
48
49 getAppropriateMagnetUri (actualDownloadSpeed = 0) {
50 if (this.files === undefined || this.files.length === 0) return ''
51 if (this.files.length === 1) return this.files[0].magnetUri
52
53 // Find first video that is good for our download speed (remember they are sorted)
54 let betterResolutionFile = this.files.find(f => actualDownloadSpeed > (f.size / this.duration))
55
56 // If the download speed is too bad, return the lowest resolution we have
57 if (betterResolutionFile === undefined) {
58 betterResolutionFile = this.files.find(f => f.resolution === VideoResolution.H_240P)
59 }
60
61 return betterResolutionFile.magnetUri
62 }
63
64 isRemovableBy (user) {
65 return user && this.isLocal === true && (this.author === user.username || user.isAdmin() === true)
66 }
67
68 isBlackistableBy (user) {
69 return user && user.isAdmin() === true && this.isLocal === false
70 }
71
72 isUpdatableBy (user) {
73 return user && this.isLocal === true && user.username === this.author
74 }
75 }