1 import * as Bluebird from 'bluebird'
2 import * as sequelize from 'sequelize'
3 import * as magnetUtil from 'magnet-uri'
4 import * as request from 'request'
6 ActivityPlaylistSegmentHashesObject,
7 ActivityPlaylistUrlObject,
9 ActivityVideoUrlObject,
11 } from '../../../shared/index'
12 import { VideoTorrentObject } from '../../../shared/models/activitypub/objects'
13 import { VideoPrivacy } from '../../../shared/models/videos'
14 import { sanitizeAndCheckVideoTorrentObject } from '../../helpers/custom-validators/activitypub/videos'
15 import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos'
16 import { resetSequelizeInstance, retryTransactionWrapper } from '../../helpers/database-utils'
17 import { logger } from '../../helpers/logger'
18 import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests'
22 P2P_MEDIA_LOADER_PEER_VERSION,
26 } from '../../initializers/constants'
27 import { ActorModel } from '../../models/activitypub/actor'
28 import { TagModel } from '../../models/video/tag'
29 import { VideoModel } from '../../models/video/video'
30 import { VideoChannelModel } from '../../models/video/video-channel'
31 import { VideoFileModel } from '../../models/video/video-file'
32 import { getOrCreateActorAndServerAndModel } from './actor'
33 import { addVideoComments } from './video-comments'
34 import { crawlCollectionPage } from './crawl'
35 import { sendCreateVideo, sendUpdateVideo } from './send'
36 import { isArray } from '../../helpers/custom-validators/misc'
37 import { VideoCaptionModel } from '../../models/video/video-caption'
38 import { JobQueue } from '../job-queue'
39 import { ActivitypubHttpFetcherPayload } from '../job-queue/handlers/activitypub-http-fetcher'
40 import { createRates } from './video-rates'
41 import { addVideoShares, shareVideoByServerAndChannel } from './share'
42 import { AccountModel } from '../../models/account/account'
43 import { fetchVideoByUrl, VideoFetchByUrlType } from '../../helpers/video'
44 import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub'
45 import { Notifier } from '../notifier'
46 import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-playlist'
47 import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
48 import { AccountVideoRateModel } from '../../models/account/account-video-rate'
49 import { VideoShareModel } from '../../models/video/video-share'
50 import { VideoCommentModel } from '../../models/video/video-comment'
51 import { sequelizeTypescript } from '../../initializers/database'
52 import { createPlaceholderThumbnail, createVideoMiniatureFromUrl } from '../thumbnail'
53 import { ThumbnailModel } from '../../models/video/thumbnail'
54 import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
55 import { join } from 'path'
56 import { FilteredModelAttributes } from '../../typings/sequelize'
57 import { Hooks } from '../plugins/hooks'
58 import { autoBlacklistVideoIfNeeded } from '../video-blacklist'
59 import { ActorFollowScoreCache } from '../files-cache'
61 async function federateVideoIfNeeded (video: VideoModel, isNewVideo: boolean, transaction?: sequelize.Transaction) {
63 // Check this is not a blacklisted video, or unfederated blacklisted video
64 (video.isBlacklisted() === false || (isNewVideo === false && video.VideoBlacklist.unfederated === false)) &&
65 // Check the video is public/unlisted and published
66 video.privacy !== VideoPrivacy.PRIVATE && video.state === VideoState.PUBLISHED
68 // Fetch more attributes that we will need to serialize in AP object
69 if (isArray(video.VideoCaptions) === false) {
70 video.VideoCaptions = await video.$get('VideoCaptions', {
71 attributes: [ 'language' ],
73 }) as VideoCaptionModel[]
77 // Now we'll add the video's meta data to our followers
78 await sendCreateVideo(video, transaction)
79 await shareVideoByServerAndChannel(video, transaction)
81 await sendUpdateVideo(video, transaction)
86 async function fetchRemoteVideo (videoUrl: string): Promise<{ response: request.RequestResponse, videoObject: VideoTorrentObject }> {
94 logger.info('Fetching remote video %s.', videoUrl)
96 const { response, body } = await doRequest(options)
98 if (sanitizeAndCheckVideoTorrentObject(body) === false || checkUrlsSameHost(body.id, videoUrl) !== true) {
99 logger.debug('Remote video JSON is not valid.', { body })
100 return { response, videoObject: undefined }
103 return { response, videoObject: body }
106 async function fetchRemoteVideoDescription (video: VideoModel) {
107 const host = video.VideoChannel.Account.Actor.Server.host
108 const path = video.getDescriptionAPIPath()
110 uri: REMOTE_SCHEME.HTTP + '://' + host + path,
114 const { body } = await doRequest(options)
115 return body.description ? body.description : ''
118 function fetchRemoteVideoStaticFile (video: VideoModel, path: string, destPath: string) {
119 const url = buildRemoteBaseUrl(video, path)
121 // We need to provide a callback, if no we could have an uncaught exception
122 return doRequestAndSaveToFile({ uri: url }, destPath)
125 function buildRemoteBaseUrl (video: VideoModel, path: string) {
126 const host = video.VideoChannel.Account.Actor.Server.host
128 return REMOTE_SCHEME.HTTP + '://' + host + path
131 function getOrCreateVideoChannelFromVideoObject (videoObject: VideoTorrentObject) {
132 const channel = videoObject.attributedTo.find(a => a.type === 'Group')
133 if (!channel) throw new Error('Cannot find associated video channel to video ' + videoObject.url)
135 if (checkUrlsSameHost(channel.id, videoObject.id) !== true) {
136 throw new Error(`Video channel url ${channel.id} does not have the same host than video object id ${videoObject.id}`)
139 return getOrCreateActorAndServerAndModel(channel.id, 'all')
148 refreshVideo?: boolean
150 async function syncVideoExternalAttributes (video: VideoModel, fetchedVideo: VideoTorrentObject, syncParam: SyncParam) {
151 logger.info('Adding likes/dislikes/shares/comments of video %s.', video.uuid)
153 const jobPayloads: ActivitypubHttpFetcherPayload[] = []
155 if (syncParam.likes === true) {
156 const handler = items => createRates(items, video, 'like')
157 const cleaner = crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'like' as 'like', crawlStartDate)
159 await crawlCollectionPage<string>(fetchedVideo.likes, handler, cleaner)
160 .catch(err => logger.error('Cannot add likes of video %s.', video.uuid, { err }))
162 jobPayloads.push({ uri: fetchedVideo.likes, videoId: video.id, type: 'video-likes' as 'video-likes' })
165 if (syncParam.dislikes === true) {
166 const handler = items => createRates(items, video, 'dislike')
167 const cleaner = crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'dislike' as 'dislike', crawlStartDate)
169 await crawlCollectionPage<string>(fetchedVideo.dislikes, handler, cleaner)
170 .catch(err => logger.error('Cannot add dislikes of video %s.', video.uuid, { err }))
172 jobPayloads.push({ uri: fetchedVideo.dislikes, videoId: video.id, type: 'video-dislikes' as 'video-dislikes' })
175 if (syncParam.shares === true) {
176 const handler = items => addVideoShares(items, video)
177 const cleaner = crawlStartDate => VideoShareModel.cleanOldSharesOf(video.id, crawlStartDate)
179 await crawlCollectionPage<string>(fetchedVideo.shares, handler, cleaner)
180 .catch(err => logger.error('Cannot add shares of video %s.', video.uuid, { err }))
182 jobPayloads.push({ uri: fetchedVideo.shares, videoId: video.id, type: 'video-shares' as 'video-shares' })
185 if (syncParam.comments === true) {
186 const handler = items => addVideoComments(items)
187 const cleaner = crawlStartDate => VideoCommentModel.cleanOldCommentsOf(video.id, crawlStartDate)
189 await crawlCollectionPage<string>(fetchedVideo.comments, handler, cleaner)
190 .catch(err => logger.error('Cannot add comments of video %s.', video.uuid, { err }))
192 jobPayloads.push({ uri: fetchedVideo.comments, videoId: video.id, type: 'video-comments' as 'video-comments' })
195 await Bluebird.map(jobPayloads, payload => JobQueue.Instance.createJob({ type: 'activitypub-http-fetcher', payload }))
198 async function getOrCreateVideoAndAccountAndChannel (options: {
199 videoObject: { id: string } | string,
200 syncParam?: SyncParam,
201 fetchType?: VideoFetchByUrlType,
202 allowRefresh?: boolean // true by default
205 const syncParam = options.syncParam || { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true, refreshVideo: false }
206 const fetchType = options.fetchType || 'all'
207 const allowRefresh = options.allowRefresh !== false
210 const videoUrl = getAPId(options.videoObject)
212 let videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType)
213 if (videoFromDatabase) {
214 if (videoFromDatabase.isOutdated() && allowRefresh === true) {
215 const refreshOptions = {
216 video: videoFromDatabase,
217 fetchedType: fetchType,
221 if (syncParam.refreshVideo === true) videoFromDatabase = await refreshVideoIfNeeded(refreshOptions)
222 else await JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: videoFromDatabase.url } })
225 return { video: videoFromDatabase, created: false }
228 const { videoObject: fetchedVideo } = await fetchRemoteVideo(videoUrl)
229 if (!fetchedVideo) throw new Error('Cannot fetch remote video with url: ' + videoUrl)
231 const channelActor = await getOrCreateVideoChannelFromVideoObject(fetchedVideo)
232 const { autoBlacklisted, videoCreated } = await retryTransactionWrapper(createVideo, fetchedVideo, channelActor, syncParam.thumbnail)
234 await syncVideoExternalAttributes(videoCreated, fetchedVideo, syncParam)
236 return { video: videoCreated, created: true, autoBlacklisted }
239 async function updateVideoFromAP (options: {
241 videoObject: VideoTorrentObject,
242 account: AccountModel,
243 channel: VideoChannelModel,
244 overrideTo?: string[]
246 const { video, videoObject, account, channel, overrideTo } = options
248 logger.debug('Updating remote video "%s".', options.videoObject.uuid)
250 let videoFieldsSave: any
251 const wasPrivateVideo = video.privacy === VideoPrivacy.PRIVATE
252 const wasUnlistedVideo = video.privacy === VideoPrivacy.UNLISTED
255 let thumbnailModel: ThumbnailModel
258 thumbnailModel = await createVideoMiniatureFromUrl(videoObject.icon.url, video, ThumbnailType.MINIATURE)
260 logger.warn('Cannot generate thumbnail of %s.', videoObject.id, { err })
263 await sequelizeTypescript.transaction(async t => {
264 const sequelizeOptions = { transaction: t }
266 videoFieldsSave = video.toJSON()
268 // Check actor has the right to update the video
269 const videoChannel = video.VideoChannel
270 if (videoChannel.Account.id !== account.id) {
271 throw new Error('Account ' + account.Actor.url + ' does not own video channel ' + videoChannel.Actor.url)
274 const to = overrideTo ? overrideTo : videoObject.to
275 const videoData = await videoActivityObjectToDBAttributes(channel, videoObject, to)
276 video.name = videoData.name
277 video.uuid = videoData.uuid
278 video.url = videoData.url
279 video.category = videoData.category
280 video.licence = videoData.licence
281 video.language = videoData.language
282 video.description = videoData.description
283 video.support = videoData.support
284 video.nsfw = videoData.nsfw
285 video.commentsEnabled = videoData.commentsEnabled
286 video.downloadEnabled = videoData.downloadEnabled
287 video.waitTranscoding = videoData.waitTranscoding
288 video.state = videoData.state
289 video.duration = videoData.duration
290 video.createdAt = videoData.createdAt
291 video.publishedAt = videoData.publishedAt
292 video.originallyPublishedAt = videoData.originallyPublishedAt
293 video.privacy = videoData.privacy
294 video.channelId = videoData.channelId
295 video.views = videoData.views
297 await video.save(sequelizeOptions)
299 if (thumbnailModel) await video.addAndSaveThumbnail(thumbnailModel, t)
301 // FIXME: use icon URL instead
302 const previewUrl = buildRemoteBaseUrl(video, join(STATIC_PATHS.PREVIEWS, video.getPreview().filename))
303 const previewModel = createPlaceholderThumbnail(previewUrl, video, ThumbnailType.PREVIEW, PREVIEWS_SIZE)
304 await video.addAndSaveThumbnail(previewModel, t)
307 const videoFileAttributes = videoFileActivityUrlToDBAttributes(video, videoObject)
308 const newVideoFiles = videoFileAttributes.map(a => new VideoFileModel(a))
310 // Remove video files that do not exist anymore
311 const destroyTasks = video.VideoFiles
312 .filter(f => !newVideoFiles.find(newFile => newFile.hasSameUniqueKeysThan(f)))
313 .map(f => f.destroy(sequelizeOptions))
314 await Promise.all(destroyTasks)
316 // Update or add other one
317 const upsertTasks = videoFileAttributes.map(a => {
318 return VideoFileModel.upsert<VideoFileModel>(a, { returning: true, transaction: t })
319 .then(([ file ]) => file)
322 video.VideoFiles = await Promise.all(upsertTasks)
326 const streamingPlaylistAttributes = streamingPlaylistActivityUrlToDBAttributes(video, videoObject, video.VideoFiles)
327 const newStreamingPlaylists = streamingPlaylistAttributes.map(a => new VideoStreamingPlaylistModel(a))
329 // Remove video files that do not exist anymore
330 const destroyTasks = video.VideoStreamingPlaylists
331 .filter(f => !newStreamingPlaylists.find(newPlaylist => newPlaylist.hasSameUniqueKeysThan(f)))
332 .map(f => f.destroy(sequelizeOptions))
333 await Promise.all(destroyTasks)
335 // Update or add other one
336 const upsertTasks = streamingPlaylistAttributes.map(a => {
337 return VideoStreamingPlaylistModel.upsert<VideoStreamingPlaylistModel>(a, { returning: true, transaction: t })
338 .then(([ streamingPlaylist ]) => streamingPlaylist)
341 video.VideoStreamingPlaylists = await Promise.all(upsertTasks)
346 const tags = videoObject.tag.map(tag => tag.name)
347 const tagInstances = await TagModel.findOrCreateTags(tags, t)
348 await video.$set('Tags', tagInstances, sequelizeOptions)
353 await VideoCaptionModel.deleteAllCaptionsOfRemoteVideo(video.id, t)
355 const videoCaptionsPromises = videoObject.subtitleLanguage.map(c => {
356 return VideoCaptionModel.insertOrReplaceLanguage(video.id, c.identifier, t)
358 video.VideoCaptions = await Promise.all(videoCaptionsPromises)
362 await autoBlacklistVideoIfNeeded({
367 transaction: undefined
370 if (wasPrivateVideo || wasUnlistedVideo) Notifier.Instance.notifyOnNewVideoIfNeeded(video) // Notify our users?
372 logger.info('Remote video with uuid %s updated', videoObject.uuid)
374 if (video !== undefined && videoFieldsSave !== undefined) {
375 resetSequelizeInstance(video, videoFieldsSave)
378 // This is just a debug because we will retry the insert
379 logger.debug('Cannot update the remote video.', { err })
384 async function refreshVideoIfNeeded (options: {
386 fetchedType: VideoFetchByUrlType,
388 }): Promise<VideoModel> {
389 if (!options.video.isOutdated()) return options.video
391 // We need more attributes if the argument video was fetched with not enough joints
392 const video = options.fetchedType === 'all'
394 : await VideoModel.loadByUrlAndPopulateAccount(options.video.url)
397 const { response, videoObject } = await fetchRemoteVideo(video.url)
398 if (response.statusCode === 404) {
399 logger.info('Cannot refresh remote video %s: video does not exist anymore. Deleting it.', video.url)
401 // Video does not exist anymore
402 await video.destroy()
406 if (videoObject === undefined) {
407 logger.warn('Cannot refresh remote video %s: invalid body.', video.url)
409 await video.setAsRefreshed()
413 const channelActor = await getOrCreateVideoChannelFromVideoObject(videoObject)
414 const account = await AccountModel.load(channelActor.VideoChannel.accountId)
416 const updateOptions = {
420 channel: channelActor.VideoChannel
422 await retryTransactionWrapper(updateVideoFromAP, updateOptions)
423 await syncVideoExternalAttributes(video, videoObject, options.syncParam)
425 ActorFollowScoreCache.Instance.addGoodServerId(video.VideoChannel.Actor.serverId)
429 logger.warn('Cannot refresh video %s.', options.video.url, { err })
431 ActorFollowScoreCache.Instance.addBadServerId(video.VideoChannel.Actor.serverId)
433 // Don't refresh in loop
434 await video.setAsRefreshed()
441 refreshVideoIfNeeded,
442 federateVideoIfNeeded,
444 getOrCreateVideoAndAccountAndChannel,
445 fetchRemoteVideoStaticFile,
446 fetchRemoteVideoDescription,
447 getOrCreateVideoChannelFromVideoObject
450 // ---------------------------------------------------------------------------
452 function isAPVideoUrlObject (url: ActivityUrlObject): url is ActivityVideoUrlObject {
453 const mimeTypes = Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT)
455 const urlMediaType = url.mediaType || url.mimeType
456 return mimeTypes.indexOf(urlMediaType) !== -1 && urlMediaType.startsWith('video/')
459 function isAPStreamingPlaylistUrlObject (url: ActivityUrlObject): url is ActivityPlaylistUrlObject {
460 const urlMediaType = url.mediaType || url.mimeType
462 return urlMediaType === 'application/x-mpegURL'
465 function isAPPlaylistSegmentHashesUrlObject (tag: any): tag is ActivityPlaylistSegmentHashesObject {
466 const urlMediaType = tag.mediaType || tag.mimeType
468 return tag.name === 'sha256' && tag.type === 'Link' && urlMediaType === 'application/json'
471 async function createVideo (videoObject: VideoTorrentObject, channelActor: ActorModel, waitThumbnail = false) {
472 logger.debug('Adding remote video %s.', videoObject.id)
474 const videoData = await videoActivityObjectToDBAttributes(channelActor.VideoChannel, videoObject, videoObject.to)
475 const video = VideoModel.build(videoData)
477 const promiseThumbnail = createVideoMiniatureFromUrl(videoObject.icon.url, video, ThumbnailType.MINIATURE)
479 let thumbnailModel: ThumbnailModel
480 if (waitThumbnail === true) {
481 thumbnailModel = await promiseThumbnail
484 const { autoBlacklisted, videoCreated } = await sequelizeTypescript.transaction(async t => {
485 const sequelizeOptions = { transaction: t }
487 const videoCreated = await video.save(sequelizeOptions)
488 videoCreated.VideoChannel = channelActor.VideoChannel
490 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
492 // FIXME: use icon URL instead
493 const previewUrl = buildRemoteBaseUrl(videoCreated, join(STATIC_PATHS.PREVIEWS, video.generatePreviewName()))
494 const previewModel = createPlaceholderThumbnail(previewUrl, video, ThumbnailType.PREVIEW, PREVIEWS_SIZE)
495 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(previewModel, t)
498 const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoCreated, videoObject)
499 if (videoFileAttributes.length === 0) {
500 throw new Error('Cannot find valid files for video %s ' + videoObject.url)
503 const videoFilePromises = videoFileAttributes.map(f => VideoFileModel.create(f, { transaction: t }))
504 const videoFiles = await Promise.all(videoFilePromises)
506 const videoStreamingPlaylists = streamingPlaylistActivityUrlToDBAttributes(videoCreated, videoObject, videoFiles)
507 const playlistPromises = videoStreamingPlaylists.map(p => VideoStreamingPlaylistModel.create(p, { transaction: t }))
508 const streamingPlaylists = await Promise.all(playlistPromises)
511 const tags = videoObject.tag
512 .filter(t => t.type === 'Hashtag')
514 const tagInstances = await TagModel.findOrCreateTags(tags, t)
515 await videoCreated.$set('Tags', tagInstances, sequelizeOptions)
518 const videoCaptionsPromises = videoObject.subtitleLanguage.map(c => {
519 return VideoCaptionModel.insertOrReplaceLanguage(videoCreated.id, c.identifier, t)
521 const captions = await Promise.all(videoCaptionsPromises)
523 video.VideoFiles = videoFiles
524 video.VideoStreamingPlaylists = streamingPlaylists
525 video.Tags = tagInstances
526 video.VideoCaptions = captions
528 const autoBlacklisted = await autoBlacklistVideoIfNeeded({
536 logger.info('Remote video with uuid %s inserted.', videoObject.uuid)
538 return { autoBlacklisted, videoCreated }
541 if (waitThumbnail === false) {
542 promiseThumbnail.then(thumbnailModel => {
543 thumbnailModel = videoCreated.id
545 return thumbnailModel.save()
549 return { autoBlacklisted, videoCreated }
552 async function videoActivityObjectToDBAttributes (
553 videoChannel: VideoChannelModel,
554 videoObject: VideoTorrentObject,
557 const privacy = to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ? VideoPrivacy.PUBLIC : VideoPrivacy.UNLISTED
558 const duration = videoObject.duration.replace(/[^\d]+/, '')
560 let language: string | undefined
561 if (videoObject.language) {
562 language = videoObject.language.identifier
565 let category: number | undefined
566 if (videoObject.category) {
567 category = parseInt(videoObject.category.identifier, 10)
570 let licence: number | undefined
571 if (videoObject.licence) {
572 licence = parseInt(videoObject.licence.identifier, 10)
575 const description = videoObject.content || null
576 const support = videoObject.support || null
579 name: videoObject.name,
580 uuid: videoObject.uuid,
587 nsfw: videoObject.sensitive,
588 commentsEnabled: videoObject.commentsEnabled,
589 downloadEnabled: videoObject.downloadEnabled,
590 waitTranscoding: videoObject.waitTranscoding,
591 state: videoObject.state,
592 channelId: videoChannel.id,
593 duration: parseInt(duration, 10),
594 createdAt: new Date(videoObject.published),
595 publishedAt: new Date(videoObject.published),
596 originallyPublishedAt: videoObject.originallyPublishedAt ? new Date(videoObject.originallyPublishedAt) : null,
597 // FIXME: updatedAt does not seems to be considered by Sequelize
598 updatedAt: new Date(videoObject.updated),
599 views: videoObject.views,
607 function videoFileActivityUrlToDBAttributes (video: VideoModel, videoObject: VideoTorrentObject) {
608 const fileUrls = videoObject.url.filter(u => isAPVideoUrlObject(u)) as ActivityVideoUrlObject[]
610 if (fileUrls.length === 0) {
611 throw new Error('Cannot find video files for ' + video.url)
614 const attributes: FilteredModelAttributes<VideoFileModel>[] = []
615 for (const fileUrl of fileUrls) {
616 // Fetch associated magnet uri
617 const magnet = videoObject.url.find(u => {
618 const mediaType = u.mediaType || u.mimeType
619 return mediaType === 'application/x-bittorrent;x-scheme-handler/magnet' && (u as any).height === fileUrl.height
622 if (!magnet) throw new Error('Cannot find associated magnet uri for file ' + fileUrl.href)
624 const parsed = magnetUtil.decode(magnet.href)
625 if (!parsed || isVideoFileInfoHashValid(parsed.infoHash) === false) {
626 throw new Error('Cannot parse magnet URI ' + magnet.href)
629 const mediaType = fileUrl.mediaType || fileUrl.mimeType
631 extname: MIMETYPES.VIDEO.MIMETYPE_EXT[ mediaType ],
632 infoHash: parsed.infoHash,
633 resolution: fileUrl.height,
636 fps: fileUrl.fps || -1
639 attributes.push(attribute)
645 function streamingPlaylistActivityUrlToDBAttributes (video: VideoModel, videoObject: VideoTorrentObject, videoFiles: VideoFileModel[]) {
646 const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) as ActivityPlaylistUrlObject[]
647 if (playlistUrls.length === 0) return []
649 const attributes: FilteredModelAttributes<VideoStreamingPlaylistModel>[] = []
650 for (const playlistUrlObject of playlistUrls) {
651 const segmentsSha256UrlObject = playlistUrlObject.tag
653 return isAPPlaylistSegmentHashesUrlObject(t)
654 }) as ActivityPlaylistSegmentHashesObject
655 if (!segmentsSha256UrlObject) {
656 logger.warn('No segment sha256 URL found in AP playlist object.', { playlistUrl: playlistUrlObject })
661 type: VideoStreamingPlaylistType.HLS,
662 playlistUrl: playlistUrlObject.href,
663 segmentsSha256Url: segmentsSha256UrlObject.href,
664 p2pMediaLoaderInfohashes: VideoStreamingPlaylistModel.buildP2PMediaLoaderInfoHashes(playlistUrlObject.href, videoFiles),
665 p2pMediaLoaderPeerVersion: P2P_MEDIA_LOADER_PEER_VERSION,
669 attributes.push(attribute)