aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-08 11:13:49 +0200
committerChocobozzz <me@florianbigard.com>2019-04-08 11:16:14 +0200
commitae9bbed46dbc8d9870c9feb66bbada484c1c7582 (patch)
tree69a04af65274f9f39cb439384ad58b1fc1058ba0 /server/lib
parent14aed608f540b587b3ab2529d06690815214d232 (diff)
downloadPeerTube-ae9bbed46dbc8d9870c9feb66bbada484c1c7582.tar.gz
PeerTube-ae9bbed46dbc8d9870c9feb66bbada484c1c7582.tar.zst
PeerTube-ae9bbed46dbc8d9870c9feb66bbada484c1c7582.zip
Update P2P media loader peer version
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/videos.ts22
-rw-r--r--server/lib/hls.ts22
2 files changed, 28 insertions, 16 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index d935e3f90..339f8e797 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -290,7 +290,11 @@ async function updateVideoFromAP (options: {
290 } 290 }
291 291
292 { 292 {
293 const streamingPlaylistAttributes = streamingPlaylistActivityUrlToDBAttributes(options.video, options.videoObject) 293 const streamingPlaylistAttributes = streamingPlaylistActivityUrlToDBAttributes(
294 options.video,
295 options.videoObject,
296 options.video.VideoFiles
297 )
294 const newStreamingPlaylists = streamingPlaylistAttributes.map(a => new VideoStreamingPlaylistModel(a)) 298 const newStreamingPlaylists = streamingPlaylistAttributes.map(a => new VideoStreamingPlaylistModel(a))
295 299
296 // Remove video files that do not exist anymore 300 // Remove video files that do not exist anymore
@@ -449,9 +453,9 @@ async function createVideo (videoObject: VideoTorrentObject, channelActor: Actor
449 } 453 }
450 454
451 const videoFilePromises = videoFileAttributes.map(f => VideoFileModel.create(f, { transaction: t })) 455 const videoFilePromises = videoFileAttributes.map(f => VideoFileModel.create(f, { transaction: t }))
452 await Promise.all(videoFilePromises) 456 const videoFiles = await Promise.all(videoFilePromises)
453 457
454 const videoStreamingPlaylists = streamingPlaylistActivityUrlToDBAttributes(videoCreated, videoObject) 458 const videoStreamingPlaylists = streamingPlaylistActivityUrlToDBAttributes(videoCreated, videoObject, videoFiles)
455 const playlistPromises = videoStreamingPlaylists.map(p => VideoStreamingPlaylistModel.create(p, { transaction: t })) 459 const playlistPromises = videoStreamingPlaylists.map(p => VideoStreamingPlaylistModel.create(p, { transaction: t }))
456 await Promise.all(playlistPromises) 460 await Promise.all(playlistPromises)
457 461
@@ -575,20 +579,12 @@ function videoFileActivityUrlToDBAttributes (video: VideoModel, videoObject: Vid
575 return attributes 579 return attributes
576} 580}
577 581
578function streamingPlaylistActivityUrlToDBAttributes (video: VideoModel, videoObject: VideoTorrentObject) { 582function streamingPlaylistActivityUrlToDBAttributes (video: VideoModel, videoObject: VideoTorrentObject, videoFiles: VideoFileModel[]) {
579 const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) as ActivityPlaylistUrlObject[] 583 const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) as ActivityPlaylistUrlObject[]
580 if (playlistUrls.length === 0) return [] 584 if (playlistUrls.length === 0) return []
581 585
582 const attributes: FilteredModelAttributes<VideoStreamingPlaylistModel>[] = [] 586 const attributes: FilteredModelAttributes<VideoStreamingPlaylistModel>[] = []
583 for (const playlistUrlObject of playlistUrls) { 587 for (const playlistUrlObject of playlistUrls) {
584 const p2pMediaLoaderInfohashes = playlistUrlObject.tag
585 .filter(t => t.type === 'Infohash')
586 .map(t => t.name)
587 if (p2pMediaLoaderInfohashes.length === 0) {
588 logger.warn('No infohashes found in AP playlist object.', { playlistUrl: playlistUrlObject })
589 continue
590 }
591
592 const segmentsSha256UrlObject = playlistUrlObject.tag 588 const segmentsSha256UrlObject = playlistUrlObject.tag
593 .find(t => { 589 .find(t => {
594 return isAPPlaylistSegmentHashesUrlObject(t) 590 return isAPPlaylistSegmentHashesUrlObject(t)
@@ -602,7 +598,7 @@ function streamingPlaylistActivityUrlToDBAttributes (video: VideoModel, videoObj
602 type: VideoStreamingPlaylistType.HLS, 598 type: VideoStreamingPlaylistType.HLS,
603 playlistUrl: playlistUrlObject.href, 599 playlistUrl: playlistUrlObject.href,
604 segmentsSha256Url: segmentsSha256UrlObject.href, 600 segmentsSha256Url: segmentsSha256UrlObject.href,
605 p2pMediaLoaderInfohashes, 601 p2pMediaLoaderInfohashes: VideoStreamingPlaylistModel.buildP2PMediaLoaderInfoHashes(playlistUrlObject.href, videoFiles),
606 videoId: video.id 602 videoId: video.id
607 } 603 }
608 604
diff --git a/server/lib/hls.ts b/server/lib/hls.ts
index 74ed25183..5a7d61dee 100644
--- a/server/lib/hls.ts
+++ b/server/lib/hls.ts
@@ -1,6 +1,6 @@
1import { VideoModel } from '../models/video/video' 1import { VideoModel } from '../models/video/video'
2import { basename, join, dirname } from 'path' 2import { basename, dirname, join } from 'path'
3import { CONFIG, HLS_STREAMING_PLAYLIST_DIRECTORY } from '../initializers' 3import { CONFIG, HLS_STREAMING_PLAYLIST_DIRECTORY, sequelizeTypescript } from '../initializers'
4import { close, ensureDir, move, open, outputJSON, pathExists, read, readFile, remove, writeFile } from 'fs-extra' 4import { close, ensureDir, move, open, outputJSON, pathExists, read, readFile, remove, writeFile } from 'fs-extra'
5import { getVideoFileSize } from '../helpers/ffmpeg-utils' 5import { getVideoFileSize } from '../helpers/ffmpeg-utils'
6import { sha256 } from '../helpers/core-utils' 6import { sha256 } from '../helpers/core-utils'
@@ -9,6 +9,21 @@ import { logger } from '../helpers/logger'
9import { doRequest, doRequestAndSaveToFile } from '../helpers/requests' 9import { doRequest, doRequestAndSaveToFile } from '../helpers/requests'
10import { generateRandomString } from '../helpers/utils' 10import { generateRandomString } from '../helpers/utils'
11import { flatten, uniq } from 'lodash' 11import { flatten, uniq } from 'lodash'
12import { VideoFileModel } from '../models/video/video-file'
13
14async function updateStreamingPlaylistsInfohashesIfNeeded () {
15 const playlistsToUpdate = await VideoStreamingPlaylistModel.listByIncorrectPeerVersion()
16
17 // Use separate SQL queries, because we could have many videos to update
18 for (const playlist of playlistsToUpdate) {
19 await sequelizeTypescript.transaction(async t => {
20 const videoFiles = await VideoFileModel.listByStreamingPlaylist(playlist.id, t)
21
22 playlist.p2pMediaLoaderInfohashes = await VideoStreamingPlaylistModel.buildP2PMediaLoaderInfoHashes(playlist.playlistUrl, videoFiles)
23 await playlist.save({ transaction: t })
24 })
25 }
26}
12 27
13async function updateMasterHLSPlaylist (video: VideoModel) { 28async function updateMasterHLSPlaylist (video: VideoModel) {
14 const directory = join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid) 29 const directory = join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid)
@@ -159,7 +174,8 @@ function downloadPlaylistSegments (playlistUrl: string, destinationDir: string,
159export { 174export {
160 updateMasterHLSPlaylist, 175 updateMasterHLSPlaylist,
161 updateSha256Segments, 176 updateSha256Segments,
162 downloadPlaylistSegments 177 downloadPlaylistSegments,
178 updateStreamingPlaylistsInfohashesIfNeeded
163} 179}
164 180
165// --------------------------------------------------------------------------- 181// ---------------------------------------------------------------------------