diff options
author | Chocobozzz <me@florianbigard.com> | 2021-08-06 15:25:45 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-08-06 15:25:45 +0200 |
commit | 18998c45c001869a883ec7a2d286d8170f768381 (patch) | |
tree | 83cd925fc3ba14f5dabf66e24c26adfee061f21e /server/lib/hls.ts | |
parent | a1c63fe1a2159c5796e37a63c2e4acd96dc557ca (diff) | |
download | PeerTube-18998c45c001869a883ec7a2d286d8170f768381.tar.gz PeerTube-18998c45c001869a883ec7a2d286d8170f768381.tar.zst PeerTube-18998c45c001869a883ec7a2d286d8170f768381.zip |
Correctly handle large HLS files for redundancy
Diffstat (limited to 'server/lib/hls.ts')
-rw-r--r-- | server/lib/hls.ts | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/server/lib/hls.ts b/server/lib/hls.ts index 32b02bc26..0e77ab9fa 100644 --- a/server/lib/hls.ts +++ b/server/lib/hls.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { close, ensureDir, move, open, outputJSON, pathExists, read, readFile, remove, writeFile } from 'fs-extra' | 1 | import { close, ensureDir, move, open, outputJSON, pathExists, read, readFile, remove, stat, writeFile } from 'fs-extra' |
2 | import { flatten, uniq } from 'lodash' | 2 | import { flatten, uniq } from 'lodash' |
3 | import { basename, dirname, join } from 'path' | 3 | import { basename, dirname, join } from 'path' |
4 | import { MStreamingPlaylistFilesVideo, MVideoWithFile } from '@server/types/models' | 4 | import { MStreamingPlaylistFilesVideo, MVideoWithFile } from '@server/types/models' |
@@ -108,8 +108,9 @@ async function buildSha256Segment (segmentPath: string) { | |||
108 | return sha256(buf) | 108 | return sha256(buf) |
109 | } | 109 | } |
110 | 110 | ||
111 | function downloadPlaylistSegments (playlistUrl: string, destinationDir: string, timeout: number) { | 111 | function downloadPlaylistSegments (playlistUrl: string, destinationDir: string, timeout: number, bodyKBLimit: number) { |
112 | let timer | 112 | let timer |
113 | let remainingBodyKBLimit = bodyKBLimit | ||
113 | 114 | ||
114 | logger.info('Importing HLS playlist %s', playlistUrl) | 115 | logger.info('Importing HLS playlist %s', playlistUrl) |
115 | 116 | ||
@@ -136,8 +137,12 @@ function downloadPlaylistSegments (playlistUrl: string, destinationDir: string, | |||
136 | for (const fileUrl of fileUrls) { | 137 | for (const fileUrl of fileUrls) { |
137 | const destPath = join(tmpDirectory, basename(fileUrl)) | 138 | const destPath = join(tmpDirectory, basename(fileUrl)) |
138 | 139 | ||
139 | const bodyKBLimit = 10 * 1000 * 1000 // 10GB | 140 | await doRequestAndSaveToFile(fileUrl, destPath, { bodyKBLimit: remainingBodyKBLimit }) |
140 | await doRequestAndSaveToFile(fileUrl, destPath, { bodyKBLimit }) | 141 | |
142 | const { size } = await stat(destPath) | ||
143 | remainingBodyKBLimit -= (size / 1000) | ||
144 | |||
145 | logger.debug('Downloaded HLS playlist file %s with %d kB remained limit.', fileUrl, Math.floor(remainingBodyKBLimit)) | ||
141 | } | 146 | } |
142 | 147 | ||
143 | clearTimeout(timer) | 148 | clearTimeout(timer) |