]>
Commit | Line | Data |
---|---|---|
404b54e1 | 1 | import { |
47564bbe C |
2 | UserRight, VideoChannel, VideoDetails as VideoDetailsServerModel, VideoFile, VideoPrivacy, |
3 | VideoResolution | |
404b54e1 | 4 | } from '../../../../../shared' |
47564bbe C |
5 | import { Account } from '../../../../../shared/models/actors' |
6 | import { AuthUser } from '../../core' | |
7 | import { Video } from '../../shared/video/video.model' | |
404b54e1 C |
8 | |
9 | export class VideoDetails extends Video implements VideoDetailsServerModel { | |
b1fa3eba | 10 | accountName: string |
404b54e1 C |
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 | |
2422c46b | 21 | support: string |
404b54e1 C |
22 | duration: number |
23 | durationLabel: string | |
24 | id: number | |
25 | uuid: string | |
26 | isLocal: boolean | |
27 | name: string | |
60862425 | 28 | serverHost: string |
404b54e1 C |
29 | tags: string[] |
30 | thumbnailPath: string | |
31 | thumbnailUrl: string | |
32 | previewPath: string | |
33 | previewUrl: string | |
34 | embedPath: string | |
35 | embedUrl: string | |
36 | views: number | |
37 | likes: number | |
38 | dislikes: number | |
39 | nsfw: boolean | |
2de96f4d | 40 | descriptionPath: string |
404b54e1 C |
41 | files: VideoFile[] |
42 | channel: VideoChannel | |
fd45e8f4 C |
43 | privacy: VideoPrivacy |
44 | privacyLabel: string | |
b1fa3eba | 45 | account: Account |
6a9e1d42 C |
46 | likesPercent: number |
47 | dislikesPercent: number | |
47564bbe | 48 | commentsEnabled: boolean |
404b54e1 C |
49 | |
50 | constructor (hash: VideoDetailsServerModel) { | |
51 | super(hash) | |
52 | ||
fd45e8f4 C |
53 | this.privacy = hash.privacy |
54 | this.privacyLabel = hash.privacyLabel | |
2de96f4d | 55 | this.descriptionPath = hash.descriptionPath |
404b54e1 C |
56 | this.files = hash.files |
57 | this.channel = hash.channel | |
b1fa3eba | 58 | this.account = hash.account |
d48ff09d | 59 | this.tags = hash.tags |
07fa4c97 | 60 | this.support = hash.support |
47564bbe | 61 | this.commentsEnabled = hash.commentsEnabled |
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) { |
6221f311 | 91 | return user && this.isLocal === true && (this.accountName === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO)) |
404b54e1 C |
92 | } |
93 | } |