@@ -571,21 +571,89 @@ def create_linear_channel_listitem(network):
571571# display a Big Inning item within a game list
572572def create_big_inning_listitem (game_day ):
573573 try :
574- display_title = LOCAL_STRING (30368 )
575- name = display_title
576-
577- desc = 'MLB Big Inning brings fans all the best action from around the league with live look-ins, breaking highlights and big moments as they happen all season long. Airing seven days a week on MLB.TV.'
578-
579- # create the list item
580- liz = xbmcgui .ListItem (name )
581- liz .setInfo ( type = "Video" , infoLabels = { "Title" : display_title , 'plot' : desc } )
582- liz .setProperty ("IsPlayable" , "true" )
583- icon = 'https://img.mlbstatic.com/mlb-images/image/private/ar_16:9,g_auto,q_auto:good,w_372,c_fill,f_jpg/mlb/uwr8vepua4t1fe8uwyki'
584- fanart = 'https://img.mlbstatic.com/mlb-images/image/private/g_auto,c_fill,ar_16:9,q_60,w_1920/e_gradient_fade:15,x_0.6,b_black/mlb/uwr8vepua4t1fe8uwyki'
585- liz .setArt ({'icon' : icon , 'thumb' : icon , 'fanart' : fanart })
586- u = sys .argv [0 ]+ "?mode=" + str (301 )+ "&featured_video=" + urllib .quote_plus (LOCAL_STRING (30367 ) + LOCAL_STRING (30368 ))+ "&name=" + urllib .quote_plus (LOCAL_STRING (30367 ) + LOCAL_STRING (30368 ))
587- xbmcplugin .addDirectoryItem (handle = addon_handle ,url = u ,listitem = liz ,isFolder = False )
588- xbmcplugin .setContent (addon_handle , 'episodes' )
574+ # check when we last fetched the Big Inning schedule
575+ today = localToEastern ()
576+ big_inning_date = str (settings .getSetting (id = "big_inning_date" ))
577+
578+ # if we've already fetched it today, use the cached schedule
579+ if big_inning_date == today :
580+ xbmc .log ('Using cached Big Inning schedule' )
581+ big_inning_schedule = json .loads (settings .getSetting (id = "big_inning_schedule" ))
582+ # otherwise, fetch a new big inning schedule
583+ else :
584+ xbmc .log ('Fetching Big Inning schedule' )
585+ settings .setSetting (id = 'big_inning_date' , value = today )
586+ url = 'https://api.fubo.tv/gg/series/123881219/live-programs?limit=14&languages=en&countrySlugs=USA'
587+
588+ headers = {
589+ 'accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' ,
590+ 'accept-language' : 'en-US,en;q=0.9' ,
591+ 'cache-control' : 'no-cache' ,
592+ 'dnt' : '1' ,
593+ 'pragma' : 'no-cache' ,
594+ 'sec-fetch-dest' : 'document' ,
595+ 'sec-fetch-mode' : 'navigate' ,
596+ 'sec-fetch-site' : 'none' ,
597+ 'sec-fetch-user' : '?1' ,
598+ 'sec-gpc' : '1' ,
599+ 'upgrade-insecure-requests' : '1' ,
600+ 'user-agent' : UA_PC
601+ }
602+ r = requests .get (url ,headers = headers , verify = VERIFY )
603+ #xbmc.log(r.text)
604+
605+ # parse the response
606+ json_source = r .json ()
607+
608+ big_inning_schedule = {}
609+ if 'data' in json_source :
610+ for entry in json_source ['data' ]:
611+ if 'airings' in entry and len (entry ['airings' ]) > 0 and entry ['airings' ][0 ] and 'accessRights' in entry ['airings' ][0 ] and 'live' in entry ['airings' ][0 ]['accessRights' ]:
612+ airing = entry ['airings' ][0 ]['accessRights' ]['live' ]
613+ big_inning_date = get_eastern_game_date (parse (airing ['startTime' ]))
614+ xbmc .log ('Formatted date ' + big_inning_date )
615+ # ignore dates in the past
616+ if big_inning_date >= today :
617+ big_inning_start = str (UTCToLocal (parse (airing ['startTime' ])))
618+ big_inning_end = str (UTCToLocal (parse (airing ['endTime' ])))
619+ big_inning_schedule [big_inning_date ] = {'start' : big_inning_start , 'end' : big_inning_end }
620+ # save the scraped schedule
621+ settings .setSetting (id = 'big_inning_schedule' , value = json .dumps (big_inning_schedule ))
622+
623+ if game_day in big_inning_schedule :
624+ xbmc .log (game_day + ' has a scheduled Big Inning broadcast' )
625+ display_title = LOCAL_STRING (30368 )
626+
627+ big_inning_start = parse (big_inning_schedule [game_day ]['start' ])
628+ big_inning_end = parse (big_inning_schedule [game_day ]['end' ])
629+
630+ # format the time for display
631+
632+ game_time = get_display_time (big_inning_start ) + ' - ' + get_display_time (big_inning_end )
633+ now = datetime .now ()
634+ if now < big_inning_start :
635+ game_time = colorString (game_time , UPCOMING )
636+ elif now > big_inning_end :
637+ game_time = colorString (game_time , FINAL )
638+ elif now >= big_inning_start and now <= big_inning_end :
639+ display_title = LOCAL_STRING (30367 ) + LOCAL_STRING (30368 )
640+ game_time = colorString (game_time , LIVE )
641+ name = game_time + ' ' + display_title
642+
643+ desc = 'MLB Big Inning brings fans all the best action from around the league with live look-ins, breaking highlights and big moments as they happen all season long. Airing seven days a week on MLB.TV.'
644+
645+ # create the list item
646+ liz = xbmcgui .ListItem (name )
647+ liz .setInfo ( type = "Video" , infoLabels = { "Title" : display_title , 'plot' : desc } )
648+ liz .setProperty ("IsPlayable" , "true" )
649+ icon = 'https://img.mlbstatic.com/mlb-images/image/private/ar_16:9,g_auto,q_auto:good,w_372,c_fill,f_jpg/mlb/uwr8vepua4t1fe8uwyki'
650+ fanart = 'https://img.mlbstatic.com/mlb-images/image/private/g_auto,c_fill,ar_16:9,q_60,w_1920/e_gradient_fade:15,x_0.6,b_black/mlb/uwr8vepua4t1fe8uwyki'
651+ liz .setArt ({'icon' : icon , 'thumb' : icon , 'fanart' : fanart })
652+ u = sys .argv [0 ]+ "?mode=" + str (301 )+ "&featured_video=" + urllib .quote_plus (LOCAL_STRING (30367 ) + LOCAL_STRING (30368 ))+ "&name=" + urllib .quote_plus (LOCAL_STRING (30367 ) + LOCAL_STRING (30368 ))
653+ xbmcplugin .addDirectoryItem (handle = addon_handle ,url = u ,listitem = liz ,isFolder = False )
654+ xbmcplugin .setContent (addon_handle , 'episodes' )
655+ else :
656+ xbmc .log (game_day + ' does not have a scheduled Big Inning broadcast' )
589657 except Exception as e :
590658 xbmc .log ('big inning error : ' + str (e ))
591659 pass
0 commit comments