X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fhls.ts;h=7aa15263851b6ac493df47d668ec119fab169432;hb=284ef529113ad61de30ff30a28c699b97d9ca02f;hp=76380b1f23e9730a4603225d007dab7ae067b40e;hpb=d7b1c7b4f1a9099eac61f944249f2cdb4f94415e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/hls.ts b/server/lib/hls.ts index 76380b1f2..7aa152638 100644 --- a/server/lib/hls.ts +++ b/server/lib/hls.ts @@ -65,7 +65,7 @@ async function updateMasterHLSPlaylist (video: MVideoWithFile) { await writeFile(masterPlaylistPath, masterPlaylists.join('\n') + '\n') } -async function updateSha256Segments (video: MVideoWithFile) { +async function updateSha256VODSegments (video: MVideoWithFile) { const json: { [filename: string]: { [range: string]: string } } = {} const playlistDirectory = join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid) @@ -101,20 +101,9 @@ async function updateSha256Segments (video: MVideoWithFile) { await outputJSON(outputPath, json) } -function getRangesFromPlaylist (playlistContent: string) { - const ranges: { offset: number, length: number }[] = [] - const lines = playlistContent.split('\n') - const regex = /^#EXT-X-BYTERANGE:(\d+)@(\d+)$/ - - for (const line of lines) { - const captured = regex.exec(line) - - if (captured) { - ranges.push({ length: parseInt(captured[1], 10), offset: parseInt(captured[2], 10) }) - } - } - - return ranges +async function buildSha256Segment (segmentPath: string) { + const buf = await readFile(segmentPath) + return sha256(buf) } function downloadPlaylistSegments (playlistUrl: string, destinationDir: string, timeout: number) { @@ -187,9 +176,26 @@ function downloadPlaylistSegments (playlistUrl: string, destinationDir: string, export { updateMasterHLSPlaylist, - updateSha256Segments, + updateSha256VODSegments, + buildSha256Segment, downloadPlaylistSegments, updateStreamingPlaylistsInfohashesIfNeeded } // --------------------------------------------------------------------------- + +function getRangesFromPlaylist (playlistContent: string) { + const ranges: { offset: number, length: number }[] = [] + const lines = playlistContent.split('\n') + const regex = /^#EXT-X-BYTERANGE:(\d+)@(\d+)$/ + + for (const line of lines) { + const captured = regex.exec(line) + + if (captured) { + ranges.push({ length: parseInt(captured[1], 10), offset: parseInt(captured[2], 10) }) + } + } + + return ranges +}