Exemplo n.º 1
0
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
Exemplo n.º 2
0
def _parse_rows(rows, default_art=None):
    items = []

    for row in rows:
        item = plugin.Item(
            label    = row['title'],
            info     = {'plot': row['description']},
            art      = _get_art(row.get('images', []), default_art),
        )

        if row['type'] in ('movie', 'episode'):
            videos = _get_videos(row.get('videos', []))

            item.info.update({
                'duration': int(videos['main']['duration']),
                'mediatype': row['type'],
            })

            item.video = {'height': videos['main']['height'], 'width': videos['main']['width'], 'codec': 'h264'}
            item.path  = plugin.url_for(play, video_id=videos['main']['id'])
            item.playable = True

            if 'trailer' in videos:
                item.info['trailer'] = plugin.url_for(play, video_id=videos['trailer']['id'])

            if not item.label:
                item.label = _(L_EPISODE_NUMBER, episode_number=row['number'])

        elif row['type'] == 'tv_series':
            item.path      = plugin.url_for(series, series_id=row['id'])
            item.cache_key = cache.key_for(series, series_id=row['id'])

        items.append(item)

    return items
def _process_media(row):
    if settings.getBool('child_friendly', False) and not row.get('is_child_friendly', False):
        #maybe just block playback and add label, so pagination still correct
        return None

    is_published   = row.get('is_published', True)
    is_collection  = row.get('is_collection', False)
    is_free        = row.get('is_free', False) 
    is_series      = row.get('is_numbered_series', False)
    duration       = row.get('duration', 0) if plugin.logged_in or is_free else PREVIEW_LENGTH

    context = []

    if plugin.logged_in and not is_collection:
        user_media   = row.get('user_media') or {}
        in_watchlist = user_media.get('is_bookmarked', False)

        if in_watchlist:
            context.append((_.REMOVE_WATCHLIST, "XBMC.RunPlugin({})".format(plugin.url_for(remove_watchlist, id=row['id'], title=row['title']))))
        else:
            context.append((_.ADD_WATCHLIST, "XBMC.RunPlugin({})".format(plugin.url_for(add_watchlist, id=row['id'], title=row['title']))))

    if is_collection:
        path = plugin.url_for(series, id=row['id'])
    else:
        path = plugin.url_for(play, id=row['id'])

    return plugin.Item(
        label = row.get('title'),
        info  = {'plot': row['description'], 'duration': duration, 'year': row.get('year_produced')},
        art   = {'thumb': _image(row, 'image_medium')},
        path  = path,
        context = context,
        playable = not is_collection,
    )
Exemplo n.º 4
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
Exemplo n.º 5
0
def play_channel(id, **kwargs):
    url = api.play_channel(id)

    return plugin.Item(
        path        = url,
        headers     = HEADERS,
        inputstream = inputstream.HLS(),
    )
def proxy_merge(type=None, **kwargs):
    from .service import run_merge

    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)

    if type == 'epg':
        run_merge([Source.EPG])
        return plugin.Item(path=epg_path)

    elif type == 'playlist':
        run_merge([Source.PLAYLIST])
        return plugin.Item(path=playlist_path)

    else:
        run_merge([Source.EPG, Source.PLAYLIST])
        return plugin.Item(path=output_dir)
Exemplo n.º 7
0
def _parse_panel(row):
    art = {}

    items = _parse_contents(row.get('contents', []))
    if items:
        art = items[0].art

    return plugin.Item(
        label=row['title'],
        path=plugin.url_for(panel, id=row['id']),
        art=art,
    )
Exemplo n.º 8
0
def _parse_show(asset):
    return plugin.Item(
        label=asset['title'],
        art={
            'thumb': _get_image(asset, 'show', 'thumb'),
            'fanart': _get_image(asset, 'show', 'fanart'),
        },
        info={
            'plot': asset.get('description-short'),
        },
        path=plugin.url_for(show, id=asset['id'], title=asset['title']),
    )
Exemplo n.º 9
0
def play(id, **kwargs):
    url, license = api.play_media(id)

    return plugin.Item(
        path        = url,
        headers     = HEADERS,
        inputstream = inputstream.Widevine(
            license_key  = license,
            challenge    = '',
            content_type = '',
            response     = 'JBlicense',
        ),
    )
Exemplo n.º 10
0
def _parse_show(asset):
    return plugin.Item(
        label=asset['title'],
        art={
            'thumb': _get_image(asset, 'carousel-item'),
            'fanart': _get_image(asset, 'hero-default'),
        },
        info={
            'plot': asset.get('description-short'),
            'mediatype': 'tvshow',
        },
        path=plugin.url_for(show, id=asset['id'], title=asset['title']),
    )
Exemplo n.º 11
0
def _landing(name, sport=None):
    items = []

    for row in api.landing(name, sport=sport, profile=userdata.get('profile')):
        if row['panelType'] == 'hero-carousel' and row.get('contents') and settings.getBool('show_hero_contents', True):
            items.extend(_parse_contents(row['contents']))

        elif row['panelType'] != 'hero-carousel' and 'id' in row:
            items.append(plugin.Item(
                label = row['title'],
                path  = plugin.url_for(panel, id=row['id'], sport=sport),
            ))

    return items
