-import { uuidToShort } from '@shared/core-utils/uuid'
import { generateMagnetUri } from '@server/helpers/webtorrent'
+import { getActivityStreamDuration } from '@server/lib/activitypub/activity'
+import { tracer } from '@server/lib/opentelemetry/tracing'
import { getLocalVideoFileMetadataUrl } from '@server/lib/video-urls'
-import { VideoViews } from '@server/lib/video-views'
-import { VideoFile, VideosCommonQueryAfterSanitize } from '@shared/models'
-import { ActivityTagObject, ActivityUrlObject, VideoObject } from '../../../../shared/models/activitypub/objects'
-import { Video, VideoDetails, VideoInclude } from '../../../../shared/models/videos'
-import { VideoStreamingPlaylist } from '../../../../shared/models/videos/video-streaming-playlist.model'
+import { VideoViewsManager } from '@server/lib/views/video-views-manager'
+import { uuidToShort } from '@shared/extra-utils'
+import {
+ ActivityTagObject,
+ ActivityUrlObject,
+ Video,
+ VideoDetails,
+ VideoFile,
+ VideoInclude,
+ VideoObject,
+ VideosCommonQueryAfterSanitize,
+ VideoStreamingPlaylist
+} from '@shared/models'
import { isArray } from '../../../helpers/custom-validators/misc'
import {
MIMETYPES,
}
function videoModelToFormattedJSON (video: MVideoFormattable, options: VideoFormattingJSONOptions = {}): Video {
+ const span = tracer.startSpan('peertube.VideoModel.toFormattedJSON')
+
const userHistory = isArray(video.UserVideoHistories) ? video.UserVideoHistories[0] : undefined
const videoObject: Video = {
isLocal: video.isOwned(),
duration: video.duration,
+
views: video.views,
+ viewers: VideoViewsManager.Instance.getViewers(video),
+
likes: video.likes,
dislikes: video.dislikes,
thumbnailPath: video.getMiniatureStaticPath(),
pluginData: (video as any).pluginData
}
- if (video.isLive) {
- videoObject.viewers = VideoViews.Instance.getViewers(video)
- }
-
const add = options.additionalAttributes
if (add?.state === true) {
videoObject.state = {
videoObject.files = videoFilesModelToFormattedJSON(video, video.VideoFiles)
}
+ span.end()
+
return videoObject
}
function videoModelToFormattedDetailsJSON (video: MVideoFormattableDetails): VideoDetails {
+ const span = tracer.startSpan('peertube.VideoModel.toFormattedDetailsJSON')
+
const videoJSON = video.toFormattedJSON({
additionalAttributes: {
scheduledUpdate: true,
trackerUrls: video.getTrackerUrls()
}
+ span.end()
+
return Object.assign(videoJSON, detailsJSON)
}
.sort(sortByResolutionDesc)
.map(videoFile => {
return {
+ id: videoFile.id,
+
resolution: {
id: videoFile.resolution,
label: videoFile.resolution === 0 ? 'Audio' : `${videoFile.resolution}p`
views: video.views,
sensitive: video.nsfw,
waitTranscoding: video.waitTranscoding,
- isLiveBroadcast: video.isLive,
-
- liveSaveReplay: video.isLive
- ? video.VideoLive.saveReplay
- : null,
-
- permanentLive: video.isLive
- ? video.VideoLive.permanentLive
- : null,
state: video.state,
commentsEnabled: video.commentsEnabled,
: null,
updated: video.updatedAt.toISOString(),
+
mediaType: 'text/markdown',
content: video.description,
support: video.support,
+
subtitleLanguage,
+
icon: icons.map(i => ({
type: 'Image',
url: i.getFileUrl(video),
width: i.width,
height: i.height
})),
+
url,
+
likes: getLocalVideoLikesActivityPubUrl(video),
dislikes: getLocalVideoDislikesActivityPubUrl(video),
shares: getLocalVideoSharesActivityPubUrl(video),
comments: getLocalVideoCommentsActivityPubUrl(video),
+
attributedTo: [
{
type: 'Person',
type: 'Group',
id: video.VideoChannel.Actor.url
}
- ]
- }
-}
+ ],
-function getActivityStreamDuration (duration: number) {
- // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration
- return 'PT' + duration + 'S'
+ ...buildLiveAPAttributes(video)
+ }
}
function getCategoryLabel (id: number) {
videoModelToFormattedDetailsJSON,
videoFilesModelToFormattedJSON,
videoModelToActivityPubObject,
- getActivityStreamDuration,
guessAdditionalAttributesFromQuery,
getPrivacyLabel,
getStateLabel
}
+
+// ---------------------------------------------------------------------------
+
+function buildLiveAPAttributes (video: MVideoAP) {
+ if (!video.isLive) {
+ return {
+ isLiveBroadcast: false,
+ liveSaveReplay: null,
+ permanentLive: null,
+ latencyMode: null
+ }
+ }
+
+ return {
+ isLiveBroadcast: true,
+ liveSaveReplay: video.VideoLive.saveReplay,
+ permanentLive: video.VideoLive.permanentLive,
+ latencyMode: video.VideoLive.latencyMode
+ }
+}