X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Flib%2Factivitypub%2Fvideos%2Fshared%2Fobject-to-model-attributes.ts;h=1fa16295d4402a07871054de78db9c0a2a673858;hb=764b1a14fc494f2cfd7ea590d2f07b01df65c7ad;hp=8a81055005cd4a8b0de9ca03485b101de9ab9d7f;hpb=69290ab37b8aead01477b9b98fdfad0e69b08582;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/videos/shared/object-to-model-attributes.ts b/server/lib/activitypub/videos/shared/object-to-model-attributes.ts index 8a8105500..1fa16295d 100644 --- a/server/lib/activitypub/videos/shared/object-to-model-attributes.ts +++ b/server/lib/activitypub/videos/shared/object-to-model-attributes.ts @@ -7,10 +7,11 @@ import { logger } from '@server/helpers/logger' import { getExtFromMimetype } from '@server/helpers/video' import { ACTIVITY_PUB, MIMETYPES, P2P_MEDIA_LOADER_PEER_VERSION, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '@server/initializers/constants' import { generateTorrentFileName } from '@server/lib/video-paths' +import { VideoCaptionModel } from '@server/models/video/video-caption' import { VideoFileModel } from '@server/models/video/video-file' import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' import { FilteredModelAttributes } from '@server/types' -import { MChannelId, MStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoId } from '@server/types/models' +import { isStreamingPlaylist, MChannelId, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoId } from '@server/types/models' import { ActivityHashTagObject, ActivityMagnetUrlObject, @@ -44,7 +45,7 @@ function getTagsFromObject (videoObject: VideoObject) { .map(t => t.name) } -function videoFileActivityUrlToDBAttributes ( +function getFileAttributesFromUrl ( videoOrPlaylist: MVideo | MStreamingPlaylistVideo, urls: (ActivityTagObject | ActivityUrlObject)[] ) { @@ -79,8 +80,8 @@ function videoFileActivityUrlToDBAttributes ( const extname = getExtFromMimetype(MIMETYPES.VIDEO.MIMETYPE_EXT, fileUrl.mediaType) const resolution = fileUrl.height - const videoId = (videoOrPlaylist as MStreamingPlaylist).playlistUrl ? null : videoOrPlaylist.id - const videoStreamingPlaylistId = (videoOrPlaylist as MStreamingPlaylist).playlistUrl ? videoOrPlaylist.id : null + const videoId = isStreamingPlaylist(videoOrPlaylist) ? null : videoOrPlaylist.id + const videoStreamingPlaylistId = isStreamingPlaylist(videoOrPlaylist) ? videoOrPlaylist.id : null const attribute = { extname, @@ -109,7 +110,7 @@ function videoFileActivityUrlToDBAttributes ( return attributes } -function streamingPlaylistActivityUrlToDBAttributes (video: MVideoId, videoObject: VideoObject, videoFiles: MVideoFile[]) { +function getStreamingPlaylistAttributesFromObject (video: MVideoId, videoObject: VideoObject, videoFiles: MVideoFile[]) { const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) as ActivityPlaylistUrlObject[] if (playlistUrls.length === 0) return [] @@ -129,11 +130,17 @@ function streamingPlaylistActivityUrlToDBAttributes (video: MVideoId, videoObjec const attribute = { type: VideoStreamingPlaylistType.HLS, + + playlistFilename: basename(playlistUrlObject.href), playlistUrl: playlistUrlObject.href, + + segmentsSha256Filename: basename(segmentsSha256UrlObject.href), segmentsSha256Url: segmentsSha256UrlObject.href, + p2pMediaLoaderInfohashes: VideoStreamingPlaylistModel.buildP2PMediaLoaderInfoHashes(playlistUrlObject.href, files), p2pMediaLoaderPeerVersion: P2P_MEDIA_LOADER_PEER_VERSION, videoId: video.id, + tagAPObject: playlistUrlObject.tag } @@ -143,7 +150,24 @@ function streamingPlaylistActivityUrlToDBAttributes (video: MVideoId, videoObjec return attributes } -function videoActivityObjectToDBAttributes (videoChannel: MChannelId, videoObject: VideoObject, to: string[] = []) { +function getLiveAttributesFromObject (video: MVideoId, videoObject: VideoObject) { + return { + saveReplay: videoObject.liveSaveReplay, + permanentLive: videoObject.permanentLive, + videoId: video.id + } +} + +function getCaptionAttributesFromObject (video: MVideoId, videoObject: VideoObject) { + return videoObject.subtitleLanguage.map(c => ({ + videoId: video.id, + filename: VideoCaptionModel.generateCaptionName(c.identifier), + language: c.identifier, + fileUrl: c.url + })) +} + +function getVideoAttributesFromObject (videoChannel: MChannelId, videoObject: VideoObject, to: string[] = []) { const privacy = to.includes(ACTIVITY_PUB.PUBLIC) ? VideoPrivacy.PUBLIC : VideoPrivacy.UNLISTED @@ -203,10 +227,13 @@ export { getTagsFromObject, - videoActivityObjectToDBAttributes, + getFileAttributesFromUrl, + getStreamingPlaylistAttributesFromObject, + + getLiveAttributesFromObject, + getCaptionAttributesFromObject, - videoFileActivityUrlToDBAttributes, - streamingPlaylistActivityUrlToDBAttributes + getVideoAttributesFromObject } // ---------------------------------------------------------------------------