]>
Commit | Line | Data |
---|---|---|
b1fa3eba | 1 | import { Account } from '../../../../../shared/models/accounts' |
202f6b6c | 2 | import { Video } from '../../shared/video/video.model' |
954605a8 | 3 | import { AuthUser } from '../../core' |
404b54e1 C |
4 | import { |
5 | VideoDetails as VideoDetailsServerModel, | |
6 | VideoFile, | |
7 | VideoChannel, | |
954605a8 | 8 | VideoResolution, |
fd45e8f4 C |
9 | UserRight, |
10 | VideoPrivacy | |
404b54e1 C |
11 | } from '../../../../../shared' |
12 | ||
13 | export class VideoDetails extends Video implements VideoDetailsServerModel { | |
b1fa3eba | 14 | accountName: string |
404b54e1 C |
15 | by: string |
16 | createdAt: Date | |
17 | updatedAt: Date | |
18 | categoryLabel: string | |
19 | category: number | |
20 | licenceLabel: string | |
21 | licence: number | |
22 | languageLabel: string | |
23 | language: number | |
24 | description: string | |
25 | duration: number | |
26 | durationLabel: string | |
27 | id: number | |
28 | uuid: string | |
29 | isLocal: boolean | |
30 | name: string | |
60862425 | 31 | serverHost: string |
404b54e1 C |
32 | tags: string[] |
33 | thumbnailPath: string | |
34 | thumbnailUrl: string | |
35 | previewPath: string | |
36 | previewUrl: string | |
37 | embedPath: string | |
38 | embedUrl: string | |
39 | views: number | |
40 | likes: number | |
41 | dislikes: number | |
42 | nsfw: boolean | |
2de96f4d | 43 | descriptionPath: string |
404b54e1 C |
44 | files: VideoFile[] |
45 | channel: VideoChannel | |
fd45e8f4 C |
46 | privacy: VideoPrivacy |
47 | privacyLabel: string | |
b1fa3eba | 48 | account: Account |
6a9e1d42 C |
49 | likesPercent: number |
50 | dislikesPercent: number | |
404b54e1 C |
51 | |
52 | constructor (hash: VideoDetailsServerModel) { | |
53 | super(hash) | |
54 | ||
fd45e8f4 C |
55 | this.privacy = hash.privacy |
56 | this.privacyLabel = hash.privacyLabel | |
2de96f4d | 57 | this.descriptionPath = hash.descriptionPath |
404b54e1 C |
58 | this.files = hash.files |
59 | this.channel = hash.channel | |
b1fa3eba | 60 | this.account = hash.account |
d48ff09d | 61 | this.tags = hash.tags |
6a9e1d42 C |
62 | |
63 | this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100 | |
64 | this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100 | |
404b54e1 C |
65 | } |
66 | ||
67 | getAppropriateMagnetUri (actualDownloadSpeed = 0) { | |
68 | if (this.files === undefined || this.files.length === 0) return '' | |
69 | if (this.files.length === 1) return this.files[0].magnetUri | |
70 | ||
71 | // Find first video that is good for our download speed (remember they are sorted) | |
72 | let betterResolutionFile = this.files.find(f => actualDownloadSpeed > (f.size / this.duration)) | |
73 | ||
74 | // If the download speed is too bad, return the lowest resolution we have | |
75 | if (betterResolutionFile === undefined) { | |
76 | betterResolutionFile = this.files.find(f => f.resolution === VideoResolution.H_240P) | |
77 | } | |
78 | ||
79 | return betterResolutionFile.magnetUri | |
80 | } | |
81 | ||
954605a8 | 82 | isRemovableBy (user: AuthUser) { |
b1fa3eba | 83 | return user && this.isLocal === true && (this.accountName === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO)) |
404b54e1 C |
84 | } |
85 | ||
954605a8 C |
86 | isBlackistableBy (user: AuthUser) { |
87 | return user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true && this.isLocal === false | |
404b54e1 C |
88 | } |
89 | ||
954605a8 | 90 | isUpdatableBy (user: AuthUser) { |
b1fa3eba | 91 | return user && this.isLocal === true && user.username === this.accountName |
404b54e1 C |
92 | } |
93 | } |