X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fhls.ts;h=9ea83f33762f5a5658b7c8ebc5b6748ac1b57568;hb=3b01f4c0ac764ecb70efaadfd939ca868c28769c;hp=e38a8788c654a308cdc7c112b67968af7d70bde8;hpb=c6c0fa6cd8fe8f752463d8982c3dbcd448739c4e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/hls.ts b/server/lib/hls.ts index e38a8788c..9ea83f337 100644 --- a/server/lib/hls.ts +++ b/server/lib/hls.ts @@ -1,17 +1,17 @@ -import { basename, dirname, join } from 'path' -import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION } from '../initializers/constants' import { close, ensureDir, move, open, outputJSON, pathExists, read, readFile, remove, writeFile } from 'fs-extra' -import { getVideoStreamSize, getAudioStreamCodec, getVideoStreamCodec } from '../helpers/ffmpeg-utils' +import { flatten, uniq } from 'lodash' +import { basename, dirname, join } from 'path' +import { MVideoWithFile } from '@server/types/models' import { sha256 } from '../helpers/core-utils' -import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist' +import { getAudioStreamCodec, getVideoStreamCodec, getVideoStreamSize } from '../helpers/ffprobe-utils' 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' import { CONFIG } from '../initializers/config' +import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION } from '../initializers/constants' import { sequelizeTypescript } from '../initializers/database' -import { MVideoWithFile } from '@server/types/models' +import { VideoFileModel } from '../models/video/video-file' +import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist' import { getVideoFilename, getVideoFilePath } from './video-paths' async function updateStreamingPlaylistsInfohashesIfNeeded () { @@ -106,22 +106,6 @@ async function buildSha256Segment (segmentPath: string) { return sha256(buf) } -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 -} - function downloadPlaylistSegments (playlistUrl: string, destinationDir: string, timeout: number) { let timer @@ -199,3 +183,19 @@ export { } // --------------------------------------------------------------------------- + +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 +}