Example #1
0
def gem_asset(asset):
    asset_layout = GemV2.get_asset_by_id(asset)
    resp = GemV2.get_episode(asset_layout['playSession']['url'])
    url = None if not resp else resp['url'] if 'url' in resp else None
    if not url:
        log('Failed to get stream URL, attempting to authorize.')
        if authorize():
            resp = GemV2().get_episode(asset_layout['playSession']['url'])
            url = resp['url'] if 'url' in resp else None
    labels = GemV2.get_labels({'title': asset_layout['series']}, asset_layout)
    image = asset_layout['image']
    play(labels, image, url)
Example #2
0
def gem_episode():
    """Play an episode."""
    json_str = plugin.args['query'][0]
    episode = json.loads(json_str)

    # get the url, and failing that, attempt authorization, then retry
    resp = GemV2().get_episode(episode['url'])
    url = None if not resp else resp['url'] if 'url' in resp else None
    if not url:
        log('Failed to get stream URL, attempting to authorize.')
        if authorize():
            resp = GemV2().get_episode(episode['url'])
            url = resp['url'] if 'url' in resp else None

    labels = episode['labels']
    play(labels, None, url)
Example #3
0
def gem_add_film_assets(assets):
    for asset in assets:
        labels = GemV2.get_labels({'title': asset['series']}, asset)
        image = asset['image']
        item = xbmcgui.ListItem(labels['title'])
        item.setInfo(type="Video", infoLabels=labels)
        item.setArt({'thumb': image, 'poster': image})
        item.setProperty('IsPlayable', 'true')
        episode_info = {'url': asset['playSession']['url'], 'labels': labels}
        url = plugin.url_for(gem_episode, query=json.dumps(episode_info))
        xbmcplugin.addDirectoryItem(plugin.handle, url, item, False)
Example #4
0
def gem_category_menu(category_id):
    """Populate a menu with categorical content."""
    handle = plugin.handle
    xbmcplugin.setContent(handle, 'videos')
    category = GemV2.get_category(category_id)
    for show in category['items']:
        item = xbmcgui.ListItem(show['title'])
        item.setInfo(type="Video", infoLabels=CBC.get_labels(show))
        image = show['image'].replace('(Size)', '224')
        item.setArt({'thumb': image, 'poster': image})
        url = plugin.url_for(gem_show_menu, show['id'])
        xbmcplugin.addDirectoryItem(handle, url, item, True)
    xbmcplugin.addSortMethod(handle, xbmcplugin.SORT_METHOD_TITLE_IGNORE_THE)
    xbmcplugin.endOfDirectory(handle)
Example #5
0
def gem_show_menu(show_id):
    """Create a menu for a shelfs items."""
    xbmcplugin.setContent(plugin.handle, 'videos')
    show_layout = GemV2.get_show_layout_by_id(show_id)
    show = {
        k: v
        for (k, v) in show_layout.items() if k not in ['sponsors', 'seasons']
    }
    for season in show_layout['seasons']:

        # films seem to have been shoe-horned (with teeth) into the structure oddly -- compensate
        if season['title'] == 'Film':
            gem_add_film_assets(season['assets'])
        else:
            labels = GemV2.get_labels(season, season)
            item = xbmcgui.ListItem(season['title'])
            item.setInfo(type="Video", infoLabels=labels)
            image = season['image'].replace('(Size)', '224')
            item.setArt({'thumb': image, 'poster': image})
            show['season'] = season
            url = plugin.url_for(gem_show_season, query=json.dumps(show))
            xbmcplugin.addDirectoryItem(plugin.handle, url, item, True)

    xbmcplugin.endOfDirectory(plugin.handle)
Example #6
0
def layout_menu(layout):
    """Populate the menu with featured items."""
    handle = plugin.handle
    xbmcplugin.setContent(handle, 'videos')
    layout = GemV2.get_layout(layout)
    if 'categories' in layout:
        for category in layout['categories']:
            item = xbmcgui.ListItem(category['title'])
            url = plugin.url_for(gem_category_menu, category['id'])
            xbmcplugin.addDirectoryItem(handle, url, item, True)
    if 'shelves' in layout:
        for shelf in layout['shelves']:
            item = xbmcgui.ListItem(shelf['title'])
            shelf_items = json.dumps(shelf['items'])
            url = plugin.url_for(gem_shelf_menu, query=shelf_items)
            xbmcplugin.addDirectoryItem(handle, url, item, True)
    xbmcplugin.endOfDirectory(handle)
Example #7
0
def gem_show_season():
    """Create a menu for a show season."""
    xbmcplugin.setContent(plugin.handle, 'videos')
    json_str = plugin.args['query'][0]
    # remember show['season'] is season details but there is general show info in show as well
    show = json.loads(json_str)
    for episode in show['season']['assets']:
        item = xbmcgui.ListItem(episode['title'])
        image = episode['image'].replace('(Size)', '224')
        item.setArt({'thumb': image, 'poster': image})
        item.setProperty('IsPlayable', 'true')
        labels = GemV2.get_labels(show, episode)
        item.setInfo(type="Video", infoLabels=labels)
        episode_info = {'url': episode['playSession']['url'], 'labels': labels}
        url = plugin.url_for(gem_episode, query=json.dumps(episode_info))
        xbmcplugin.addDirectoryItem(plugin.handle, url, item, False)
    xbmcplugin.endOfDirectory(plugin.handle)
Example #8
0
def search():
    handle = plugin.handle
    term = xbmcgui.Dialog().input(SEARCH, type=xbmcgui.INPUT_ALPHANUM)
    results = GemV2.search_by_term(term)
    add_items(handle, results)
    xbmcplugin.endOfDirectory(handle)
Example #9
0
shows = Shows()
res = []

if options.authorize:
    if not cbc.authorize(options.username, options.password, progress):
        print('Error: Authorization failed')
        sys.exit(1)
    print('Authorization successful')
    sys.exit(0)

if options.chans:
    res = chans.get_live_channels()
elif options.progs:
    res = events.getLivePrograms()
elif options.layout:
    res = GemV2.get_layout(options.layout)
elif options.video:
    try:
        res = shows.getStream(args[0])
    except CBCAuthError as e:
        print('ERROR: login required' if e.payment else 'ERROR: Unauthorized')
        sys.exit(1)
    print(res)
    sys.exit(0)
elif options.shows:
    res = shows.getShows(None if len(args) == 0 else args[0],
                         progress_callback=progress)
else:
    print('\nPlease specify something to do\n')
    parser.print_help()
    sys.exit(1)