- const formattedJson = this.toFormattedJSON()
-
- // Maybe our server is not up to date and there are new privacy settings since our version
- let privacyLabel = VIDEO_PRIVACIES[this.privacy]
- if (!privacyLabel) privacyLabel = 'Unknown'
-
- const detailsJson = {
- privacy: {
- id: this.privacy,
- label: privacyLabel
- },
- support: this.support,
- descriptionPath: this.getDescriptionPath(),
- channel: this.VideoChannel.toFormattedJSON(),
- account: this.VideoChannel.Account.toFormattedJSON(),
- tags: map<TagModel, string>(this.Tags, 'name'),
- commentsEnabled: this.commentsEnabled,
- files: []
- }
-
- // Format and sort video files
- const { baseUrlHttp, baseUrlWs } = this.getBaseUrls()
- detailsJson.files = this.VideoFiles
- .map(videoFile => {
- let resolutionLabel = videoFile.resolution + 'p'
-
- return {
- resolution: {
- id: videoFile.resolution,
- label: resolutionLabel
- },
- magnetUri: this.generateMagnetUri(videoFile, baseUrlHttp, baseUrlWs),
- size: videoFile.size,
- torrentUrl: this.getTorrentUrl(videoFile, baseUrlHttp),
- fileUrl: this.getVideoFileUrl(videoFile, baseUrlHttp)
- }
- })
- .sort((a, b) => {
- if (a.resolution.id < b.resolution.id) return 1
- if (a.resolution.id === b.resolution.id) return 0
- return -1
- })
-
- return Object.assign(formattedJson, detailsJson)
- }
-
- toActivityPubObject (): VideoTorrentObject {
- const { baseUrlHttp, baseUrlWs } = this.getBaseUrls()
- if (!this.Tags) this.Tags = []
-
- const tag = this.Tags.map(t => ({
- type: 'Hashtag' as 'Hashtag',
- name: t.name
- }))
-
- let language
- if (this.language) {
- language = {
- identifier: this.language + '',
- name: VideoModel.getLanguageLabel(this.language)
- }
- }
-
- let category
- if (this.category) {
- category = {
- identifier: this.category + '',
- name: VideoModel.getCategoryLabel(this.category)
- }
- }
-
- let licence
- if (this.licence) {
- licence = {
- identifier: this.licence + '',
- name: VideoModel.getLicenceLabel(this.licence)
- }
- }
-
- let likesObject
- let dislikesObject
-
- if (Array.isArray(this.AccountVideoRates)) {
- const res = this.toRatesActivityPubObjects()
- likesObject = res.likesObject
- dislikesObject = res.dislikesObject
- }
-
- let sharesObject
- if (Array.isArray(this.VideoShares)) {
- sharesObject = this.toAnnouncesActivityPubObject()
- }
-
- let commentsObject
- if (Array.isArray(this.VideoComments)) {
- commentsObject = this.toCommentsActivityPubObject()
- }
-
- const url = []
- for (const file of this.VideoFiles) {
- url.push({
- type: 'Link',
- mimeType: 'video/' + file.extname.replace('.', ''),
- href: this.getVideoFileUrl(file, baseUrlHttp),
- width: file.resolution,
- size: file.size
- })
-
- url.push({
- type: 'Link',
- mimeType: 'application/x-bittorrent',
- href: this.getTorrentUrl(file, baseUrlHttp),
- width: file.resolution
- })
-
- url.push({
- type: 'Link',
- mimeType: 'application/x-bittorrent;x-scheme-handler/magnet',
- href: this.generateMagnetUri(file, baseUrlHttp, baseUrlWs),
- width: file.resolution
- })
- }
-
- // Add video url too
- url.push({
- type: 'Link',
- mimeType: 'text/html',
- href: CONFIG.WEBSERVER.URL + '/videos/watch/' + this.uuid
- })
-
- return {
- type: 'Video' as 'Video',
- id: this.url,
- name: this.name,
- duration: this.getActivityStreamDuration(),
- uuid: this.uuid,
- tag,
- category,
- licence,
- language,
- views: this.views,
- sensitive: this.nsfw,
- commentsEnabled: this.commentsEnabled,
- published: this.createdAt.toISOString(),
- updated: this.updatedAt.toISOString(),
- mediaType: 'text/markdown',
- content: this.getTruncatedDescription(),
- support: this.support,
- icon: {
- type: 'Image',
- url: this.getThumbnailUrl(baseUrlHttp),
- mediaType: 'image/jpeg',
- width: THUMBNAILS_SIZE.width,
- height: THUMBNAILS_SIZE.height
- },
- url,
- likes: likesObject,
- dislikes: dislikesObject,
- shares: sharesObject,
- comments: commentsObject,
- attributedTo: [
- {
- type: 'Person',
- id: this.VideoChannel.Account.Actor.url
- },
- {
- type: 'Group',
- id: this.VideoChannel.Actor.url
- }
- ]
- }
- }
-
- toAnnouncesActivityPubObject () {
- const shares: string[] = []
-
- for (const videoShare of this.VideoShares) {
- shares.push(videoShare.url)
- }
-
- return activityPubCollection(getVideoSharesActivityPubUrl(this), shares)