Пример #1
0
def service():
    alerts = userdata.get('alerts', [])
    if not alerts:
        return

    now     = arrow.now()
    notify  = []
    _alerts = []

    for id in alerts:
        asset = api.event(id)
        start = arrow.get(asset.get('preCheckTime', asset['transmissionTime']))

        #If we are streaming and started less than 10 minutes ago
        if asset.get('isStreaming', False) and (now - start).total_seconds() <= 60*10:
            notify.append(asset)
        elif start > now:
            _alerts.append(id)

    userdata.set('alerts', _alerts)

    for asset in notify:
        if not gui.yes_no(_(_.EVENT_STARTED, event=asset['title']), yeslabel=_.WATCH, nolabel=_.CLOSE):
            continue

        with signals.throwable():
            start_from = 1
            start      = arrow.get(asset['transmissionTime'])

            if start < now and 'preCheckTime' in asset:
                precheck = arrow.get(asset['preCheckTime'])
                if precheck < start:
                    start_from = (start - precheck).seconds

            play(id=asset['id'], start_from=start_from, play_type=settings.getEnum('live_play_type', LIVE_PLAY_TYPES, default=FROM_CHOOSE))
Пример #2
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 delete_source(id, **kwargs):
    source = Source.get_by_id(id)

    if gui.yes_no(_.CONFIRM_DELETE_SOURCE):
        source.delete_instance()
        Source.update(order=Source.order -
                      1).where(Source.order > source.order).execute()
        gui.refresh()
Пример #4
0
def service():
    alerts = userdata.get('alerts', [])
    if not alerts:
        return

    now = arrow.now()

    _alerts = []
    for id in alerts:
        asset = api.event(id)
        start = arrow.get(asset.get('preCheckTime', asset['transmissionTime']))

        if asset.get('isStreaming', False):
            if gui.yes_no(_(_.EVENT_STARTED, event=asset['title']),
                          yeslabel=_.WATCH,
                          nolabel=_.CLOSE):
                play(id).play()
        elif start > now or (now - start).seconds < SERVICE_TIME:
            _alerts.append(id)

    userdata.set('alerts', _alerts)
Пример #5
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)

    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
Пример #6
0
def logout(**kwargs):
    if not gui.yes_no(_.LOGOUT_YES_NO):
        return

    api.logout()
    gui.refresh()
Пример #7
0
def logout():
    if not gui.yes_no(_(L_LOGOUT_YES_NO)):
        return

    api.logout()
    gui.refresh()
Пример #8
0
def delete_source(id):
    source = Source.get_by_id(id)
    if gui.yes_no(_.CONFIRM_DELETE_SOURCE) and source.delete_instance():
        gui.refresh()
Пример #9
0
def dns4me_logout(**kwargs):
    if not gui.yes_no('Are you sure logout?'):
        return

    userdata.delete('dns4me_key')
    gui.refresh()