diff options
Diffstat (limited to 'server/lib/hls.ts')
-rw-r--r-- | server/lib/hls.ts | 22 |
1 files changed, 19 insertions, 3 deletions
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 @@ | |||
1 | import { VideoModel } from '../models/video/video' | 1 | import { VideoModel } from '../models/video/video' |
2 | import { basename, join, dirname } from 'path' | 2 | import { basename, dirname, join } from 'path' |
3 | import { CONFIG, HLS_STREAMING_PLAYLIST_DIRECTORY } from '../initializers' | 3 | import { CONFIG, HLS_STREAMING_PLAYLIST_DIRECTORY, sequelizeTypescript } from '../initializers' |
4 | import { close, ensureDir, move, open, outputJSON, pathExists, read, readFile, remove, writeFile } from 'fs-extra' | 4 | import { close, ensureDir, move, open, outputJSON, pathExists, read, readFile, remove, writeFile } from 'fs-extra' |
5 | import { getVideoFileSize } from '../helpers/ffmpeg-utils' | 5 | import { getVideoFileSize } from '../helpers/ffmpeg-utils' |
6 | import { sha256 } from '../helpers/core-utils' | 6 | import { sha256 } from '../helpers/core-utils' |
@@ -9,6 +9,21 @@ import { logger } from '../helpers/logger' | |||
9 | import { doRequest, doRequestAndSaveToFile } from '../helpers/requests' | 9 | import { doRequest, doRequestAndSaveToFile } from '../helpers/requests' |
10 | import { generateRandomString } from '../helpers/utils' | 10 | import { generateRandomString } from '../helpers/utils' |
11 | import { flatten, uniq } from 'lodash' | 11 | import { flatten, uniq } from 'lodash' |
12 | import { VideoFileModel } from '../models/video/video-file' | ||
13 | |||
14 | async 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 | ||
13 | async function updateMasterHLSPlaylist (video: VideoModel) { | 28 | async 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, | |||
159 | export { | 174 | export { |
160 | updateMasterHLSPlaylist, | 175 | updateMasterHLSPlaylist, |
161 | updateSha256Segments, | 176 | updateSha256Segments, |
162 | downloadPlaylistSegments | 177 | downloadPlaylistSegments, |
178 | updateStreamingPlaylistsInfohashesIfNeeded | ||
163 | } | 179 | } |
164 | 180 | ||
165 | // --------------------------------------------------------------------------- | 181 | // --------------------------------------------------------------------------- |