mlbserver 2022.10.7 → 2023.3.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 +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/session.js +30 -159
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -2459,7 +2459,7 @@ function start_multiview_stream(streams, sync, dvr, faster, reencode, audio_url,
|
|
|
2459
2459
|
// Filters: resampling preserve timestamps and padding allows the multiview stream to continue if one stream ends
|
|
2460
2460
|
audio_reencoded = []
|
|
2461
2461
|
for (var i=0; i<audio_present.length; i++) {
|
|
2462
|
-
let audio_input = audio_present[i] + ':m:language:en?'
|
|
2462
|
+
let audio_input = audio_present[i] + ':a:m:language:en?'
|
|
2463
2463
|
let filter = ''
|
|
2464
2464
|
// Optionally apply sync adjustments
|
|
2465
2465
|
if ( sync[audio_present[i]] ) {
|
package/package.json
CHANGED
package/session.js
CHANGED
|
@@ -12,12 +12,13 @@ const parseString = require('xml2js').parseString
|
|
|
12
12
|
const MULTIVIEW_DIRECTORY_NAME = 'multiview'
|
|
13
13
|
|
|
14
14
|
// Default user agent to use for API requests
|
|
15
|
-
const USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:
|
|
15
|
+
const USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:109.0) Gecko/20100101 Firefox/110.0'
|
|
16
16
|
|
|
17
17
|
// Other variables to use in API communications
|
|
18
18
|
const PLATFORM = "macintosh"
|
|
19
19
|
const BAM_SDK_VERSION = '4.3'
|
|
20
20
|
const BAM_TOKEN_URL = 'https://us.edge.bamgrid.com/token'
|
|
21
|
+
const API_KEY = 'bWxidHYmYW5kcm9pZCYxLjAuMA.6LZMbH2r--rbXcgEabaDdIslpo4RyZrlVfWZhsAgXIk'
|
|
21
22
|
|
|
22
23
|
// Default date handling
|
|
23
24
|
const TODAY_UTC_HOURS = 8 // UTC hours (EST + 4) into tomorrow to still use today's date
|
|
@@ -1378,26 +1379,6 @@ class sessionClass {
|
|
|
1378
1379
|
})
|
|
1379
1380
|
}
|
|
1380
1381
|
|
|
1381
|
-
async getXApiKey() {
|
|
1382
|
-
this.debuglog('getXApiKey')
|
|
1383
|
-
if ( !this.data.xApiKey || !this.data.xApiKey ) {
|
|
1384
|
-
await this.getApiKeys()
|
|
1385
|
-
if ( this.data.xApiKey ) return this.data.xApiKey
|
|
1386
|
-
} else {
|
|
1387
|
-
return this.data.xApiKey
|
|
1388
|
-
}
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1391
|
-
async getClientApiKey() {
|
|
1392
|
-
this.debuglog('getClientApiKey')
|
|
1393
|
-
if ( !this.data.clientApiKey ) {
|
|
1394
|
-
await this.getApiKeys()
|
|
1395
|
-
if ( this.data.clientApiKey ) return this.data.clientApiKey
|
|
1396
|
-
} else {
|
|
1397
|
-
return this.data.clientApiKey
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
|
|
1401
1382
|
// API call
|
|
1402
1383
|
async getApiKeys() {
|
|
1403
1384
|
this.debuglog('getApiKeys')
|
|
@@ -1433,40 +1414,6 @@ class sessionClass {
|
|
|
1433
1414
|
}
|
|
1434
1415
|
}
|
|
1435
1416
|
|
|
1436
|
-
// API call
|
|
1437
|
-
async getOktaClientId() {
|
|
1438
|
-
this.debuglog('getOktaClientId')
|
|
1439
|
-
if ( !this.data.oktaClientId ) {
|
|
1440
|
-
this.debuglog('need to get oktaClientId')
|
|
1441
|
-
let reqObj = {
|
|
1442
|
-
url: 'https://www.mlbstatic.com/mlb.com/vendor/mlb-okta/mlb-okta.js',
|
|
1443
|
-
headers: {
|
|
1444
|
-
'User-agent': USER_AGENT,
|
|
1445
|
-
'Origin': 'https://www.mlb.com',
|
|
1446
|
-
'Accept-Encoding': 'gzip, deflate, br'
|
|
1447
|
-
},
|
|
1448
|
-
gzip: true
|
|
1449
|
-
}
|
|
1450
|
-
var response = await this.httpGet(reqObj)
|
|
1451
|
-
if ( response ) {
|
|
1452
|
-
// disabled because it's very big!
|
|
1453
|
-
//this.debuglog('getOktaClientId response : ' + response)
|
|
1454
|
-
var parsed = response.match('production:{clientId:"([^"]+)",')
|
|
1455
|
-
if ( parsed[1] ) {
|
|
1456
|
-
this.data.oktaClientId = parsed[1]
|
|
1457
|
-
this.save_session_data()
|
|
1458
|
-
return this.data.oktaClientId
|
|
1459
|
-
} else {
|
|
1460
|
-
this.log('getOktaClientId parse failure')
|
|
1461
|
-
}
|
|
1462
|
-
} else {
|
|
1463
|
-
this.log('getOktaClientId response failure')
|
|
1464
|
-
}
|
|
1465
|
-
} else {
|
|
1466
|
-
return this.data.oktaClientId
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1470
1417
|
// API call
|
|
1471
1418
|
async getMediaIdFromContentId(gamePk, contentId) {
|
|
1472
1419
|
this.debuglog('getMediaIdFromContentId from ' + gamePk + ' and ' + contentId)
|
|
@@ -1586,14 +1533,14 @@ class sessionClass {
|
|
|
1586
1533
|
let reqObj = {
|
|
1587
1534
|
url: BAM_TOKEN_URL,
|
|
1588
1535
|
headers: {
|
|
1589
|
-
'Authorization': 'Bearer ' +
|
|
1536
|
+
'Authorization': 'Bearer ' + API_KEY,
|
|
1590
1537
|
'User-agent': USER_AGENT,
|
|
1591
1538
|
'Accept': 'application/vnd.media-service+json; version=1',
|
|
1592
1539
|
'x-bamsdk-version': BAM_SDK_VERSION,
|
|
1593
1540
|
'x-bamsdk-platform': PLATFORM,
|
|
1594
1541
|
'Origin': 'https://www.mlb.com',
|
|
1595
1542
|
'Accept-Encoding': 'gzip, deflate, br',
|
|
1596
|
-
'Content-type': 'application/
|
|
1543
|
+
'Content-type': 'application/x-www-form-urlencoded'
|
|
1597
1544
|
},
|
|
1598
1545
|
form: {
|
|
1599
1546
|
'grant_type': 'urn:ietf:params:oauth:grant-type:token-exchange',
|
|
@@ -1626,17 +1573,14 @@ class sessionClass {
|
|
|
1626
1573
|
let reqObj = {
|
|
1627
1574
|
url: 'https://media-entitlement.mlb.com/api/v3/jwt',
|
|
1628
1575
|
headers: {
|
|
1629
|
-
'Authorization': 'Bearer ' + await this.
|
|
1630
|
-
'Origin': 'https://www.mlb.com'
|
|
1631
|
-
'x-api-key': await this.getXApiKey() || this.halt('missing xApiKey'),
|
|
1632
|
-
'Accept-Encoding': 'gzip, deflate, br'
|
|
1576
|
+
'Authorization': 'Bearer ' + await this.getLoginToken() || this.halt('missing loginToken'),
|
|
1577
|
+
'Origin': 'https://www.mlb.com'
|
|
1633
1578
|
},
|
|
1634
1579
|
qs: {
|
|
1635
1580
|
'os': PLATFORM,
|
|
1636
1581
|
'did': await this.getDeviceId() || this.halt('missing deviceId'),
|
|
1637
1582
|
'appname': 'mlbtv_web'
|
|
1638
|
-
}
|
|
1639
|
-
gzip: true
|
|
1583
|
+
}
|
|
1640
1584
|
}
|
|
1641
1585
|
var response = await this.httpGet(reqObj)
|
|
1642
1586
|
if ( response ) {
|
|
@@ -1683,7 +1627,7 @@ class sessionClass {
|
|
|
1683
1627
|
let reqObj = {
|
|
1684
1628
|
url: BAM_TOKEN_URL,
|
|
1685
1629
|
headers: {
|
|
1686
|
-
'Authorization': 'Bearer ' +
|
|
1630
|
+
'Authorization': 'Bearer ' + API_KEY,
|
|
1687
1631
|
'Origin': 'https://www.mlb.com'
|
|
1688
1632
|
},
|
|
1689
1633
|
form: {
|
|
@@ -1712,7 +1656,7 @@ class sessionClass {
|
|
|
1712
1656
|
let reqObj = {
|
|
1713
1657
|
url: 'https://us.edge.bamgrid.com/devices',
|
|
1714
1658
|
headers: {
|
|
1715
|
-
'Authorization': 'Bearer ' +
|
|
1659
|
+
'Authorization': 'Bearer ' + API_KEY,
|
|
1716
1660
|
'Origin': 'https://www.mlb.com'
|
|
1717
1661
|
},
|
|
1718
1662
|
json: {
|
|
@@ -1732,113 +1676,40 @@ class sessionClass {
|
|
|
1732
1676
|
}
|
|
1733
1677
|
}
|
|
1734
1678
|
|
|
1735
|
-
async getOktaAccessToken() {
|
|
1736
|
-
this.debuglog('getOktaAccessToken')
|
|
1737
|
-
let oktaAccessToken = await this.retrieveOktaAccessToken()
|
|
1738
|
-
if ( oktaAccessToken ) return oktaAccessToken
|
|
1739
|
-
else {
|
|
1740
|
-
oktaAccessToken = await this.retrieveOktaAccessToken()
|
|
1741
|
-
if ( oktaAccessToken ) return oktaAccessToken
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1744
|
-
|
|
1745
|
-
// API call
|
|
1746
|
-
async retrieveOktaAccessToken() {
|
|
1747
|
-
this.debuglog('retrieveOktaAccessToken')
|
|
1748
|
-
if ( !this.data.oktaAccessToken || !this.data.oktaAccessTokenExpiry || (Date.parse(this.data.oktaAccessTokenExpiry) < new Date()) ) {
|
|
1749
|
-
this.debuglog('need to get new oktaAccessToken')
|
|
1750
|
-
let state = this.getRandomString(64)
|
|
1751
|
-
let nonce = this.getRandomString(64)
|
|
1752
|
-
let reqObj = {
|
|
1753
|
-
url: 'https://ids.mlb.com/oauth2/aus1m088yK07noBfh356/v1/authorize',
|
|
1754
|
-
headers: {
|
|
1755
|
-
'user-agent': USER_AGENT,
|
|
1756
|
-
'accept-encoding': 'identity'
|
|
1757
|
-
},
|
|
1758
|
-
qs: {
|
|
1759
|
-
'client_id': await this.getOktaClientId() || this.halt('missing oktaClientId'),
|
|
1760
|
-
'redirect_uri': 'https://www.mlb.com/login',
|
|
1761
|
-
'response_type': 'id_token token',
|
|
1762
|
-
'response_mode': 'okta_post_message',
|
|
1763
|
-
'state': state,
|
|
1764
|
-
'nonce': nonce,
|
|
1765
|
-
'prompt': 'none',
|
|
1766
|
-
'sessionToken': await this.getAuthnSessionToken() || this.halt('missing authnSessionToken'),
|
|
1767
|
-
'scope': 'openid email'
|
|
1768
|
-
}
|
|
1769
|
-
}
|
|
1770
|
-
var response = await this.httpGet(reqObj)
|
|
1771
|
-
if ( response ) {
|
|
1772
|
-
var str = response.toString()
|
|
1773
|
-
this.debuglog('retrieveOktaAccessToken response : ' + str)
|
|
1774
|
-
if ( str.match ) {
|
|
1775
|
-
var errorParsed = str.match("data.error = 'login_required'")
|
|
1776
|
-
if ( errorParsed ) {
|
|
1777
|
-
// Need to log in again
|
|
1778
|
-
this.log('Logging in...')
|
|
1779
|
-
delete this.data.authnSessionToken
|
|
1780
|
-
this.save_session_data()
|
|
1781
|
-
} else {
|
|
1782
|
-
var parsed_token = str.match("data.access_token = '([^']+)'")
|
|
1783
|
-
var parsed_expiry = str.match("data.expires_in = '([^']+)'")
|
|
1784
|
-
if ( parsed_token && parsed_token[1] && parsed_expiry && parsed_expiry[1] ) {
|
|
1785
|
-
let oktaAccessToken = parsed_token[1].split('\\x2D').join('-')
|
|
1786
|
-
let oktaAccessTokenExpiry = parsed_expiry[1]
|
|
1787
|
-
this.debuglog('retrieveOktaAccessToken : ' + oktaAccessToken)
|
|
1788
|
-
this.debuglog('retrieveOktaAccessToken expires in : ' + oktaAccessTokenExpiry)
|
|
1789
|
-
this.data.oktaAccessToken = oktaAccessToken
|
|
1790
|
-
this.data.oktaAccessTokenExpiry = new Date(new Date().getTime() + oktaAccessTokenExpiry * 1000)
|
|
1791
|
-
this.save_session_data()
|
|
1792
|
-
return this.data.oktaAccessToken
|
|
1793
|
-
} else {
|
|
1794
|
-
this.log('retrieveOktaAccessToken parse failure')
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
} else {
|
|
1798
|
-
this.log('retrieveOktaAccessToken string response failure')
|
|
1799
|
-
}
|
|
1800
|
-
} else {
|
|
1801
|
-
this.log('retrieveOktaAccessToken response failure')
|
|
1802
|
-
}
|
|
1803
|
-
} else {
|
|
1804
|
-
return this.data.oktaAccessToken
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
|
|
1808
1679
|
// API call
|
|
1809
|
-
async
|
|
1810
|
-
this.debuglog('
|
|
1811
|
-
if ( !this.data.
|
|
1812
|
-
this.debuglog('need to get
|
|
1680
|
+
async getLoginToken() {
|
|
1681
|
+
this.debuglog('getLoginToken')
|
|
1682
|
+
if ( !this.data.loginToken || !this.data.loginTokenExpiry || (Date.parse(this.data.loginTokenExpiry) < new Date()) ) {
|
|
1683
|
+
this.debuglog('need to get loginToken')
|
|
1813
1684
|
let reqObj = {
|
|
1814
|
-
url: 'https://ids.mlb.com/
|
|
1685
|
+
url: 'https://ids.mlb.com/oauth2/aus1m088yK07noBfh356/v1/token',
|
|
1815
1686
|
headers: {
|
|
1816
1687
|
'user-agent': USER_AGENT,
|
|
1817
|
-
'
|
|
1818
|
-
'content-type': 'application/json'
|
|
1688
|
+
'content-type': 'application/x-www-form-urlencoded'
|
|
1819
1689
|
},
|
|
1820
|
-
|
|
1690
|
+
form: {
|
|
1821
1691
|
'username': this.credentials.account_username || this.halt('missing account username'),
|
|
1822
1692
|
'password': this.credentials.account_password || this.halt('missing account password'),
|
|
1823
|
-
'
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
}
|
|
1693
|
+
'grant_type': 'password',
|
|
1694
|
+
'scope': 'openid offline_access',
|
|
1695
|
+
'client_id': '0oa3e1nutA1HLzAKG356'
|
|
1827
1696
|
}
|
|
1828
1697
|
}
|
|
1829
1698
|
var response = await this.httpPost(reqObj)
|
|
1830
|
-
if ( response
|
|
1831
|
-
|
|
1832
|
-
this.debuglog('
|
|
1833
|
-
this.
|
|
1699
|
+
if ( this.isValidJson(response) ) {
|
|
1700
|
+
let obj = JSON.parse(response)
|
|
1701
|
+
this.debuglog('getLoginToken : ' + obj.access_token)
|
|
1702
|
+
this.debuglog('getLoginToken expires in : ' + obj.expires_in)
|
|
1703
|
+
this.data.loginToken = obj.access_token
|
|
1704
|
+
this.data.loginTokenExpiry = new Date(new Date().getTime() + obj.expires_in * 1000)
|
|
1834
1705
|
this.save_session_data()
|
|
1835
|
-
return this.data.
|
|
1706
|
+
return this.data.loginToken
|
|
1836
1707
|
} else {
|
|
1837
|
-
this.log('
|
|
1708
|
+
this.log('getLoginToken response failure')
|
|
1838
1709
|
}
|
|
1839
1710
|
} else {
|
|
1840
|
-
this.debuglog('using cached
|
|
1841
|
-
return this.data.
|
|
1711
|
+
this.debuglog('using cached loginToken')
|
|
1712
|
+
return this.data.loginToken
|
|
1842
1713
|
}
|
|
1843
1714
|
}
|
|
1844
1715
|
|
|
@@ -3217,7 +3088,7 @@ class sessionClass {
|
|
|
3217
3088
|
url: playbackURL,
|
|
3218
3089
|
simple: false,
|
|
3219
3090
|
headers: {
|
|
3220
|
-
'Authorization': 'Bearer ' + await this.
|
|
3091
|
+
'Authorization': 'Bearer ' + await this.getLoginToken() || this.halt('missing loginToken'),
|
|
3221
3092
|
'User-agent': USER_AGENT,
|
|
3222
3093
|
'Accept': '*/*',
|
|
3223
3094
|
'Origin': 'https://www.mlb.com',
|