def play(id, start_from=0): asset = api.stream(id) start = arrow.get(asset.get('preCheckTime', asset['transmissionTime'])) if start > arrow.now(): return gui.ok(_(_.GAME_NOT_STARTED, start=start.humanize())) stream = _get_stream(asset) item = plugin.Item( path=stream['manifest']['uri'], art=False, headers=HEADERS, ) if stream['mediaFormat'] == 'dash': item.inputstream = inputstream.MPD() elif stream['mediaFormat'] == 'hls-ts': item.inputstream = inputstream.HLS() if start_from: item.properties['ResumeTime'] = start_from item.properties['TotalTime'] = start_from return item
def play(id, start_from=0, play_type=FROM_LIVE, **kwargs): asset = api.stream(id) start_from = int(start_from) play_type = int(play_type) is_live = kwargs.get(ROUTE_LIVE_TAG) == ROUTE_LIVE_SUFFIX now = arrow.now() start = arrow.get(asset.get('preCheckTime', asset['transmissionTime'])) if start > now: raise PluginError( _(_.GAME_NOT_STARTED, start=_makeHumanised(now, start).upper() + ' ' + _makeTime(start))) streams = [asset['recommendedStream']] streams.extend(asset['alternativeStreams']) streams = [s for s in streams if s['mediaFormat'] in SUPPORTED_FORMATS] if not streams: raise PluginError(_.NO_STREAM) provider = PREFER_PROVIDER or api.cdn_selection( 'live' if is_live else 'vod') streams = sorted( streams, key=lambda k: (k['provider'] == provider, k['mediaFormat'] == PREFER_FORMAT), reverse=True) stream = streams[0] log.debug('Stream CDN: {provider} | Stream Format: {mediaFormat}'.format( **stream)) item = plugin.Item( path=stream['manifest']['uri'], art=False, headers=HEADERS, ) if is_live and ( play_type == FROM_LIVE or (play_type == FROM_CHOOSE and gui.yes_no( _.PLAY_FROM, yeslabel=_.FROM_LIVE, nolabel=_.FROM_START))): start_from = 0 if stream['mediaFormat'] == FORMAT_DASH: item.inputstream = inputstream.MPD() elif stream['mediaFormat'] == FORMAT_HLS_TS: hls = inputstream.HLS() if is_live and start_from == 0 and not hls.check(): raise PluginError(_.HLS_REQUIRED) else: item.inputstream = hls if start_from: item.properties['ResumeTime'] = start_from item.properties['TotalTime'] = start_from return item
def play(id, start_from=0, play_type=FROM_LIVE, **kwargs): asset = api.stream(id) start_from = int(start_from) play_type = int(play_type) start = arrow.get(asset.get('preCheckTime', asset['transmissionTime'])) if start > arrow.now(): raise PluginError(_(_.GAME_NOT_STARTED, start=start.humanize())) stream = _get_stream(asset) item = plugin.Item( path=stream['manifest']['uri'], art=False, headers=HEADERS, ) if asset['isLive'] and play_type == FROM_LIVE or ( play_type == FROM_CHOOSE and gui.yes_no( _.PLAY_FROM, yeslabel=_.FROM_LIVE, nolabel=_.FROM_START)): start_from = 0 hls = inputstream.HLS() if stream['mediaFormat'] == 'dash': item.inputstream = inputstream.MPD() elif stream['mediaFormat'] == 'hls-ts': #If live stream FROM_LIVE and no HLS if asset['isLive'] and not start_from and not hls.check(): raise PluginError(_.HLS_REQUIRED) else: item.inputstream = hls if start_from: item.properties['ResumeTime'] = start_from item.properties['TotalTime'] = start_from return item