mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
Update P2P media loader peer version
This commit is contained in:
parent
14aed608f5
commit
ae9bbed46d
9 changed files with 121 additions and 24 deletions
|
@ -1,6 +1,6 @@
|
|||
import { VideoModel } from '../models/video/video'
|
||||
import { basename, join, dirname } from 'path'
|
||||
import { CONFIG, HLS_STREAMING_PLAYLIST_DIRECTORY } from '../initializers'
|
||||
import { basename, dirname, join } from 'path'
|
||||
import { CONFIG, HLS_STREAMING_PLAYLIST_DIRECTORY, sequelizeTypescript } from '../initializers'
|
||||
import { close, ensureDir, move, open, outputJSON, pathExists, read, readFile, remove, writeFile } from 'fs-extra'
|
||||
import { getVideoFileSize } from '../helpers/ffmpeg-utils'
|
||||
import { sha256 } from '../helpers/core-utils'
|
||||
|
@ -9,6 +9,21 @@ import { logger } from '../helpers/logger'
|
|||
import { doRequest, doRequestAndSaveToFile } from '../helpers/requests'
|
||||
import { generateRandomString } from '../helpers/utils'
|
||||
import { flatten, uniq } from 'lodash'
|
||||
import { VideoFileModel } from '../models/video/video-file'
|
||||
|
||||
async function updateStreamingPlaylistsInfohashesIfNeeded () {
|
||||
const playlistsToUpdate = await VideoStreamingPlaylistModel.listByIncorrectPeerVersion()
|
||||
|
||||
// Use separate SQL queries, because we could have many videos to update
|
||||
for (const playlist of playlistsToUpdate) {
|
||||
await sequelizeTypescript.transaction(async t => {
|
||||
const videoFiles = await VideoFileModel.listByStreamingPlaylist(playlist.id, t)
|
||||
|
||||
playlist.p2pMediaLoaderInfohashes = await VideoStreamingPlaylistModel.buildP2PMediaLoaderInfoHashes(playlist.playlistUrl, videoFiles)
|
||||
await playlist.save({ transaction: t })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function updateMasterHLSPlaylist (video: VideoModel) {
|
||||
const directory = join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid)
|
||||
|
@ -159,7 +174,8 @@ function downloadPlaylistSegments (playlistUrl: string, destinationDir: string,
|
|||
export {
|
||||
updateMasterHLSPlaylist,
|
||||
updateSha256Segments,
|
||||
downloadPlaylistSegments
|
||||
downloadPlaylistSegments,
|
||||
updateStreamingPlaylistsInfohashesIfNeeded
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue