Exemple #1
0
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 categories(id=None, **kwargs):
    folder = plugin.Folder(title=_.CATEGORIES)

    rows = api.categories()
    if id:
        row = _search_category(rows, id)
        if not row:
            raise PluginError(_(_.CATEGORY_NOT_FOUND, category_id=id))

        folder.title = row['label']
        rows = row.get('subcategories', [])

    for row in rows:
        subcategories = row.get('subcategories', [])

        if subcategories:
            path = plugin.url_for(categories, id=row['id'])
        else:
            path = plugin.url_for(media, title=row['label'], filterby='category', term=row['name'])

        folder.add_item(
            label = row['label'],
            art   = {'thumb': _image(row, 'image_url')},
            path  = path,
        )

    return folder
def merge(**kwargs):
    if xbmc.getInfoLabel('Skin.String({})'.format(ADDON_ID)) == FORCE_RUN_FLAG:
        raise PluginError(_.MERGE_IN_PROGRESS)

    xbmc.executebuiltin('Skin.SetString({},{})'.format(ADDON_ID,
                                                       FORCE_RUN_FLAG))
    gui.notification(_.MERGE_STARTED)
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
def setup(**kwargs):
    try:
        xbmc.executebuiltin('InstallAddon({})'.format(IPTV_SIMPLE_ID), True)
        xbmc.executeJSONRPC(
            '{{"jsonrpc":"2.0","id":1,"method":"Addons.SetAddonEnabled","params":{{"addonid":"{}","enabled":true}}}}'
            .format(IPTV_SIMPLE_ID))
        addon = xbmcaddon.Addon(IPTV_SIMPLE_ID)
    except:
        raise PluginError(_.NO_IPTV_SIMPLE)

    xbmc.executeJSONRPC(
        '{{"jsonrpc":"2.0","id":1,"method":"Addons.SetAddonEnabled","params":{{"addonid":"{}","enabled":false}}}}'
        .format(IPTV_SIMPLE_ID))

    output_dir = xbmc.translatePath(
        settings.get('output_dir', '').strip() or ADDON_PROFILE)
    playlist_path = os.path.join(output_dir, PLAYLIST_FILE_NAME)
    epg_path = os.path.join(output_dir, EPG_FILE_NAME)

    addon.setSetting('m3uPathType', '0')
    addon.setSetting('m3uPath', playlist_path)

    addon.setSetting('epgPathType', '0')
    addon.setSetting('epgPath', epg_path)

    settings.setBool('restart_pvr', True)

    xbmc.executeJSONRPC(
        '{{"jsonrpc":"2.0","id":1,"method":"Addons.SetAddonEnabled","params":{{"addonid":"{}","enabled":true}}}}'
        .format(IPTV_SIMPLE_ID))

    xbmc.executeJSONRPC(
        '{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"epg.futuredaystodisplay", "value":7}, "id":1}'
    )
    xbmc.executeJSONRPC(
        '{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"pvrmanager.backendchannelorder", "value":true}, "id":1}'
    )
    xbmc.executeJSONRPC(
        '{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"pvrmanager.usebackendchannelnumbers", "value":true}, "id":1}'
    )
    xbmc.executeJSONRPC(
        '{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"pvrmanager.syncchannelgroups", "value":true}, "id":1}'
    )
    xbmc.executeJSONRPC(
        '{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"epg.ignoredbforclient", "value":true}, "id":1}'
    )
    #xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"pvrmanager.preselectplayingchannel", "value":true}, "id":1}')

    gui.ok(_.SETUP_COMPLETE)
def _get_stream(asset):
    streams = [asset['recommendedStream']]
    streams.extend(asset['alternativeStreams'])

    playable = ['hls-ts', 'dash']
    streams = [s for s in streams if s['mediaFormat'] in playable]
    streams = sorted(streams,
                     key=lambda k:
                     (k['mediaFormat'] == 'hls-ts', k['provider'] == 'AKAMAI'),
                     reverse=True)

    if not streams:
        raise PluginError(_.NO_STREAM)

    return streams[0]