From 092092969633bbcf6d4891a083ea497a7d5c3154 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 29 Jan 2019 08:37:25 +0100 Subject: Add hls support on server --- shared/utils/videos/video-playlists.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 shared/utils/videos/video-playlists.ts (limited to 'shared/utils/videos/video-playlists.ts') diff --git a/shared/utils/videos/video-playlists.ts b/shared/utils/videos/video-playlists.ts new file mode 100644 index 000000000..9a0710ca6 --- /dev/null +++ b/shared/utils/videos/video-playlists.ts @@ -0,0 +1,21 @@ +import { makeRawRequest } from '../requests/requests' + +function getPlaylist (url: string, statusCodeExpected = 200) { + return makeRawRequest(url, statusCodeExpected) +} + +function getSegment (url: string, statusCodeExpected = 200) { + return makeRawRequest(url, statusCodeExpected) +} + +function getSegmentSha256 (url: string, statusCodeExpected = 200) { + return makeRawRequest(url, statusCodeExpected) +} + +// --------------------------------------------------------------------------- + +export { + getPlaylist, + getSegment, + getSegmentSha256 +} -- cgit v1.2.3 From 4c280004ce62bf11ddb091854c28f1e1d54a54d6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 7 Feb 2019 15:08:19 +0100 Subject: Use a single file instead of segments for HLS --- shared/utils/videos/video-playlists.ts | 36 +++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'shared/utils/videos/video-playlists.ts') diff --git a/shared/utils/videos/video-playlists.ts b/shared/utils/videos/video-playlists.ts index 9a0710ca6..eb25011cb 100644 --- a/shared/utils/videos/video-playlists.ts +++ b/shared/utils/videos/video-playlists.ts @@ -1,21 +1,51 @@ import { makeRawRequest } from '../requests/requests' +import { sha256 } from '../../../server/helpers/core-utils' +import { VideoStreamingPlaylist } from '../../models/videos/video-streaming-playlist.model' +import { expect } from 'chai' function getPlaylist (url: string, statusCodeExpected = 200) { return makeRawRequest(url, statusCodeExpected) } -function getSegment (url: string, statusCodeExpected = 200) { - return makeRawRequest(url, statusCodeExpected) +function getSegment (url: string, statusCodeExpected = 200, range?: string) { + return makeRawRequest(url, statusCodeExpected, range) } function getSegmentSha256 (url: string, statusCodeExpected = 200) { return makeRawRequest(url, statusCodeExpected) } +async function checkSegmentHash ( + baseUrlPlaylist: string, + baseUrlSegment: string, + videoUUID: string, + resolution: number, + hlsPlaylist: VideoStreamingPlaylist +) { + const res = await getPlaylist(`${baseUrlPlaylist}/${videoUUID}/${resolution}.m3u8`) + const playlist = res.text + + const videoName = `${videoUUID}-${resolution}-fragmented.mp4` + + const matches = /#EXT-X-BYTERANGE:(\d+)@(\d+)/.exec(playlist) + + const length = parseInt(matches[1], 10) + const offset = parseInt(matches[2], 10) + const range = `${offset}-${offset + length - 1}` + + const res2 = await getSegment(`${baseUrlSegment}/${videoUUID}/${videoName}`, 206, `bytes=${range}`) + + const resSha = await getSegmentSha256(hlsPlaylist.segmentsSha256Url) + + const sha256Server = resSha.body[ videoName ][range] + expect(sha256(res2.body)).to.equal(sha256Server) +} + // --------------------------------------------------------------------------- export { getPlaylist, getSegment, - getSegmentSha256 + getSegmentSha256, + checkSegmentHash } -- cgit v1.2.3