@warren-bank/hls-proxy 3.4.2 → 3.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/hls-proxy/manifest_parser.js +8 -2
- package/hls-proxy/utils.js +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
* inject custom HTTP headers in all outbound proxied requests
|
|
14
14
|
* prefetch video segments (.ts files)
|
|
15
15
|
* use a hook function to conditionally decide which video segments to prefetch
|
|
16
|
-
* use a hook function to conditionally redirect URLs in the playlist (
|
|
16
|
+
* use a hook function to conditionally redirect URLs in the playlist (_before_ and/or _after_ they're modified to pass through the proxy)
|
|
17
|
+
* use a hook function to conditionally rewrite URLs after they're received by the proxy
|
|
17
18
|
|
|
18
19
|
#### Benefits:
|
|
19
20
|
|
|
@@ -231,6 +232,10 @@ options:
|
|
|
231
232
|
* conditionally modify the content of .m3u8 files __before__ they are parsed to extract URLs
|
|
232
233
|
* `"redirect": (url) => new_url`
|
|
233
234
|
* conditionally redirect the URLs encountered in .m3u8 files __before__ they are modified to pass through the proxy
|
|
235
|
+
* `"redirect_final": (url) => new_url`
|
|
236
|
+
* conditionally redirect the URLs encountered in .m3u8 files __after__ they are modified to pass through the proxy
|
|
237
|
+
* `"rewrite": (url) => new_url`
|
|
238
|
+
* conditionally rewrite the URLs requested by clients __before__ they are proxied
|
|
234
239
|
* `"prefetch": (url) => boolean`
|
|
235
240
|
* conditionally decide whether to prefetch video segments on a per-URL basis
|
|
236
241
|
* return value must be a strict boolean type (ie: `true` or `false`)
|
|
@@ -123,7 +123,7 @@ const parse_manifest = function(m3u8_content, m3u8_url, referer_url, hooks, cach
|
|
|
123
123
|
redirect_embedded_url(embedded_url, hooks, m3u8_url, debug)
|
|
124
124
|
if (validate_embedded_url(embedded_url)) {
|
|
125
125
|
finalize_embedded_url(embedded_url, vod_start_at_ms, debug)
|
|
126
|
-
encode_embedded_url(embedded_url, redirected_base_url, debug, manifest_extension, segment_extension)
|
|
126
|
+
encode_embedded_url(embedded_url, hooks, redirected_base_url, debug, manifest_extension, segment_extension)
|
|
127
127
|
get_prefetch_url(embedded_url, should_prefetch_url, prefetch_urls)
|
|
128
128
|
modify_m3u8_line(embedded_url, m3u8_lines)
|
|
129
129
|
}
|
|
@@ -330,7 +330,7 @@ const finalize_embedded_url = function(embedded_url, vod_start_at_ms, debug) {
|
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
-
const encode_embedded_url = function(embedded_url, redirected_base_url, debug, manifest_extension, segment_extension) {
|
|
333
|
+
const encode_embedded_url = function(embedded_url, hooks, redirected_base_url, debug, manifest_extension, segment_extension) {
|
|
334
334
|
if (embedded_url.unencoded_url) {
|
|
335
335
|
let file_extension = embedded_url.url_type
|
|
336
336
|
if (file_extension) {
|
|
@@ -343,6 +343,12 @@ const encode_embedded_url = function(embedded_url, redirected_base_url, debug, m
|
|
|
343
343
|
embedded_url.encoded_url = `${redirected_base_url}/${ utils.base64_encode(embedded_url.unencoded_url) }.${file_extension || 'other'}`
|
|
344
344
|
|
|
345
345
|
debug(3, 'redirecting (proxied):', embedded_url.encoded_url)
|
|
346
|
+
|
|
347
|
+
if (hooks && (hooks instanceof Object) && hooks.redirect_final && (typeof hooks.redirect_final === 'function')) {
|
|
348
|
+
embedded_url.encoded_url = hooks.redirect_final(embedded_url.encoded_url)
|
|
349
|
+
|
|
350
|
+
debug(3, 'redirecting (proxied, post-hook):', embedded_url.encoded_url)
|
|
351
|
+
}
|
|
346
352
|
}
|
|
347
353
|
else {
|
|
348
354
|
embedded_url.encoded_url = ''
|
package/hls-proxy/utils.js
CHANGED
|
@@ -17,7 +17,7 @@ const base64_decode = function(str) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const parse_req_url = function(params, req) {
|
|
20
|
-
const {is_secure, host, manifest_extension, segment_extension} = params
|
|
20
|
+
const {is_secure, host, manifest_extension, segment_extension, hooks} = params
|
|
21
21
|
|
|
22
22
|
const result = {redirected_base_url: '', url_type: '', url: '', referer_url: ''}
|
|
23
23
|
|
|
@@ -38,7 +38,11 @@ const parse_req_url = function(params, req) {
|
|
|
38
38
|
|
|
39
39
|
let url, url_lc, index
|
|
40
40
|
|
|
41
|
-
url
|
|
41
|
+
url = base64_decode( decodeURIComponent( matches[2] ) ).trim()
|
|
42
|
+
|
|
43
|
+
if (hooks && (hooks instanceof Object) && hooks.rewrite && (typeof hooks.rewrite === 'function'))
|
|
44
|
+
url = hooks.rewrite(url)
|
|
45
|
+
|
|
42
46
|
url_lc = url.toLowerCase()
|
|
43
47
|
index = url_lc.indexOf('http')
|
|
44
48
|
|
package/package.json
CHANGED