Advertisement
Guest User

Untitled

a guest
Apr 6th, 2014
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.88 KB | None | 0 0
  1. import os
  2. import re
  3. import sys
  4. import cookielib
  5. import urllib
  6. import time
  7. import xbmc
  8. import xbmcplugin
  9. import xbmcgui
  10. import xbmcaddon
  11. import StorageServer
  12. from mlb_common import TeamCodes, addon_log, coloring, getRequest
  13. from BeautifulSoup import BeautifulStoneSoup, BeautifulSoup
  14. from subprocess import Popen, PIPE, STDOUT
  15. import tempfile
  16. import platform
  17.  
  18. addon = xbmcaddon.Addon(id='plugin.video.mlbmc.hls')
  19. profile = xbmc.translatePath(addon.getAddonInfo('profile'))
  20. home = xbmc.translatePath(addon.getAddonInfo('path'))
  21. language = addon.getLocalizedString
  22. icon = os.path.join(home, 'icon.png')
  23. cookie_file = os.path.join(profile, 'cookie_file')
  24. cookie_jar = cookielib.LWPCookieJar(cookie_file)
  25. debug = addon.getSetting('debug')
  26. fanart1 = 'http://mlbmc-xbmc.googlecode.com/svn/icons/fanart1.jpg'
  27. system_os = platform.system()
  28.  
  29. SOAPCODES = {
  30. "1" : "OK",
  31. "-1000": "Requested Media Not Found",
  32. "-1500": "Other Undocumented Error",
  33. "-2000": "Authentication Error",
  34. "-2500": "Blackout Error",
  35. "-3000": "Identity Error",
  36. "-3500": "Sign-on Restriction Error",
  37. "-4000": "System Error",
  38. }
  39.  
  40.  
  41. def mlb_login():
  42. addon_log('Login to get cookies!')
  43. # Get the cookie first
  44. url = 'https://secure.mlb.com/enterworkflow.do?flowId=registration.wizard&c_id=mlb'
  45. headers = {'User-agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0'}
  46. login = getRequest(url,None,headers)
  47.  
  48. # now authenticate
  49. url = 'https://secure.mlb.com/authenticate.do'
  50. headers = {'User-agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0',
  51. 'Referer' : 'https://secure.mlb.com/enterworkflow.do?flowId=registration.wizard&c_id=mlb'}
  52. values = {'uri' : '/account/login_register.jsp',
  53. 'registrationAction' : 'identify',
  54. 'emailAddress' : addon.getSetting('email'),
  55. 'password' : addon.getSetting('password')}
  56. login = getRequest(url,urllib.urlencode(values),headers)
  57. cookie_jar.load(cookie_file, ignore_discard=False, ignore_expires=False)
  58. cookies = {}
  59. addon_log('These are the cookies we have received from authenticate.do:')
  60. for i in cookie_jar:
  61. cookies[i.name] = i.value
  62. addon_log('%s: %s' %(i.name, i.value))
  63.  
  64. pattern = re.compile(r'Welcome to your personal (MLB|mlb).com account.')
  65. try:
  66. loggedin = re.search(pattern, login).groups()
  67. addon_log( "Logged in successfully!" )
  68. except:
  69. addon_log("Login Failed!")
  70. try:
  71. soup = BeautifulSoup(login)
  72. addon_log(str(soup.head.title))
  73. except: pass
  74. xbmc.executebuiltin("XBMC.Notification("+language(30035)+","+language(30042)+",5000,"+icon+")")
  75.  
  76. if cookies.has_key('ipid') and cookies.has_key('fprt'):
  77. return True
  78. else:
  79. return False
  80.  
  81.  
  82. def mlbGame(event_id, full_count=False):
  83. if not full_count:
  84. # Check if cookies have expired.
  85. cookie_jar.load(cookie_file, ignore_discard=True, ignore_expires=False)
  86. cookies = {}
  87. addon_log('These are the cookies we have in the cookie file:')
  88. for i in cookie_jar:
  89. cookies[i.name] = i.value
  90. addon_log('%s: %s' %(i.name, i.value))
  91. if cookies.has_key('ipid') and cookies.has_key('fprt'):
  92. addon_log('We have valid cookies')
  93. login = 'old'
  94. else:
  95. login = mlb_login()
  96.  
  97. if not login:
  98. addon_log( "Seems to ba a cookie problem" )
  99. xbmc.executebuiltin("XBMC.Notification("+language(30035)+","+language(30043)+",10000,"+icon+")")
  100. return
  101.  
  102. if login == 'old':
  103. # lets see if we get new cookies
  104. addon_log('old cookies: ipid - %s , fprt - %s' %(cookies['ipid'], cookies['fprt']))
  105. url = 'http://mlb.mlb.com/enterworkflow.do?flowId=media.media'
  106. data = getRequest(url,None,None)
  107. addon_log('These are the cookies we have after enterworkflow.do?flowId=media.media:')
  108.  
  109. cookie_jar.load(cookie_file, ignore_discard=True, ignore_expires=True)
  110. cookies = {}
  111. for i in cookie_jar:
  112. cookies[i.name] = i.value
  113. addon_log('%s: %s' %(i.name, i.value))
  114. session = None
  115. if cookies.has_key('ftmu'):
  116. addon_log("cookies.has_key('ftmu')")
  117. session = urllib.unquote(cookies['ftmu'])
  118.  
  119. values = {
  120. 'eventId': event_id,
  121. 'sessionKey': session,
  122. 'fingerprint': urllib.unquote(cookies['fprt']),
  123. 'identityPointId': cookies['ipid'],
  124. 'subject':'LIVE_EVENT_COVERAGE',
  125. 'platform':'WEB_MEDIAPLAYER'
  126. }
  127. else:
  128. values = {
  129. 'platform':'WEB_MEDIAPLAYER',
  130. 'eventId':event_id,
  131. 'subject':'MLB_FULLCOUNT'
  132. }
  133. url = 'https://mlb-ws.mlb.com/pubajaxws/bamrest/MediaService2_0/op-findUserVerifiedEvent/v-2.3?'
  134. headers = {'User-agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0',
  135. 'Referer' : 'http://mlb.mlb.com/shared/flash/mediaplayer/v4.3/R1/MediaPlayer4.swf?v=14'}
  136. data = getRequest(url,urllib.urlencode(values),headers)
  137. if debug == "true":
  138. addon_log(data)
  139. soup = BeautifulStoneSoup(data)
  140. status = soup.find('status-code').string
  141. if status != "1":
  142. try:
  143. error_str = SOAPCODES[status]
  144. except:
  145. error_str = 'Unknown Error'
  146. addon_log(error_str)
  147. if not full_count:
  148. if login == 'old':
  149. cookie_jar.clear()
  150. login = mlb_login()
  151. if not login:
  152. xbmc.executebuiltin("XBMC.Notification("+language(30035)+","+language(30044)+error_str+",10000,"+icon+")")
  153. return
  154. else:
  155. cookie_jar.load(cookie_file, ignore_discard=True, ignore_expires=True)
  156. cookies = {}
  157. for i in cookie_jar:
  158. cookies[i.name] = i.value
  159. addon_log('%s: %s' %(i.name, i.value))
  160. session = None
  161. if cookies.has_key('ftmu'):
  162. addon_log("cookies.has_key('ftmu')")
  163. session = urllib.unquote(cookies['ftmu'])
  164.  
  165. values = {
  166. 'eventId': event_id,
  167. 'sessionKey': session,
  168. 'fingerprint': urllib.unquote(cookies['fprt']),
  169. 'identityPointId': cookies['ipid'],
  170. 'subject':'LIVE_EVENT_COVERAGE',
  171. 'platform':'WEB_MEDIAPLAYER'
  172. }
  173. data = getRequest(url,urllib.urlencode(values),headers)
  174. else:
  175. return
  176. cookie_jar.load(cookie_file, ignore_discard=True, ignore_expires=True)
  177. cookies = {}
  178. addon_log('These are the cookies we have after UserVerifiedEvent request 1:')
  179. for i in cookie_jar:
  180. cookies[i.name] = i.value
  181. addon_log('%s: %s' %(i.name, i.value))
  182. try:
  183. session_key = soup.find('session-key').string
  184. except AttributeError:
  185. session_key = None
  186. if session_key:
  187. session = session_key
  188.  
  189. Innings = False
  190. if not full_count:
  191. innings_url = soup.find('innings-index').string
  192. if len(innings_url) > 1:
  193. Innings = True
  194.  
  195. event_id = soup.find('event-id').string
  196. items = soup.findAll('user-verified-content')
  197. verified_content = {'video': [], 'audio': []}
  198. for item in items:
  199. audio = False
  200. if item.state.string == 'MEDIA_ARCHIVE':
  201. if not addon.getSetting('hls') == 'true':
  202. if int(event_id.split('-')[2]) < 2012:
  203. scenario = addon.getSetting('archive_scenario')
  204. else:
  205. scenario = 'FMS_CLOUD'
  206. else:
  207. scenario = 'HTTP_CLOUD_WIRED_WEB'
  208. live = False
  209. else:
  210. if not addon.getSetting('hls') == 'true':
  211. scenario = 'FMS_CLOUD'
  212. else:
  213. scenario = 'HTTP_CLOUD_WIRED_WEB'
  214. live = True
  215.  
  216. content_id = item('content-id')[0].string
  217. if full_count:
  218. name = 'full_count'
  219. session = ''
  220. return getGameURL(name,event_id,content_id,session,None,None,scenario,True,None)
  221. else:
  222. # post season games have blackout status even when they arent
  223. if int(event_id.split('-')[-2]) >= 9:
  224. blackout_status = item('blackout-status')[0]
  225. try:
  226. blackout = item('blackout')[0].string.replace('_',' ')
  227. except:
  228. blackout = language(30031)
  229. else:
  230. addon_log('ignoring blackout: %s' %item('blackout-status')[0])
  231.  
  232. try:
  233. call_letters = item('domain-attribute', attrs={'name' : "call_letters"})[0].string
  234. except:
  235. call_letters = ''
  236.  
  237. if item('domain-attribute', attrs={'name' : "home_team_id"})[0].string == item('domain-attribute', attrs={'name' : "coverage_association"})[0].string:
  238. coverage = TeamCodes[item('domain-attribute', attrs={'name' : "home_team_id"})[0].string][0]+' Coverage'
  239. elif item('domain-attribute', attrs={'name' : "away_team_id"})[0].string == item('domain-attribute', attrs={'name' : "coverage_association"})[0].string:
  240. coverage = TeamCodes[item('domain-attribute', attrs={'name' : "away_team_id"})[0].string][0]+' Coverage'
  241. else:
  242. coverage = ''
  243.  
  244. name = coverage+' - '+call_letters
  245.  
  246. if item.type.string == 'audio':
  247. audio = True
  248. name += ' Gameday Audio'
  249. scenario = 'AUDIO_FMS_32K'
  250.  
  251. name = name.replace('.','').rstrip(' ')
  252.  
  253. if item.state.string == 'MEDIA_OFF':
  254. addon_log('MEDIA_OFF: %s' %name)
  255. continue
  256.  
  257. else:
  258. start = None
  259. if Innings:
  260. if addon.getSetting('lookup_innings') == 'true':
  261. start = innings_url
  262. if audio:
  263. verified_content['audio'].append((name,event_id,content_id,session,cookies['ipid'],cookies['fprt'],scenario,live,start))
  264. else:
  265. verified_content['video'].append((name,event_id,content_id,session,cookies['ipid'],cookies['fprt'],scenario,live,start))
  266.  
  267. index = 0
  268. name_list = []
  269. sorted_content = {}
  270. for i in verified_content['video'] + verified_content['audio']:
  271. sorted_content[index] = i
  272. name_list.append(i[0])
  273. index += 1
  274.  
  275. dialog = xbmcgui.Dialog()
  276. ret = dialog.select(language(30033), name_list)
  277. if ret >= 0:
  278. addon_log('Selected: %s' %name_list[ret])
  279. addon_log('content: %s' %sorted_content[ret][0])
  280. if addon.getSetting('lookup_innings') == 'true':
  281. getInnings(*sorted_content[ret])
  282. else:
  283. getGameURL(*sorted_content[ret])
  284.  
  285.  
  286. def getGameURL(name,event,content,session,cookieIp,cookieFp,scenario,live,start):
  287. if name == 'full_count':
  288. subject = 'MLB_FULLCOUNT'
  289. url = 'https://mlb-ws.mlb.com/pubajaxws/bamrest/MediaService2_0/op-findUserVerifiedEvent/v-2.3?'
  290. else:
  291. subject = 'LIVE_EVENT_COVERAGE'
  292. url = 'https://secure.mlb.com/pubajaxws/bamrest/MediaService2_0/op-findUserVerifiedEvent/v-2.1?'
  293.  
  294. try:
  295. cookieFp = urllib.unquote(cookieFp)
  296. except AttributeError:
  297. pass
  298. values = {
  299. 'subject': subject,
  300. 'sessionKey': session,
  301. 'identityPointId': cookieIp,
  302. 'contentId': content,
  303. 'playbackScenario': scenario,
  304. 'eventId': event,
  305. 'fingerprint': cookieFp,
  306. 'platform':'WEB_MEDIAPLAYER'
  307. }
  308.  
  309. data = getRequest(url,urllib.urlencode(values),None)
  310. if debug == "true":
  311. addon_log(data)
  312. soup = BeautifulStoneSoup(data, convertEntities=BeautifulStoneSoup.XML_ENTITIES)
  313. try:
  314. new_fprt = soup.find('updated-fingerprint').string
  315. if len(new_fprt) > 0:
  316. addon_log('New Fingerprint: %s' %new_fprt)
  317. new_cookie = cookielib.Cookie(
  318. version=0, name='fprt', value=new_fprt, port=None, port_specified=False,
  319. domain='.mlb.com', domain_specified=False, domain_initial_dot=False,
  320. path='/', path_specified=True, secure=False, expires=None, discard=True,
  321. comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False)
  322. cookie_jar.load(cookie_file, ignore_discard=True, ignore_expires=True)
  323. cookie_jar.set_cookie(new_cookie)
  324. cookie_jar.save(cookie_file, ignore_discard=True, ignore_expires=True)
  325. cookieFp = new_fprt
  326. except AttributeError:
  327. addon_log('No New Fingerprint')
  328. status = soup.find('status-code').string
  329. if status != "1":
  330. try:
  331. error_str = SOAPCODES[status]
  332. xbmc.executebuiltin("XBMC.Notification("+language(30035)+","+language(30044)+error_str+",10000,"+icon+")")
  333. except:
  334. addon_log ( 'Unknown status-code: '+status )
  335. xbmc.executebuiltin("XBMC.Notification("+language(30035)+","+language(30046)+status+",10000,"+icon+")")
  336. return
  337.  
  338. elif soup.find('state').string == 'MEDIA_OFF':
  339. addon_log( 'Status : Media Off' )
  340. try:
  341. preview = soup.find('preview-url').contents[0]
  342. if re.search('innings-index',str(preview)):
  343. if debug == "true":
  344. addon_log( 'No preview' )
  345. raise Exception
  346. else:
  347. xbmc.executebuiltin("XBMC.Notification("+language(30035)+","+language(30045)+language(30047)+",10000,"+icon+")")
  348. item = xbmcgui.ListItem(path=preview)
  349. xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, item)
  350. except:
  351. xbmc.executebuiltin("XBMC.Notification("+language(30035)+","+language(30045)+",5000,"+icon+")")
  352. return
  353.  
  354. elif not 'successstatus' in str(soup.find('blackout-status')):
  355. # post season games have blackout status even when they arent
  356. if int(event.split('-')[-2]) >= 9:
  357. addon_log( 'Status : Blackout' )
  358. try:
  359. blackout = item('blackout')[0].string.replace('_',' ')
  360. except:
  361. blackout = 'Blackout'
  362. try:
  363. preview = soup.find('preview-url').contents[0]
  364. if re.search('innings-index',str(preview)):
  365. if debug == "true":
  366. addon_log( 'No preview' )
  367. raise Exception
  368. else:
  369. xbmc.executebuiltin("XBMC.Notification("+language(30035)+","+language(30044)+blackout+language(30047)+",15000,"+icon+")")
  370. item = xbmcgui.ListItem(path=preview)
  371. xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, item)
  372. except:
  373. xbmc.executebuiltin("XBMC.Notification("+language(30035)+","+language(30044)+blackout+language(30047)+",5000,"+icon+")")
  374. return
  375. else:
  376. addon_log('ignoring blackout: %s' %item('blackout-status')[0])
  377.  
  378. elif 'notauthorizedstatus' in str(soup.find('auth-status')):
  379. addon_log( 'Status : Not Authorized' )
  380. try:
  381. preview = soup.find('preview-url').contents[0]
  382. if re.search('innings-index',str(preview)):
  383. if debug == "true":
  384. addon_log( 'No preview' )
  385. raise Exception
  386. else:
  387. xbmc.executebuiltin("XBMC.Notification("+language(30035)+","+language(30048)+language(30047)+",15000,"+icon+")")
  388. item = xbmcgui.ListItem(path=preview)
  389. xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, item)
  390. except:
  391. xbmc.executebuiltin("XBMC.Notification("+language(30035)+","+language(30048)+",5000,"+icon+")")
  392. return
  393.  
  394. else:
  395. try:
  396. game_url = soup.findAll('user-verified-content')[0]('user-verified-media-item')[0]('url')[0].string
  397. if debug == "true":
  398. addon_log( 'game_url = '+game_url )
  399. except:
  400. addon_log( 'game_url not found' )
  401. xbmc.executebuiltin("XBMC.Notification("+language(30035)+","+language(30049)+",5000,"+icon+")")
  402. return
  403.  
  404. innings_url = soup.find('innings-index').string
  405. if scenario == "HTTP_CLOUD_WIRED_WEB":
  406. addon_log('Starting HLS')
  407. tmp_setting = addon.getSetting('tmp_dir')
  408. if tmp_setting == '':
  409. tmp_setting = None
  410. tmpdir = tempfile.mkdtemp(suffix='', prefix='mlbtv.tmp-', dir=tmp_setting)
  411. filename = os.path.join(tmpdir, name.replace(' ','_')+'.ts')
  412. addon_log('Temp File: '+filename)
  413.  
  414. if addon.getSetting('fifo') == 'true':
  415. try:
  416. os.mkfifo(filename)
  417. except OSError, e:
  418. addon_log( "Failed to create FIFO: %s" % e )
  419.  
  420.  
  421. if len(addon.getSetting('mlbhls')) > 1:
  422. target = addon.getSetting('mlbhls')
  423. else:
  424. if system_os == 'Windows':
  425. target = os.path.join(home, 'resources', 'mlbhls', 'mlbhls_win32', 'mlbhls.exe')
  426. else:
  427. target = 'mlbhls'
  428.  
  429. target += ' -B '+game_url+' -o '+filename
  430.  
  431. if addon.getSetting('hls_lock') == 'true':
  432. target += ' -L'
  433.  
  434. bitrate_values = {
  435. '0':' 4500000',
  436. '1':' 3000000',
  437. '2':' 2400000',
  438. '3':' 1800000',
  439. '4':' 1200000',
  440. '5':' 800000',
  441. '6':' 500000'
  442. }
  443.  
  444. start_bitrate = addon.getSetting('hls_start')
  445. if not name == 'full_count':
  446. target += ' -s'+bitrate_values[start_bitrate]
  447. else:
  448. if addon.getSetting('hls_start') == '0':
  449. target += ' -s'+bitrate_values['1']
  450. else:
  451. target += ' -s'+bitrate_values[start_bitrate]
  452.  
  453. if addon.getSetting('hls_lock') == 'false':
  454. max_bitrate = addon.getSetting('hls_max')
  455. if not max_bitrate == '7':
  456. target += ' -b'+bitrate_values[max_bitrate]
  457. min_bitrate = addon.getSetting('hls_min')
  458. if not min_bitrate == '7':
  459. target += ' -m'+bitrate_values[min_bitrate]
  460.  
  461. if not name == 'full_count':
  462. start_values = {
  463. '0':' 0',
  464. '1':' 5',
  465. '2':' 10',
  466. '3':' 20',
  467. '4':' 30',
  468. '5':' 40',
  469. '6':' 50',
  470. '7':' 60',
  471. '8':' 70',
  472. '9':' 80',
  473. '10':' 90',
  474. '11':' 100'
  475. }
  476. start_block = addon.getSetting('hls_start_block')
  477. if start != '' and start is not None:
  478. target += ' -F ' + start
  479. elif live and addon.getSetting('hls_start_time') == 'false':
  480. target += ' -f 0'
  481. elif addon.getSetting('hls_start_time') == 'false' and addon.getSetting('lookup_innings') == 'false':
  482. target += ' -f' + start_values[start_block]
  483. elif not name == 'full_count':
  484. if (not live) or (addon.getSetting('hls_start_time') == 'true'):
  485. try:
  486. start_time = getStartTime(innings_url, 'start')
  487. target += ' -F ' + start_time
  488. except:
  489. addon_log('getStartTime exception')
  490. target += ' -f 50'
  491.  
  492. addon_log( 'Target: '+target )
  493. script = os.path.join(home, 'resources', 'mlbtv_player.py')
  494. return xbmc.executebuiltin("XBMC.RunScript(%s, %s, %s, %s, %s)" %(script, filename, tmpdir, event, target))
  495.  
  496.  
  497. elif game_url.startswith('rtmp'):
  498. if re.search('ondemand', game_url):
  499. rtmp = game_url.split('ondemand/')[0]+'ondemand?_fcs_vhost=cp65670.edgefcs.net&akmfv=1.6&'+game_url.split('?')[1]
  500. playpath = ' Playpath='+game_url.split('ondemand/')[1]
  501. if re.search('live/', game_url):
  502. rtmp = game_url.split('mlb_')[0]
  503. playpath = ' Playpath=mlb_'+game_url.split('mlb_')[1]
  504. else:
  505. smil = get_smil(game_url.split('?')[0])
  506. rtmp = smil[0]
  507. playpath = ' Playpath='+smil[1]+'?'+game_url.split('?')[1]
  508.  
  509.  
  510. if name == 'full_count':
  511. pageurl = (' pageUrl=http://mlb.mlb.com/shared/flash/mediaplayer/v4.4/R3/MP4.jsp?calendar_event_id=%s'
  512. '&content_id=&media_id=&view_key=&media_type=&source=FULLCOUNT&sponsor=FULLCOUNT&clickOrigin=&affiliateId='
  513. % soup.find('event-id').string)
  514. elif 'mp3:' in game_url:
  515. pageurl = (' pageUrl=http://mlb.mlb.com/shared/flash/mediaplayer/v4.4/R1/MP4.jsp?calendar_event_id='
  516. '%s&content_id=%s&media_id=&view_key=&media_type=audio&source=MLB&sponsor=MLB&'
  517. 'clickOrigin=Media+Grid&affiliateId=Media+Grid&feed_code=h&team=mlb'
  518. %(soup.find('event-id').string, content))
  519. else:
  520. pageurl = (' pageUrl=http://mlb.mlb.com/shared/flash/mediaplayer/v4.4/R4/MP4.jsp?calendar_event_id=%s&content_id='
  521. '&media_id=&view_key=&media_type=video&source=MLB&sponsor=MLB&clickOrigin=&affiliateId=&team=mlb'
  522. % soup.find('event-id').string)
  523. swfurl = ' swfUrl=http://mlb.mlb.com/shared/flash/mediaplayer/v4.4/R4/MediaPlayer4.swf swfVfy=1'
  524. if live:
  525. swfurl += ' live=1'
  526. final_url = rtmp+playpath+pageurl+swfurl
  527. if debug == "true":
  528. addon_log( 'Name: '+name )
  529. addon_log( 'final url: '+final_url )
  530. item = xbmcgui.ListItem(path=final_url)
  531. xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, item)
  532.  
  533.  
  534. def getStartTime(url, start=False):
  535. soup = BeautifulStoneSoup(getRequest(url), convertEntities=BeautifulStoneSoup.XML_ENTITIES)
  536. try:
  537. start_time = soup.game['start_timecode']
  538. addon_log('Start Time: %s' %start_time)
  539. except:
  540. start_time = None
  541. if start:
  542. return start_time
  543. else:
  544. innings_list = []
  545. if start_time:
  546. inning = ('Start', start_time, start_time)
  547. innings_list.append(inning)
  548. items = soup('inningtimes')
  549. for i in items:
  550. inning_number = i['inning_number']
  551. hls_start = i('inningtime', attrs={'type' : 'SCAST'})[0]['start']
  552. fms_start = i('inningtime', attrs={'type' : 'FMS'})[0]['start']
  553. if i['top'] == "true":
  554. inning_number += ' Top'
  555. else:
  556. inning_number += ' Bottom'
  557. addon_log('inning: %s hls_start: %s fms_start: %s' %(inning_number, hls_start, fms_start))
  558. inning = (inning_number, hls_start, fms_start)
  559. innings_list.append(inning)
  560. return innings_list
  561.  
  562.  
  563. def get_smil(url):
  564. soup = BeautifulStoneSoup(getRequest(url))
  565. base = soup.meta['base']
  566. scenario = addon.getSetting('scenario')
  567. for i in soup('video'):
  568. if i['system-bitrate'] == scenario.replace('K','000'):
  569. path = i['src']
  570. return (base, path)
  571. else: continue
  572.  
  573.  
  574. def getInnings(name,event,content,session,cookieIp,cookieFp,scenario,live,start):
  575. innings_list = getStartTime(start)
  576. if len(innings_list) > 0:
  577. start_list = []
  578. name_list = []
  579. for i in innings_list:
  580. if i[0] == 'Start':
  581. inning_name = 'Start of broadcast'
  582. else:
  583. inning_name = 'Inning '+i[0]
  584. if scenario != "HTTP_CLOUD_WIRED_WEB":
  585. start = i[2]
  586. else:
  587. start = i[1]
  588. start_list.append(start)
  589. name_list.append(inning_name)
  590. if live:
  591. start_list.append('')
  592. name_list.append('Live')
  593. dialog = xbmcgui.Dialog()
  594. ret = dialog.select('Select an inning.', name_list)
  595. if ret >= 0:
  596. getGameURL(name,event,content,session,cookieIp,cookieFp,scenario,live,start_list[ret])
  597. else:
  598. addon_log('No start times???')
  599. getGameURL(name,event,content,session,cookieIp,cookieFp,scenario,live,None)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement