mlbserver 2022.8.31 → 2022.10.7

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
@@ -1,6 +1,6 @@
1
1
  # mlbserver
2
2
 
3
- Current version 2022.08.31
3
+ Current version 2022.10.07
4
4
 
5
5
  Credit to https://github.com/tonycpsu/streamglob and https://github.com/mafintosh/hls-decryptor
6
6
 
package/index.js CHANGED
@@ -1186,7 +1186,7 @@ app.get('/', async function(req, res) {
1186
1186
  }
1187
1187
  var cache_data = await session.getDayData(gameDate)
1188
1188
  var big_inning
1189
- if ( cache_data.dates && cache_data.dates[0] && cache_data.dates[0].games && (cache_data.dates[0].games.length > 0) ) {
1189
+ if ( cache_data.dates && cache_data.dates[0] && (cache_data.dates[0].date >= today) && cache_data.dates[0].games && (cache_data.dates[0].games.length > 0) && cache_data.dates[0].games[0] && (cache_data.dates[0].games[0].seriesDescription == 'Regular Season') ) {
1190
1190
  big_inning = await session.getBigInningSchedule(gameDate)
1191
1191
  }
1192
1192
 
@@ -1653,8 +1653,8 @@ app.get('/', async function(req, res) {
1653
1653
  let broadcast_count = await session.count_broadcasts(cache_data.dates[0].games[j].content.media.epg[k].items, mediaType, mediaTitle, language)
1654
1654
 
1655
1655
  for (var x = 0; x < cache_data.dates[0].games[j].content.media.epg[k].items.length; x++) {
1656
- // for video, check that pay TV authentication isn't required
1657
- if ( (mediaType == 'MLBTV') && await session.check_pay_tv(cache_data.dates[0].games[j].content.media.epg[k].items[x]) ) {
1656
+ // for video, check that it's not in-market
1657
+ if ( (mediaType == 'MLBTV') && await session.check_in_market(cache_data.dates[0].games[j].content.media.epg[k].items[x]) ) {
1658
1658
  continue
1659
1659
  }
1660
1660
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mlbserver",
3
- "version": "2022.08.31",
3
+ "version": "2022.10.07",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
package/session.js CHANGED
@@ -1916,8 +1916,8 @@ class sessionClass {
1916
1916
  broadcast_count = await this.count_broadcasts(cache_data.dates[0].games[j].content.media.epg[k].items, mediaType, mediaTitle, language)
1917
1917
 
1918
1918
  for (var x = 0; x < cache_data.dates[0].games[j].content.media.epg[k].items.length; x++) {
1919
- // for video, check that pay TV authentication isn't required
1920
- if ( (mediaType == 'MLBTV') && await this.check_pay_tv(cache_data.dates[0].games[j].content.media.epg[k].items[x]) ) {
1919
+ // for video, check that it's not in-market
1920
+ if ( (mediaType == 'MLBTV') && await this.check_in_market(cache_data.dates[0].games[j].content.media.epg[k].items[x]) ) {
1921
1921
  continue
1922
1922
  }
1923
1923
 
@@ -2085,7 +2085,7 @@ class sessionClass {
2085
2085
  let cache_data
2086
2086
  let cache_name = dateString
2087
2087
  //let data_url = 'https://bdfed.stitch.mlbinfra.com/bdfed/transform-mlb-scoreboard?stitch_env=prod&sortTemplate=2&sportId=1&sportId=17&startDate=' + dateString + '&endDate=' + dateString + '&gameType=E&&gameType=S&&gameType=R&&gameType=F&&gameType=D&&gameType=L&&gameType=W&&gameType=A&language=en&leagueId=104&leagueId=103&leagueId=131&contextTeamId='
2088
- let data_url = 'http://statsapi.mlb.com/api/v1/schedule?sportId=1,51&startDate=' + dateString + '&endDate=' + dateString + '&hydrate=game(content(media(epg))),probablePitcher,linescore,team,flags,gameInfo'
2088
+ let data_url = 'http://statsapi.mlb.com/api/v1/schedule?sportId=1&startDate=' + dateString + '&endDate=' + dateString + '&hydrate=game(content(media(epg))),probablePitcher,linescore,team,flags,gameInfo'
2089
2089
  if ( team && !team.toUpperCase().startsWith('NATIONAL.') && !team.toUpperCase().startsWith('FREE.') ) {
2090
2090
  this.debuglog('getDayData for team ' + team + ' on date ' + dateString)
2091
2091
  cache_name = team.toUpperCase() + dateString
@@ -2238,6 +2238,7 @@ class sessionClass {
2238
2238
 
2239
2239
  let cache_data = await this.getWeeksData()
2240
2240
  if (cache_data) {
2241
+ let today = this.liveDate()
2241
2242
  var channels = {}
2242
2243
  var nationalChannels = {}
2243
2244
  var programs = ""
@@ -2327,8 +2328,8 @@ class sessionClass {
2327
2328
  let broadcast_count = await this.count_broadcasts(cache_data.dates[i].games[j].content.media.epg[k].items, mediaType, mediaTitle, language)
2328
2329
 
2329
2330
  for (var x = 0; x < cache_data.dates[i].games[j].content.media.epg[k].items.length; x++) {
2330
- // for video, check that pay TV authentication isn't required
2331
- if ( (mediaType == 'MLBTV') && await this.check_pay_tv(cache_data.dates[i].games[j].content.media.epg[k].items[x]) ) {
2331
+ // for video, check that it's not in-market
2332
+ if ( (mediaType == 'MLBTV') && await this.check_in_market(cache_data.dates[i].games[j].content.media.epg[k].items[x]) ) {
2332
2333
  continue
2333
2334
  }
2334
2335
 
@@ -2497,7 +2498,10 @@ class sessionClass {
2497
2498
  let title = 'MLB Big Inning'
2498
2499
  let description = 'Live look-ins and big moments from around the league'
2499
2500
 
2500
- await this.getBigInningSchedule()
2501
+ if ( cache_data.dates && cache_data.dates[0] && (cache_data.dates[0].date >= today) && cache_data.dates[0].games && (cache_data.dates[0].games.length > 0) && cache_data.dates[0].games[0] && (cache_data.dates[0].games[0].seriesDescription == 'Regular Season') ) {
2502
+ await this.getBigInningSchedule()
2503
+ }
2504
+
2501
2505
  for (var i = 0; i < cache_data.dates.length; i++) {
2502
2506
  let gameDate = cache_data.dates[i].date
2503
2507
  if ( this.cache.bigInningSchedule[gameDate] && this.cache.bigInningSchedule[gameDate].start ) {
@@ -3314,48 +3318,51 @@ class sessionClass {
3314
3318
 
3315
3319
  let national_blackout = /(^\d{5}$)/.test(this.credentials.zip_code)
3316
3320
 
3317
- if ( national_blackout ) {
3318
- let regional_fox_games_exist
3319
- for (var j = 0; j < games.length; j++) {
3320
- let game_pk = games[j].gamePk.toString()
3321
- if ( games[j].content && games[j].content.media && games[j].content.media.epg ) {
3322
- for (var k = 0; k < games[j].content.media.epg.length; k++) {
3323
- if ( games[j].content.media.epg[k].title == 'MLBTV' ) {
3324
- for (var x = 0; x < games[j].content.media.epg[k].items.length; x++) {
3325
- if (games[j].content.media.epg[k].items[x].mediaFeedType == 'NATIONAL') {
3326
- if ( (games[j].content.media.epg[k].items[x].callLetters == 'FOX') && (games[j].seriesDescription == 'Regular Season') ) {
3327
- if ( !regional_fox_games_exist ) {
3328
- regional_fox_games_exist = await this.check_regional_fox_games(games)
3329
- }
3330
- if ( regional_fox_games_exist == 'false' ) {
3331
- blackouts[game_pk] = { blackout_type:'National' }
3332
- break
3333
- }
3334
- } else {
3321
+ let regional_fox_games_exist
3322
+ for (var j = 0; j < games.length; j++) {
3323
+ let game_pk = games[j].gamePk.toString()
3324
+ if ( games[j].content && games[j].content.media && games[j].content.media.epg ) {
3325
+ for (var k = 0; k < games[j].content.media.epg.length; k++) {
3326
+ if ( games[j].content.media.epg[k].title == 'MLBTV' ) {
3327
+ for (var x = 0; x < games[j].content.media.epg[k].items.length; x++) {
3328
+ if (games[j].content.media.epg[k].items[x].mediaFeedType == 'NATIONAL') {
3329
+ if ( national_blackout && (games[j].content.media.epg[k].items[x].callLetters == 'FOX') && (games[j].seriesDescription == 'Regular Season') ) {
3330
+ if ( !regional_fox_games_exist ) {
3331
+ regional_fox_games_exist = await this.check_regional_fox_games(games)
3332
+ }
3333
+ if ( regional_fox_games_exist == 'false' ) {
3335
3334
  blackouts[game_pk] = { blackout_type:'National' }
3336
3335
  break
3337
3336
  }
3338
- }
3339
-
3340
- let awayteam = games[j].teams['away'].team.abbreviation
3341
- let hometeam = games[j].teams['home'].team.abbreviation
3342
- if ( (games[j].seriesDescription != 'Spring Training') && (this.credentials.blackout_teams.includes(hometeam) || this.credentials.blackout_teams.includes(awayteam)) ) {
3343
- blackouts[game_pk] = { blackout_type:'Local' }
3337
+ } else {
3338
+ if ( (games[j].seriesDescription != 'Spring Training') && (games[j].seriesDescription != 'Regular Season') ) {
3339
+ blackouts[game_pk] = { blackout_type:'International' }
3340
+ } else if ( national_blackout ) {
3341
+ blackouts[game_pk] = { blackout_type:'National' }
3342
+ }
3344
3343
  break
3345
3344
  }
3346
3345
  }
3347
- break
3346
+
3347
+ let awayteam = games[j].teams['away'].team.abbreviation
3348
+ let hometeam = games[j].teams['home'].team.abbreviation
3349
+ if ( (games[j].seriesDescription != 'Spring Training') && (this.credentials.blackout_teams.includes(hometeam) || this.credentials.blackout_teams.includes(awayteam)) ) {
3350
+ blackouts[game_pk] = { blackout_type:'Local' }
3351
+ break
3352
+ }
3348
3353
  }
3354
+ break
3349
3355
  }
3356
+ }
3350
3357
 
3351
- // add blackout expiry, if requested
3352
- if ( blackouts[game_pk] && calculate_expiries && await this.check_game_time(games[j]) ) {
3353
- let blackoutExpiry = await this.get_blackout_expiry(games[j])
3354
- blackouts[game_pk].blackoutExpiry = blackoutExpiry
3355
- }
3358
+ // add blackout expiry, if requested
3359
+ if ( blackouts[game_pk] && calculate_expiries && await this.check_game_time(games[j]) ) {
3360
+ let blackoutExpiry = await this.get_blackout_expiry(games[j])
3361
+ blackouts[game_pk].blackoutExpiry = blackoutExpiry
3356
3362
  }
3357
3363
  }
3358
3364
  }
3365
+
3359
3366
  return blackouts
3360
3367
  }
3361
3368
 
@@ -3841,8 +3848,8 @@ class sessionClass {
3841
3848
  async count_broadcasts(items, mediaType, mediaTitle, language) {
3842
3849
  let broadcast_count = 0
3843
3850
  for (var x = 0; x < items.length; x++) {
3844
- // for video, check that it's not in-market and that pay TV authentication isn't required
3845
- if ( (mediaType == 'MLBTV') && await this.check_pay_tv(items[x]) ) {
3851
+ // for video, check that it's not in-market
3852
+ if ( (mediaType == 'MLBTV') && await this.check_in_market(items[x]) ) {
3846
3853
  continue
3847
3854
  } else if ( mediaType == mediaTitle ) {
3848
3855
  if ( ((typeof items[x].language) == 'undefined') || ((mediaType == 'Audio') && (items[x].language == language)) ) {
@@ -3853,9 +3860,20 @@ class sessionClass {
3853
3860
  return broadcast_count
3854
3861
  }
3855
3862
 
3863
+ async check_in_market(item) {
3864
+ try {
3865
+ if ( item.mediaFeedType.startsWith('IN_MARKET_') ) {
3866
+ return true
3867
+ }
3868
+ } catch (e) {
3869
+ return false
3870
+ }
3871
+ return false
3872
+ }
3873
+
3856
3874
  async check_pay_tv(item) {
3857
3875
  try {
3858
- if ( (item.mediaFeedType.startsWith('IN_MARKET_') || item.foxAuthRequired || item.tbsAuthRequired || item.espnAuthRequired || item.fs1AuthRequired || item.mlbnAuthRequired) ) {
3876
+ if ( item.foxAuthRequired || item.tbsAuthRequired || item.espnAuthRequired || item.fs1AuthRequired || item.mlbnAuthRequired ) {
3859
3877
  return true
3860
3878
  }
3861
3879
  } catch (e) {