2019-04-05 10:52:27 +02:00
|
|
|
import { AuthUser } from '@app/core'
|
2020-06-23 14:10:17 +02:00
|
|
|
import { User } from '@app/core/users/user.model'
|
2020-07-10 11:13:41 +02:00
|
|
|
import { durationToString, getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers'
|
2020-11-25 11:44:31 +01:00
|
|
|
import { Actor } from '@app/shared/shared-main/account/actor.model'
|
2021-07-26 15:04:37 +02:00
|
|
|
import { buildVideoWatchPath } from '@shared/core-utils'
|
2020-08-06 14:58:01 +02:00
|
|
|
import { peertubeTranslate } from '@shared/core-utils/i18n'
|
2020-06-23 14:10:17 +02:00
|
|
|
import {
|
2021-04-06 11:35:56 +02:00
|
|
|
ActorImage,
|
2021-06-04 13:31:41 +02:00
|
|
|
HTMLServerConfig,
|
2020-06-23 14:10:17 +02:00
|
|
|
UserRight,
|
|
|
|
Video as VideoServerModel,
|
|
|
|
VideoConstant,
|
2021-10-29 10:54:27 +02:00
|
|
|
VideoFile,
|
2020-06-23 14:10:17 +02:00
|
|
|
VideoPrivacy,
|
|
|
|
VideoScheduleUpdate,
|
2021-10-29 10:54:27 +02:00
|
|
|
VideoState,
|
2021-11-17 16:04:53 +01:00
|
|
|
VideoStreamingPlaylist,
|
|
|
|
VideoStreamingPlaylistType
|
2020-06-23 14:10:17 +02:00
|
|
|
} from '@shared/models'
|
2017-04-04 21:37:03 +02:00
|
|
|
|
2017-06-11 11:02:35 +02:00
|
|
|
export class Video implements VideoServerModel {
|
2018-08-21 16:18:59 +02:00
|
|
|
byVideoChannel: string
|
|
|
|
byAccount: string
|
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
createdAt: Date
|
2017-09-12 12:53:55 +02:00
|
|
|
updatedAt: Date
|
2018-03-28 23:38:52 +02:00
|
|
|
publishedAt: Date
|
2019-01-12 14:41:45 +01:00
|
|
|
originallyPublishedAt: Date | string
|
2018-03-19 11:04:40 +01:00
|
|
|
category: VideoConstant<number>
|
|
|
|
licence: VideoConstant<number>
|
2018-04-23 14:39:52 +02:00
|
|
|
language: VideoConstant<string>
|
2018-04-19 14:52:10 +02:00
|
|
|
privacy: VideoConstant<VideoPrivacy>
|
2021-06-28 17:30:59 +02:00
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
description: string
|
2021-06-28 17:30:59 +02:00
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
duration: number
|
|
|
|
durationLabel: string
|
2021-06-28 17:30:59 +02:00
|
|
|
|
2017-07-11 16:01:56 +02:00
|
|
|
id: number
|
|
|
|
uuid: string
|
2021-06-28 17:30:59 +02:00
|
|
|
shortUUID: string
|
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
isLocal: boolean
|
2021-06-28 17:30:59 +02:00
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
name: string
|
2017-11-15 11:00:25 +01:00
|
|
|
serverHost: string
|
2017-06-16 14:32:15 +02:00
|
|
|
thumbnailPath: string
|
|
|
|
thumbnailUrl: string
|
2020-05-29 16:16:24 +02:00
|
|
|
|
2020-09-17 09:20:52 +02:00
|
|
|
isLive: boolean
|
|
|
|
|
2017-07-12 12:16:13 +02:00
|
|
|
previewPath: string
|
|
|
|
previewUrl: string
|
2020-05-29 16:16:24 +02:00
|
|
|
|
2017-10-16 10:05:49 +02:00
|
|
|
embedPath: string
|
|
|
|
embedUrl: string
|
2020-05-29 16:16:24 +02:00
|
|
|
|
2021-10-22 14:11:58 +02:00
|
|
|
url: string
|
2020-05-29 16:16:24 +02:00
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
views: number
|
2021-11-09 10:11:20 +01:00
|
|
|
// If live
|
|
|
|
viewers?: number
|
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
likes: number
|
|
|
|
dislikes: number
|
|
|
|
nsfw: boolean
|
2018-03-12 11:06:15 +01:00
|
|
|
|
2020-01-29 13:59:40 +01:00
|
|
|
originInstanceUrl: string
|
|
|
|
originInstanceHost: string
|
|
|
|
|
2018-06-12 20:04:58 +02:00
|
|
|
waitTranscoding?: boolean
|
|
|
|
state?: VideoConstant<VideoState>
|
2018-06-15 16:52:15 +02:00
|
|
|
scheduledUpdate?: VideoScheduleUpdate
|
2021-10-27 14:37:04 +02:00
|
|
|
|
2018-08-14 09:08:47 +02:00
|
|
|
blacklisted?: boolean
|
2021-10-27 14:37:04 +02:00
|
|
|
blacklistedReason?: string
|
|
|
|
|
|
|
|
blockedOwner?: boolean
|
|
|
|
blockedServer?: boolean
|
2018-06-12 20:04:58 +02:00
|
|
|
|
2018-03-12 11:06:15 +01:00
|
|
|
account: {
|
2018-04-25 14:32:19 +02:00
|
|
|
id: number
|
2018-03-12 11:06:15 +01:00
|
|
|
name: string
|
|
|
|
displayName: string
|
|
|
|
url: string
|
2018-05-11 15:10:13 +02:00
|
|
|
host: string
|
2021-04-06 11:35:56 +02:00
|
|
|
avatar?: ActorImage
|
2018-05-11 15:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
channel: {
|
|
|
|
id: number
|
|
|
|
name: string
|
|
|
|
displayName: string
|
|
|
|
url: string
|
2018-03-12 11:06:15 +01:00
|
|
|
host: string
|
2021-04-06 11:35:56 +02:00
|
|
|
avatar?: ActorImage
|
2018-03-12 11:06:15 +01:00
|
|
|
}
|
2016-05-23 12:15:03 +02:00
|
|
|
|
2018-10-05 11:15:06 +02:00
|
|
|
userHistory?: {
|
|
|
|
currentTime: number
|
|
|
|
}
|
|
|
|
|
2020-08-20 16:18:16 +02:00
|
|
|
pluginData?: any
|
|
|
|
|
2021-10-29 10:54:27 +02:00
|
|
|
streamingPlaylists?: VideoStreamingPlaylist[]
|
|
|
|
files?: VideoFile[]
|
|
|
|
|
2021-06-28 17:30:59 +02:00
|
|
|
static buildWatchUrl (video: Partial<Pick<Video, 'uuid' | 'shortUUID'>>) {
|
2021-07-26 15:04:37 +02:00
|
|
|
return buildVideoWatchPath({ shortUUID: video.shortUUID || video.uuid })
|
2021-06-28 17:30:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static buildUpdateUrl (video: Pick<Video, 'uuid'>) {
|
|
|
|
return '/videos/update/' + video.uuid
|
2018-08-14 09:08:47 +02:00
|
|
|
}
|
|
|
|
|
2021-08-17 14:42:53 +02:00
|
|
|
constructor (hash: VideoServerModel, translations: { [ id: string ]: string } = {}) {
|
2017-12-29 19:10:13 +01:00
|
|
|
const absoluteAPIUrl = getAbsoluteAPIUrl()
|
2017-10-17 16:22:14 +02:00
|
|
|
|
2017-09-14 11:57:49 +02:00
|
|
|
this.createdAt = new Date(hash.createdAt.toString())
|
2018-03-28 23:38:52 +02:00
|
|
|
this.publishedAt = new Date(hash.publishedAt.toString())
|
2017-06-16 14:32:15 +02:00
|
|
|
this.category = hash.category
|
|
|
|
this.licence = hash.licence
|
|
|
|
this.language = hash.language
|
2018-04-19 14:52:10 +02:00
|
|
|
this.privacy = hash.privacy
|
2018-06-12 20:04:58 +02:00
|
|
|
this.waitTranscoding = hash.waitTranscoding
|
|
|
|
this.state = hash.state
|
2017-06-16 14:32:15 +02:00
|
|
|
this.description = hash.description
|
2020-01-29 13:59:40 +01:00
|
|
|
|
2020-09-17 09:20:52 +02:00
|
|
|
this.isLive = hash.isLive
|
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
this.duration = hash.duration
|
2018-08-27 15:59:00 +02:00
|
|
|
this.durationLabel = durationToString(hash.duration)
|
2020-01-29 13:59:40 +01:00
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
this.id = hash.id
|
2017-07-11 16:01:56 +02:00
|
|
|
this.uuid = hash.uuid
|
2021-06-28 17:30:59 +02:00
|
|
|
this.shortUUID = hash.shortUUID
|
2020-01-29 13:59:40 +01:00
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
this.isLocal = hash.isLocal
|
|
|
|
this.name = hash.name
|
2020-01-29 13:59:40 +01:00
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
this.thumbnailPath = hash.thumbnailPath
|
2020-09-17 09:20:52 +02:00
|
|
|
this.thumbnailUrl = this.thumbnailPath
|
|
|
|
? hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath)
|
|
|
|
: null
|
2020-01-29 13:59:40 +01:00
|
|
|
|
2017-07-12 12:16:13 +02:00
|
|
|
this.previewPath = hash.previewPath
|
2020-09-17 09:20:52 +02:00
|
|
|
this.previewUrl = this.previewPath
|
|
|
|
? hash.previewUrl || (absoluteAPIUrl + hash.previewPath)
|
|
|
|
: null
|
2020-01-29 13:59:40 +01:00
|
|
|
|
2017-10-16 10:05:49 +02:00
|
|
|
this.embedPath = hash.embedPath
|
2020-07-10 11:13:41 +02:00
|
|
|
this.embedUrl = hash.embedUrl || (getAbsoluteEmbedUrl() + hash.embedPath)
|
2020-05-29 16:16:24 +02:00
|
|
|
|
|
|
|
this.url = hash.url
|
2020-01-29 13:59:40 +01:00
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
this.views = hash.views
|
2021-11-09 10:11:20 +01:00
|
|
|
this.viewers = hash.viewers
|
2017-06-16 14:32:15 +02:00
|
|
|
this.likes = hash.likes
|
|
|
|
this.dislikes = hash.dislikes
|
2020-01-29 13:59:40 +01:00
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
this.nsfw = hash.nsfw
|
2020-01-29 13:59:40 +01:00
|
|
|
|
2018-03-12 11:06:15 +01:00
|
|
|
this.account = hash.account
|
2018-06-29 14:34:04 +02:00
|
|
|
this.channel = hash.channel
|
2016-05-27 17:49:18 +02:00
|
|
|
|
2018-08-21 16:18:59 +02:00
|
|
|
this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
|
|
|
|
this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host)
|
2018-06-06 16:46:42 +02:00
|
|
|
|
|
|
|
this.category.label = peertubeTranslate(this.category.label, translations)
|
|
|
|
this.licence.label = peertubeTranslate(this.licence.label, translations)
|
|
|
|
this.language.label = peertubeTranslate(this.language.label, translations)
|
|
|
|
this.privacy.label = peertubeTranslate(this.privacy.label, translations)
|
2018-06-12 20:04:58 +02:00
|
|
|
|
2018-06-15 16:52:15 +02:00
|
|
|
this.scheduledUpdate = hash.scheduledUpdate
|
2019-03-06 15:36:44 +01:00
|
|
|
this.originallyPublishedAt = hash.originallyPublishedAt ? new Date(hash.originallyPublishedAt.toString()) : null
|
|
|
|
|
2018-06-12 20:04:58 +02:00
|
|
|
if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
|
2018-08-14 09:08:47 +02:00
|
|
|
|
|
|
|
this.blacklisted = hash.blacklisted
|
2021-10-27 14:37:04 +02:00
|
|
|
this.blacklistedReason = hash.blacklistedReason
|
|
|
|
|
|
|
|
this.blockedOwner = hash.blockedOwner
|
|
|
|
this.blockedServer = hash.blockedServer
|
2018-10-05 11:15:06 +02:00
|
|
|
|
2021-10-29 10:54:27 +02:00
|
|
|
this.streamingPlaylists = hash.streamingPlaylists
|
|
|
|
this.files = hash.files
|
|
|
|
|
2018-10-05 11:15:06 +02:00
|
|
|
this.userHistory = hash.userHistory
|
2020-01-29 13:59:40 +01:00
|
|
|
|
|
|
|
this.originInstanceHost = this.account.host
|
|
|
|
this.originInstanceUrl = 'https://' + this.originInstanceHost
|
2020-08-20 16:18:16 +02:00
|
|
|
|
|
|
|
this.pluginData = hash.pluginData
|
2016-05-21 18:03:34 +02:00
|
|
|
}
|
|
|
|
|
2021-06-04 13:31:41 +02:00
|
|
|
isVideoNSFWForUser (user: User, serverConfig: HTMLServerConfig) {
|
2018-04-19 11:01:34 +02:00
|
|
|
// Video is not NSFW, skip
|
|
|
|
if (this.nsfw === false) return false
|
|
|
|
|
|
|
|
// Return user setting if logged in
|
|
|
|
if (user) return user.nsfwPolicy !== 'display'
|
|
|
|
|
|
|
|
// Return default instance config
|
|
|
|
return serverConfig.instance.defaultNSFWPolicy !== 'display'
|
2017-04-04 21:37:03 +02:00
|
|
|
}
|
2019-04-05 10:52:27 +02:00
|
|
|
|
|
|
|
isRemovableBy (user: AuthUser) {
|
|
|
|
return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
|
|
|
|
}
|
|
|
|
|
2020-06-02 20:50:42 +02:00
|
|
|
isBlockableBy (user: AuthUser) {
|
2020-06-09 16:07:10 +02:00
|
|
|
return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
|
2019-04-05 10:52:27 +02:00
|
|
|
}
|
|
|
|
|
2020-06-02 20:50:42 +02:00
|
|
|
isUnblockableBy (user: AuthUser) {
|
2020-06-09 16:07:10 +02:00
|
|
|
return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
|
2019-04-05 10:52:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
isUpdatableBy (user: AuthUser) {
|
|
|
|
return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
|
|
|
|
}
|
2020-01-10 10:11:28 +01:00
|
|
|
|
2021-11-18 14:35:08 +01:00
|
|
|
canRemoveFiles (user: AuthUser) {
|
2021-11-19 08:33:18 +01:00
|
|
|
return this.isLocal &&
|
|
|
|
user.hasRight(UserRight.MANAGE_VIDEO_FILES) &&
|
2021-11-18 14:35:08 +01:00
|
|
|
this.state.id !== VideoState.TO_TRANSCODE &&
|
|
|
|
this.hasHLS() &&
|
|
|
|
this.hasWebTorrent()
|
|
|
|
}
|
|
|
|
|
|
|
|
canRunTranscoding (user: AuthUser) {
|
2021-11-19 08:33:18 +01:00
|
|
|
return this.isLocal &&
|
|
|
|
user.hasRight(UserRight.RUN_VIDEO_TRANSCODING) &&
|
2021-11-18 14:35:08 +01:00
|
|
|
this.state.id !== VideoState.TO_TRANSCODE
|
|
|
|
}
|
|
|
|
|
2021-11-17 16:04:53 +01:00
|
|
|
hasHLS () {
|
|
|
|
return this.streamingPlaylists?.some(p => p.type === VideoStreamingPlaylistType.HLS)
|
|
|
|
}
|
|
|
|
|
|
|
|
hasWebTorrent () {
|
|
|
|
return this.files && this.files.length !== 0
|
|
|
|
}
|
|
|
|
|
2020-11-05 10:56:23 +01:00
|
|
|
isLiveInfoAvailableBy (user: AuthUser) {
|
|
|
|
return this.isLive &&
|
|
|
|
user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.GET_ANY_LIVE))
|
|
|
|
}
|
|
|
|
|
2020-01-10 10:11:28 +01:00
|
|
|
canBeDuplicatedBy (user: AuthUser) {
|
|
|
|
return user && this.isLocal === false && user.hasRight(UserRight.MANAGE_VIDEOS_REDUNDANCIES)
|
|
|
|
}
|
2020-11-27 15:57:38 +01:00
|
|
|
|
|
|
|
getExactNumberOfViews () {
|
|
|
|
if (this.views < 1000) return ''
|
|
|
|
|
|
|
|
if (this.isLive) {
|
|
|
|
return $localize`${this.views} viewers`
|
|
|
|
}
|
|
|
|
|
|
|
|
return $localize`${this.views} views`
|
|
|
|
}
|
2016-05-21 18:03:34 +02:00
|
|
|
}
|