@warren-bank/hls-proxy 3.4.1 → 3.4.2
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
CHANGED
|
@@ -136,6 +136,8 @@ options:
|
|
|
136
136
|
--tls-cert <filepath>
|
|
137
137
|
--tls-key <filepath>
|
|
138
138
|
--tls-pass <filepath>
|
|
139
|
+
--manifest-extension <ext>
|
|
140
|
+
--segment-extension <ext>
|
|
139
141
|
```
|
|
140
142
|
|
|
141
143
|
#### Options:
|
|
@@ -365,6 +367,10 @@ options:
|
|
|
365
367
|
* _--tls-key_ is the filepath to the private key for the _--tls-cert_ security certificate
|
|
366
368
|
* _--tls-pass_ is the filepath to a text file containing the security passphrase for the _--tls-key_ private key
|
|
367
369
|
* optional, not required when the _--tls-key_ private key was created without a security passphrase
|
|
370
|
+
* _--manifest-extension_ is the file extension associated with HLS manifests
|
|
371
|
+
* default value: `m3u8`
|
|
372
|
+
* _--segment-extension_ is the file extension associated with media segments
|
|
373
|
+
* default value: `ts`
|
|
368
374
|
|
|
369
375
|
#### Examples:
|
|
370
376
|
|
package/hls-proxy/bin/hlsd.js
CHANGED
|
@@ -45,7 +45,9 @@ const middleware = require('../proxy')({
|
|
|
45
45
|
cache_storage_fs_dirpath: argv_vals["--cache-storage-fs-dirpath"],
|
|
46
46
|
debug_level: argv_vals["-v"],
|
|
47
47
|
acl_whitelist: argv_vals["--acl-whitelist"],
|
|
48
|
-
http_proxy: argv_vals["--http-proxy"]
|
|
48
|
+
http_proxy: argv_vals["--http-proxy"],
|
|
49
|
+
manifest_extension: argv_vals["--manifest-extension"],
|
|
50
|
+
segment_extension: argv_vals["--segment-extension"]
|
|
49
51
|
})
|
|
50
52
|
|
|
51
53
|
if (middleware.connection)
|
|
@@ -38,7 +38,10 @@ const argv_flags = {
|
|
|
38
38
|
|
|
39
39
|
"--tls-cert": {file: "path-exists"},
|
|
40
40
|
"--tls-key": {file: "path-exists"},
|
|
41
|
-
"--tls-pass": {file: "path-exists"}
|
|
41
|
+
"--tls-pass": {file: "path-exists"},
|
|
42
|
+
|
|
43
|
+
"--manifest-extension": {},
|
|
44
|
+
"--segment-extension": {}
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
const argv_flag_aliases = {
|
|
@@ -110,7 +110,7 @@ const parse_HHMMSS_to_seconds = function(str) {
|
|
|
110
110
|
// prefetch_urls: [],
|
|
111
111
|
// modified_m3u8: ''
|
|
112
112
|
// }
|
|
113
|
-
const parse_manifest = function(m3u8_content, m3u8_url, referer_url, hooks, cache_segments, debug, vod_start_at_ms, redirected_base_url, should_prefetch_url) {
|
|
113
|
+
const parse_manifest = function(m3u8_content, m3u8_url, referer_url, hooks, cache_segments, debug, vod_start_at_ms, redirected_base_url, should_prefetch_url, manifest_extension, segment_extension) {
|
|
114
114
|
const m3u8_lines = m3u8_content.split(regexs.m3u8_line_separator)
|
|
115
115
|
m3u8_content = null
|
|
116
116
|
|
|
@@ -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)
|
|
126
|
+
encode_embedded_url(embedded_url, 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,13 +330,23 @@ 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) {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
333
|
+
const encode_embedded_url = function(embedded_url, redirected_base_url, debug, manifest_extension, segment_extension) {
|
|
334
|
+
if (embedded_url.unencoded_url) {
|
|
335
|
+
let file_extension = embedded_url.url_type
|
|
336
|
+
if (file_extension) {
|
|
337
|
+
if (manifest_extension && (file_extension === 'm3u8'))
|
|
338
|
+
file_extension = manifest_extension
|
|
339
|
+
if (segment_extension && (file_extension === 'ts'))
|
|
340
|
+
file_extension = segment_extension
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
embedded_url.encoded_url = `${redirected_base_url}/${ utils.base64_encode(embedded_url.unencoded_url) }.${file_extension || 'other'}`
|
|
337
344
|
|
|
338
|
-
if (embedded_url.encoded_url)
|
|
339
345
|
debug(3, 'redirecting (proxied):', embedded_url.encoded_url)
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
embedded_url.encoded_url = ''
|
|
349
|
+
}
|
|
340
350
|
}
|
|
341
351
|
|
|
342
352
|
const get_prefetch_url = function(embedded_url, should_prefetch_url, prefetch_urls = []) {
|
|
@@ -362,7 +372,7 @@ const modify_m3u8_line = function(embedded_url, m3u8_lines) {
|
|
|
362
372
|
}
|
|
363
373
|
|
|
364
374
|
const modify_m3u8_content = function(params, segment_cache, m3u8_content, m3u8_url, referer_url, redirected_base_url) {
|
|
365
|
-
const {hooks, cache_segments, max_segments, debug_level} = params
|
|
375
|
+
const {hooks, cache_segments, max_segments, debug_level, manifest_extension, segment_extension} = params
|
|
366
376
|
|
|
367
377
|
const {has_cache, get_time_since_last_access, is_expired, prefetch_segment} = segment_cache
|
|
368
378
|
|
|
@@ -419,7 +429,7 @@ const modify_m3u8_content = function(params, segment_cache, m3u8_content, m3u8_u
|
|
|
419
429
|
: null
|
|
420
430
|
|
|
421
431
|
{
|
|
422
|
-
const parsed_manifest = parse_manifest(m3u8_content, m3u8_url, referer_url, hooks, cache_segments, debug, vod_start_at_ms, redirected_base_url, should_prefetch_url)
|
|
432
|
+
const parsed_manifest = parse_manifest(m3u8_content, m3u8_url, referer_url, hooks, cache_segments, debug, vod_start_at_ms, redirected_base_url, should_prefetch_url, manifest_extension, segment_extension)
|
|
423
433
|
is_vod = !!parsed_manifest.meta_data.is_vod // default: false => hls live stream
|
|
424
434
|
seg_duration_ms = parsed_manifest.meta_data.seg_duration_ms || 10000 // default: 10 seconds in ms
|
|
425
435
|
prefetch_urls = parsed_manifest.prefetch_urls
|
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} = params
|
|
20
|
+
const {is_secure, host, manifest_extension, segment_extension} = params
|
|
21
21
|
|
|
22
22
|
const result = {redirected_base_url: '', url_type: '', url: '', referer_url: ''}
|
|
23
23
|
|
|
@@ -26,9 +26,16 @@ const parse_req_url = function(params, req) {
|
|
|
26
26
|
if (matches) {
|
|
27
27
|
result.redirected_base_url = `${ (is_secure || (host && host.endsWith(':443'))) ? 'https' : 'http' }://${host || req.headers.host}${expressjs.get_base_req_url(req) || matches[1] || ''}`
|
|
28
28
|
|
|
29
|
-
if (matches[3])
|
|
29
|
+
if (matches[3]) {
|
|
30
30
|
result.url_type = matches[3].toLowerCase().trim()
|
|
31
31
|
|
|
32
|
+
if (manifest_extension && (result.url_type === manifest_extension))
|
|
33
|
+
result.url_type = 'm3u8'
|
|
34
|
+
|
|
35
|
+
if (segment_extension && (result.url_type === segment_extension))
|
|
36
|
+
result.url_type = 'ts'
|
|
37
|
+
}
|
|
38
|
+
|
|
32
39
|
let url, url_lc, index
|
|
33
40
|
|
|
34
41
|
url = base64_decode( decodeURIComponent( matches[2] ) ).trim()
|
package/package.json
CHANGED