+import { uuidToShort } from '@server/helpers/uuid'
import { generateMagnetUri } from '@server/helpers/webtorrent'
-import { getLocalVideoFileMetadataUrl } from '@server/lib/video-paths'
+import { getLocalVideoFileMetadataUrl } from '@server/lib/video-urls'
import { VideoFile } from '@shared/models/videos/video-file.model'
import { ActivityTagObject, ActivityUrlObject, VideoObject } from '../../../../shared/models/activitypub/objects'
import { Video, VideoDetails } from '../../../../shared/models/videos'
import { VideoStreamingPlaylist } from '../../../../shared/models/videos/video-streaming-playlist.model'
import { isArray } from '../../../helpers/custom-validators/misc'
-import { MIMETYPES, WEBSERVER } from '../../../initializers/constants'
+import {
+ MIMETYPES,
+ VIDEO_CATEGORIES,
+ VIDEO_LANGUAGES,
+ VIDEO_LICENCES,
+ VIDEO_PRIVACIES,
+ VIDEO_STATES,
+ WEBSERVER
+} from '../../../initializers/constants'
import {
getLocalVideoCommentsActivityPubUrl,
getLocalVideoDislikesActivityPubUrl,
MVideoFormattableDetails
} from '../../../types/models'
import { MVideoFileRedundanciesOpt } from '../../../types/models/video/video-file'
-import { VideoModel } from '../video'
import { VideoCaptionModel } from '../video-caption'
export type VideoFormattingJSONOptions = {
const videoObject: Video = {
id: video.id,
uuid: video.uuid,
+ shortUUID: uuidToShort(video.uuid),
+
name: video.name,
category: {
id: video.category,
- label: VideoModel.getCategoryLabel(video.category)
+ label: getCategoryLabel(video.category)
},
licence: {
id: video.licence,
- label: VideoModel.getLicenceLabel(video.licence)
+ label: getLicenceLabel(video.licence)
},
language: {
id: video.language,
- label: VideoModel.getLanguageLabel(video.language)
+ label: getLanguageLabel(video.language)
},
privacy: {
id: video.privacy,
- label: VideoModel.getPrivacyLabel(video.privacy)
+ label: getPrivacyLabel(video.privacy)
},
nsfw: video.nsfw,
if (options.additionalAttributes.state === true) {
videoObject.state = {
id: video.state,
- label: VideoModel.getStateLabel(video.state)
+ label: getStateLabel(video.state)
}
}
waitTranscoding: video.waitTranscoding,
state: {
id: video.state,
- label: VideoModel.getStateLabel(video.state)
+ label: getStateLabel(video.state)
},
trackerUrls: video.getTrackerUrls(),
return {
id: playlist.id,
type: playlist.type,
- playlistUrl: playlist.playlistUrl,
- segmentsSha256Url: playlist.segmentsSha256Url,
+ playlistUrl: playlist.getMasterPlaylistUrl(video),
+ segmentsSha256Url: playlist.getSha256SegmentsUrl(video),
redundancies,
files
}
? video.getTrackerUrls()
: []
- return [ ...videoFiles ]
+ return (videoFiles || [])
.filter(f => !f.isLive())
.sort(sortByResolutionDesc)
.map(videoFile => {
return {
resolution: {
id: videoFile.resolution,
- label: videoFile.resolution + 'p'
+ label: videoFile.resolution === 0 ? 'Audio' : `${videoFile.resolution}p`
},
magnetUri: includeMagnet && videoFile.hasTorrent()
) {
const trackerUrls = video.getTrackerUrls()
- const sortedFiles = [ ...files ]
+ const sortedFiles = (files || [])
.filter(f => !f.isLive())
.sort(sortByResolutionDesc)
if (video.language) {
language = {
identifier: video.language,
- name: VideoModel.getLanguageLabel(video.language)
+ name: getLanguageLabel(video.language)
}
}
if (video.category) {
category = {
identifier: video.category + '',
- name: VideoModel.getCategoryLabel(video.category)
+ name: getCategoryLabel(video.category)
}
}
if (video.licence) {
licence = {
identifier: video.licence + '',
- name: VideoModel.getLicenceLabel(video.licence)
+ name: getLicenceLabel(video.licence)
}
}
type: 'Link',
name: 'sha256',
mediaType: 'application/json' as 'application/json',
- href: playlist.segmentsSha256Url
+ href: playlist.getSha256SegmentsUrl(video)
})
addVideoFilesInAPAcc(tag, video, playlist.VideoFiles || [])
url.push({
type: 'Link',
mediaType: 'application/x-mpegURL' as 'application/x-mpegURL',
- href: playlist.playlistUrl,
+ href: playlist.getMasterPlaylistUrl(video),
tag
})
}
return 'PT' + duration + 'S'
}
+function getCategoryLabel (id: number) {
+ return VIDEO_CATEGORIES[id] || 'Misc'
+}
+
+function getLicenceLabel (id: number) {
+ return VIDEO_LICENCES[id] || 'Unknown'
+}
+
+function getLanguageLabel (id: string) {
+ return VIDEO_LANGUAGES[id] || 'Unknown'
+}
+
+function getPrivacyLabel (id: number) {
+ return VIDEO_PRIVACIES[id] || 'Unknown'
+}
+
+function getStateLabel (id: number) {
+ return VIDEO_STATES[id] || 'Unknown'
+}
+
export {
videoModelToFormattedJSON,
videoModelToFormattedDetailsJSON,
videoFilesModelToFormattedJSON,
videoModelToActivityPubObject,
- getActivityStreamDuration
+ getActivityStreamDuration,
+
+ getCategoryLabel,
+ getLicenceLabel,
+ getLanguageLabel,
+ getPrivacyLabel,
+ getStateLabel
}