Exemplo n.º 12
0
def _process_content(rows):
    items = []
    subscriptions = userdata.get('subscriptions', [])

    for row in rows:
        if row['suspended']:
            continue

        label = row['title']

        if 'subCode' in row and subscriptions and row['subCode'] not in subscriptions:
            label = _(_.LOCKED, label=label)

            if settings.getBool('hide_unplayable', False):
                continue

        if row['type'] == 'movie':
            items.append(plugin.Item(
                label = label,
                info = {
                    'plot': row.get('synopsis'),
                    'duration': int(row.get('duration', '0 mins').strip(' mins')) * 60,
                    'mediatype': 'movie',
                },
                art  = {'thumb': IMAGE_URL.format(row['images'].get('MP',''))},
                path = plugin.url_for(play, id=row['mediaId']),
                playable = True,
            ))

        elif row['type'] == 'season':
            items.append(plugin.Item(
                label = label,
                art   = {'thumb': IMAGE_URL.format(row['images'].get('MP',''))},
                path  = plugin.url_for(series, id=row['id']),
            ))

    return items
Exemplo n.º 13
0
def play(slug, **kwargs):
    channel = get_channels()[slug]

    item = plugin.Item(
        path=channel['master_url'],
        headers=channel['headers'],
        info={'plot': channel.get('description')},
        video=channel.get('video', {}),
        audio=channel.get('audio', {}),
        art={'thumb': channel.get('logo')},
    )

    if channel.get('hls', False) and settings.getBool('use_ia_hls', False):
        item.inputstream = inputstream.HLS()

    return item
Exemplo n.º 14
0
def play(slug, **kwargs):
    region = get_region()
    channel = get_channels(region)[slug]

    item = plugin.Item(
        path=channel['mjh_master'],
        headers=channel['headers'],
        info={'plot': channel.get('description')},
        video=channel.get('video', {}),
        audio=channel.get('audio', {}),
        art={'thumb': channel.get('logo')},
    )

    if channel.get('hls', False):
        item.inputstream = inputstream.HLS()

    return item
Exemplo n.º 15
0
def _sport(sport):
    items = []

    #https://vccapi.kayosports.com.au/content/types/landing/names/sport?sport=tennis&evaluate=3&profile=d3bf57f6ce9bbadf05488e7fd82972e899e857be

    for row in api.sport_menu(sport):
        item = plugin.Item(
            label=row['name'],
            path=plugin.url_for(sport_list,
                                sport=row['sport'],
                                name=row['name']),
            art={
                'thumb':
                'https://resources.kayosports.com.au/production/sport-logos/1x1/{}.png?imwidth=320'
                .format(row['sport'])
            },
        )
        items.append(item)

    return items
Exemplo n.º 16
0
def epgs():
    folder = plugin.Folder(title=_.EPGS)
    sources = list(Source.select().where(Source.item_type == Source.EPG))

    for source in sources:
        item = plugin.Item(
            label = source.label(),
            path = plugin.url_for(edit_source, id=source.id),
            is_folder = False,
            playable = False,
        )

        item.context.append((_.DELETE_SOURCE, 'XBMC.RunPlugin({})'.format(plugin.url_for(delete_source, id=source.id))))

        folder.add_items([item])

    folder.add_item(
        label = _(_.ADD_EPG, _bold=len(sources) == 0), 
        path  = plugin.url_for(edit_source, type=Source.EPG),
    )

    return folder
Exemplo n.º 17
0
def _process_sources(sources):
    items = []

    for source in sources:
        label = source.label()

        if not source.enabled:
            label = _(_.DISABLED, label=label, _color='red')

        item = plugin.Item(
            label=label,
            path=plugin.url_for(edit_source, id=source.id),
        )

        if source.order > 0:
            item.context.append((_.MOVE_UP, 'XBMC.RunPlugin({})'.format(
                plugin.url_for(shift_source, id=source.id, shift=-1))))

        if source.order < len(sources) - 1:
            item.context.append((_.MOVE_DOWN, 'XBMC.RunPlugin({})'.format(
                plugin.url_for(shift_source, id=source.id, shift=1))))

        item.context.append((_.EDIT_SOURCE, 'XBMC.RunPlugin({})'.format(
            plugin.url_for(edit_source, id=source.id))))

        if source.enabled:
            item.context.append((_.DISABLE_SOURCE, 'XBMC.RunPlugin({})'.format(
                plugin.url_for(toggle_source, id=source.id))))
        else:
            item.context.append((_.ENABLE_SOURCE, 'XBMC.RunPlugin({})'.format(
                plugin.url_for(toggle_source, id=source.id))))

        item.context.append((_.DELETE_SOURCE, 'XBMC.RunPlugin({})'.format(
            plugin.url_for(delete_source, id=source.id))))

        items.append(item)

    return items
