]>
Commit | Line | Data |
---|---|---|
404b54e1 | 1 | import { |
09700934 C |
2 | UserRight, |
3 | VideoChannel, | |
4 | VideoDetails as VideoDetailsServerModel, | |
5 | VideoFile, | |
6 | VideoPrivacy, | |
47564bbe | 7 | VideoResolution |
404b54e1 | 8 | } from '../../../../../shared' |
47564bbe | 9 | import { Account } from '../../../../../shared/models/actors' |
09700934 | 10 | import { VideoConstant } from '../../../../../shared/models/videos/video.model' |
47564bbe C |
11 | import { AuthUser } from '../../core' |
12 | import { Video } from '../../shared/video/video.model' | |
404b54e1 C |
13 | |
14 | export class VideoDetails extends Video implements VideoDetailsServerModel { | |
09700934 C |
15 | privacy: VideoConstant<VideoPrivacy> |
16 | descriptionPath: string | |
2422c46b | 17 | support: string |
09700934 | 18 | channel: VideoChannel |
404b54e1 | 19 | tags: string[] |
404b54e1 | 20 | files: VideoFile[] |
b1fa3eba | 21 | account: Account |
09700934 C |
22 | commentsEnabled: boolean |
23 | ||
6a9e1d42 C |
24 | likesPercent: number |
25 | dislikesPercent: number | |
404b54e1 C |
26 | |
27 | constructor (hash: VideoDetailsServerModel) { | |
28 | super(hash) | |
29 | ||
fd45e8f4 | 30 | this.privacy = hash.privacy |
2de96f4d | 31 | this.descriptionPath = hash.descriptionPath |
404b54e1 C |
32 | this.files = hash.files |
33 | this.channel = hash.channel | |
b1fa3eba | 34 | this.account = hash.account |
d48ff09d | 35 | this.tags = hash.tags |
07fa4c97 | 36 | this.support = hash.support |
47564bbe | 37 | this.commentsEnabled = hash.commentsEnabled |
6a9e1d42 | 38 | |
20b40b19 | 39 | this.buildLikeAndDislikePercents() |
404b54e1 C |
40 | } |
41 | ||
42 | getAppropriateMagnetUri (actualDownloadSpeed = 0) { | |
43 | if (this.files === undefined || this.files.length === 0) return '' | |
44 | if (this.files.length === 1) return this.files[0].magnetUri | |
45 | ||
46 | // Find first video that is good for our download speed (remember they are sorted) | |
47 | let betterResolutionFile = this.files.find(f => actualDownloadSpeed > (f.size / this.duration)) | |
48 | ||
49 | // If the download speed is too bad, return the lowest resolution we have | |
50 | if (betterResolutionFile === undefined) { | |
09700934 | 51 | betterResolutionFile = this.files.find(f => f.resolution.id === VideoResolution.H_240P) |
404b54e1 C |
52 | } |
53 | ||
54 | return betterResolutionFile.magnetUri | |
55 | } | |
56 | ||
954605a8 | 57 | isRemovableBy (user: AuthUser) { |
09700934 | 58 | return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO)) |
404b54e1 C |
59 | } |
60 | ||
954605a8 C |
61 | isBlackistableBy (user: AuthUser) { |
62 | return user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true && this.isLocal === false | |
404b54e1 C |
63 | } |
64 | ||
954605a8 | 65 | isUpdatableBy (user: AuthUser) { |
09700934 | 66 | return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO)) |
404b54e1 | 67 | } |
20b40b19 C |
68 | |
69 | buildLikeAndDislikePercents () { | |
70 | this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100 | |
71 | this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100 | |
72 | } | |
404b54e1 | 73 | } |