diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-07 15:08:19 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-02-11 09:13:02 +0100 |
commit | 4c280004ce62bf11ddb091854c28f1e1d54a54d6 (patch) | |
tree | 1899fff4ef18f8663a865997d5d06119b2149319 /shared | |
parent | 6ec0b75beb9c8bcd84e178912319913b91830da2 (diff) | |
download | PeerTube-4c280004ce62bf11ddb091854c28f1e1d54a54d6.tar.gz PeerTube-4c280004ce62bf11ddb091854c28f1e1d54a54d6.tar.zst PeerTube-4c280004ce62bf11ddb091854c28f1e1d54a54d6.zip |
Use a single file instead of segments for HLS
Diffstat (limited to 'shared')
-rw-r--r-- | shared/models/activitypub/activitypub-ordered-collection.ts | 5 | ||||
-rw-r--r-- | shared/utils/requests/requests.ts | 8 | ||||
-rw-r--r-- | shared/utils/videos/video-playlists.ts | 36 |
3 files changed, 42 insertions, 7 deletions
diff --git a/shared/models/activitypub/activitypub-ordered-collection.ts b/shared/models/activitypub/activitypub-ordered-collection.ts index dfec0bb76..3de0890bb 100644 --- a/shared/models/activitypub/activitypub-ordered-collection.ts +++ b/shared/models/activitypub/activitypub-ordered-collection.ts | |||
@@ -2,6 +2,9 @@ export interface ActivityPubOrderedCollection<T> { | |||
2 | '@context': string[] | 2 | '@context': string[] |
3 | type: 'OrderedCollection' | 'OrderedCollectionPage' | 3 | type: 'OrderedCollection' | 'OrderedCollectionPage' |
4 | totalItems: number | 4 | totalItems: number |
5 | partOf?: string | ||
6 | orderedItems: T[] | 5 | orderedItems: T[] |
6 | |||
7 | partOf?: string | ||
8 | next?: string | ||
9 | first?: string | ||
7 | } | 10 | } |
diff --git a/shared/utils/requests/requests.ts b/shared/utils/requests/requests.ts index fc687c701..6b59e24fc 100644 --- a/shared/utils/requests/requests.ts +++ b/shared/utils/requests/requests.ts | |||
@@ -3,10 +3,10 @@ import { buildAbsoluteFixturePath, root } from '../miscs/miscs' | |||
3 | import { isAbsolute, join } from 'path' | 3 | import { isAbsolute, join } from 'path' |
4 | import { parse } from 'url' | 4 | import { parse } from 'url' |
5 | 5 | ||
6 | function makeRawRequest (url: string, statusCodeExpected?: number) { | 6 | function makeRawRequest (url: string, statusCodeExpected?: number, range?: string) { |
7 | const { host, protocol, pathname } = parse(url) | 7 | const { host, protocol, pathname } = parse(url) |
8 | 8 | ||
9 | return makeGetRequest({ url: `${protocol}//${host}`, path: pathname, statusCodeExpected }) | 9 | return makeGetRequest({ url: `${protocol}//${host}`, path: pathname, statusCodeExpected, range }) |
10 | } | 10 | } |
11 | 11 | ||
12 | function makeGetRequest (options: { | 12 | function makeGetRequest (options: { |
@@ -15,7 +15,8 @@ function makeGetRequest (options: { | |||
15 | query?: any, | 15 | query?: any, |
16 | token?: string, | 16 | token?: string, |
17 | statusCodeExpected?: number, | 17 | statusCodeExpected?: number, |
18 | contentType?: string | 18 | contentType?: string, |
19 | range?: string | ||
19 | }) { | 20 | }) { |
20 | if (!options.statusCodeExpected) options.statusCodeExpected = 400 | 21 | if (!options.statusCodeExpected) options.statusCodeExpected = 400 |
21 | if (options.contentType === undefined) options.contentType = 'application/json' | 22 | if (options.contentType === undefined) options.contentType = 'application/json' |
@@ -25,6 +26,7 @@ function makeGetRequest (options: { | |||
25 | if (options.contentType) req.set('Accept', options.contentType) | 26 | if (options.contentType) req.set('Accept', options.contentType) |
26 | if (options.token) req.set('Authorization', 'Bearer ' + options.token) | 27 | if (options.token) req.set('Authorization', 'Bearer ' + options.token) |
27 | if (options.query) req.query(options.query) | 28 | if (options.query) req.query(options.query) |
29 | if (options.range) req.set('Range', options.range) | ||
28 | 30 | ||
29 | return req.expect(options.statusCodeExpected) | 31 | return req.expect(options.statusCodeExpected) |
30 | } | 32 | } |
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 @@ | |||
1 | import { makeRawRequest } from '../requests/requests' | 1 | import { makeRawRequest } from '../requests/requests' |
2 | import { sha256 } from '../../../server/helpers/core-utils' | ||
3 | import { VideoStreamingPlaylist } from '../../models/videos/video-streaming-playlist.model' | ||
4 | import { expect } from 'chai' | ||
2 | 5 | ||
3 | function getPlaylist (url: string, statusCodeExpected = 200) { | 6 | function getPlaylist (url: string, statusCodeExpected = 200) { |
4 | return makeRawRequest(url, statusCodeExpected) | 7 | return makeRawRequest(url, statusCodeExpected) |
5 | } | 8 | } |
6 | 9 | ||
7 | function getSegment (url: string, statusCodeExpected = 200) { | 10 | function getSegment (url: string, statusCodeExpected = 200, range?: string) { |
8 | return makeRawRequest(url, statusCodeExpected) | 11 | return makeRawRequest(url, statusCodeExpected, range) |
9 | } | 12 | } |
10 | 13 | ||
11 | function getSegmentSha256 (url: string, statusCodeExpected = 200) { | 14 | function getSegmentSha256 (url: string, statusCodeExpected = 200) { |
12 | return makeRawRequest(url, statusCodeExpected) | 15 | return makeRawRequest(url, statusCodeExpected) |
13 | } | 16 | } |
14 | 17 | ||
18 | async function checkSegmentHash ( | ||
19 | baseUrlPlaylist: string, | ||
20 | baseUrlSegment: string, | ||
21 | videoUUID: string, | ||
22 | resolution: number, | ||
23 | hlsPlaylist: VideoStreamingPlaylist | ||
24 | ) { | ||
25 | const res = await getPlaylist(`${baseUrlPlaylist}/${videoUUID}/${resolution}.m3u8`) | ||
26 | const playlist = res.text | ||
27 | |||
28 | const videoName = `${videoUUID}-${resolution}-fragmented.mp4` | ||
29 | |||
30 | const matches = /#EXT-X-BYTERANGE:(\d+)@(\d+)/.exec(playlist) | ||
31 | |||
32 | const length = parseInt(matches[1], 10) | ||
33 | const offset = parseInt(matches[2], 10) | ||
34 | const range = `${offset}-${offset + length - 1}` | ||
35 | |||
36 | const res2 = await getSegment(`${baseUrlSegment}/${videoUUID}/${videoName}`, 206, `bytes=${range}`) | ||
37 | |||
38 | const resSha = await getSegmentSha256(hlsPlaylist.segmentsSha256Url) | ||
39 | |||
40 | const sha256Server = resSha.body[ videoName ][range] | ||
41 | expect(sha256(res2.body)).to.equal(sha256Server) | ||
42 | } | ||
43 | |||
15 | // --------------------------------------------------------------------------- | 44 | // --------------------------------------------------------------------------- |
16 | 45 | ||
17 | export { | 46 | export { |
18 | getPlaylist, | 47 | getPlaylist, |
19 | getSegment, | 48 | getSegment, |
20 | getSegmentSha256 | 49 | getSegmentSha256, |
50 | checkSegmentHash | ||
21 | } | 51 | } |