Exemplo n.º 18
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
Exemplo n.º 19
0
def _landing(name, sport=None):
    items = []

    for row in api.landing(name, sport=sport, profile=userdata.get('profile')):
        if row['panelType'] == 'hero-carousel' and row.get(
                'contents') and settings.getBool('show_hero_contents', True):
            items.extend(_parse_contents(row['contents']))

        elif row['panelType'] != 'hero-carousel' and row.get('contents'):
            items.append(
                plugin.Item(
                    label=row['title'],
                    path=plugin.url_for(panel, id=row['id'], sport=sport),
                    art={
                        'thumb':
                        _get_image(row['contents'][0]['data']['asset'],
                                   'panel', 'thumb'),
                        'fanart':
                        _get_image(row['contents'][0]['data']['asset'],
                                   'panel', 'fanart'),
                    },
                ))

    return items
Exemplo n.º 20
0
def _parse_video(row):
    asset   = row['asset']
    display = row['contentDisplay']
    alerts  = userdata.get('alerts', [])

    now      = arrow.now()
    start    = arrow.get(asset['transmissionTime'])
    precheck = start

    if 'preCheckTime' in asset:
        precheck = arrow.get(asset['preCheckTime'])
        if precheck > start:
            precheck = start

    start_from = (start - precheck).seconds

    title = display['title']
    if 'heroHeader' in display:
        title += ' [' + display['heroHeader'].replace('${DATE_HUMANISED}', _makeHumanised(now, start).upper()).replace('${TIME}', _makeTime(start)) + ']'

    item = plugin.Item(
        label = title,
        art  = {
            'thumb' : _get_image(asset, 'video', 'thumb'),
            'fanart': _get_image(asset, 'video', 'fanart'),
        },
        info = {
            'plot': display.get('description'),
            'plotoutline': display.get('description'),
            'mediatype': 'video',
        },
        playable = True,
        is_folder = False,
    )

    is_live = False

    if now < start:
        is_live = True
        toggle_alert = plugin.url_for(alert, asset=asset['id'], title=asset['title'])

        if asset['id'] not in userdata.get('alerts', []):
            item.info['playcount'] = 0
            item.context.append((_.SET_REMINDER, "XBMC.RunPlugin({})".format(toggle_alert)))
        else:
            item.info['playcount'] = 1
            item.context.append((_.REMOVE_REMINDER, "XBMC.RunPlugin({})".format(toggle_alert)))

    elif asset['isLive'] and asset.get('isStreaming', False):
        is_live = True

        item.context.append((_.FROM_LIVE, "XBMC.PlayMedia({})".format(
            plugin.url_for(play, id=asset['id'], play_type=FROM_LIVE, _is_live=is_live)
        )))

        item.context.append((_.FROM_START, "XBMC.PlayMedia({})".format(
            plugin.url_for(play, id=asset['id'], start_from=start_from, play_type=FROM_START, _is_live=is_live)
        )))

    item.path = plugin.url_for(play, id=asset['id'], start_from=start_from, play_type=settings.getEnum('live_play_type', LIVE_PLAY_TYPES, default=FROM_CHOOSE), _is_live=is_live)

    return item
Exemplo n.º 21
0
def _parse_video(asset):
    alerts = userdata.get('alerts', [])

    now = arrow.now()
    start = arrow.get(asset['transmissionTime'])
    precheck = start

    if 'preCheckTime' in asset:
        precheck = arrow.get(asset['preCheckTime'])
        if precheck > start:
            precheck = start

    start_from = (start - precheck).seconds

    item = plugin.Item(
        label=asset['title'],
        art={
            'thumb': _get_image(asset, 'carousel-item'),
            'fanart': _get_image(asset, 'hero-default'),
        },
        info={
            'plot': asset.get('description'),
            'plotoutline': asset.get('description-short'),
            'mediatype': 'video',
        },
        playable=True,
        is_folder=False,
    )

    is_live = False

    if now < start:
        is_live = True
        item.label = _(_.STARTING_SOON,
                       title=asset['title'],
                       humanize=start.humanize())
        toggle_alert = plugin.url_for(alert,
                                      asset=asset['id'],
                                      title=asset['title'],
                                      image=item.art['thumb'])

        if asset['id'] not in userdata.get('alerts', []):
            item.info['playcount'] = 0
            item.context.append(
                (_.SET_REMINDER, "XBMC.RunPlugin({})".format(toggle_alert)))
        else:
            item.info['playcount'] = 1
            item.context.append(
                (_.REMOVE_REMINDER, "XBMC.RunPlugin({})".format(toggle_alert)))

    elif asset['isLive'] and asset.get('isStreaming', False):
        is_live = True
        item.label = _(_.LIVE, title=asset['title'])

        item.context.append((_.FROM_LIVE, "XBMC.PlayMedia({})".format(
            plugin.url_for(play, id=asset['id'], is_live=is_live,
                           start_from=0))))

        item.context.append((_.FROM_START, "XBMC.PlayMedia({})".format(
            plugin.url_for(play,
                           id=asset['id'],
                           is_live=is_live,
                           start_from=start_from))))

    index = settings.getInt('live_play_type', 0)
    if is_live and LIVE_PLAY_TYPE[index] == FROM_LIVE:
        start_from = 0

    item.path = plugin.url_for(play,
                               id=asset['id'],
                               is_live=is_live,
                               start_from=start_from)

    return item