def get_all_live_tv_channels():
    """Explore each live_tv skeleton files to retrieve all sorted live tv channels

    Returns:
        list: Format: (coutry_order, country_id, country_label, country_infos, [channels]),
                      Channel format: (channel_order, channel_id, channel_label, channel_infos)
    """
    country_channels = []
    live_tv_dict = importlib.import_module(
        'resources.lib.skeletons.live_tv').menu
    for country_id, country_infos in live_tv_dict.items():
        channels = []
        channels_dict = importlib.import_module('resources.lib.skeletons.' +
                                                country_id).menu
        for channel_id, channel_infos in list(channels_dict.items()):
            # If this channel is disabled --> ignore this channel
            if not channel_infos.get('enabled', False):
                continue
            # If this channel is a folder (e.g. multi live) --> ignore this channel
            if 'resolver' not in channel_infos:
                continue
            channels.append((channel_infos['order'], channel_id,
                             get_item_label(channel_id,
                                            channel_infos), channel_infos))
        channels = sorted(channels, key=lambda x: x[2])
        country_channels.append((country_infos['order'], country_id,
                                 get_item_label(country_id,
                                                country_infos), country_infos,
                                 sorted(channels, key=lambda x: x[0])))
    return sorted(country_channels, key=lambda x: x[2])
def unmask_items(plugin, menu_id):
    """Callback function of 'Unmask items' setting buttons

    Args:
        plugin (codequick.script.Script)
        menu_id (str): Menu for which we cant to unmask items
    """

    menus_settings = get_menus_settings()
    if menu_id not in menus_settings:
        return

    menu = importlib.import_module('resources.lib.skeletons.' + menu_id).menu

    hidden_items = []
    hidden_items_labels = []
    for item_id, item in menus_settings[menu_id].items():
        if item.get('hidden', False):
            hidden_items.append(item_id)
            hidden_items_labels.append(get_item_label(item_id, menu[item_id]))

    if not hidden_items:
        return

    seleted_item = xbmcgui.Dialog().select(
        plugin.localize(30406),
        hidden_items_labels)
    if seleted_item == -1:
        return

    menus_settings[menu_id][hidden_items[seleted_item]].pop('hidden')
    save_menus_settings(menus_settings)
def unmask_items(plugin, menu_id):
    """Callback function of 'Unmask items' setting buttons

    Args:
        plugin (codequick.script.Script)
        menu_id (str): Menu for which we cant to unmask items
    """

    menus_settings = get_menus_settings()
    if menu_id not in menus_settings:
        return

    hidden_items = []
    hidden_items_labels = []
    for item_id, item in menus_settings[menu_id].items():
        if item.get('hidden', False):
            hidden_items.append(item_id)
            hidden_items_labels.append(get_item_label(item_id))

    if not hidden_items:
        return

    seleted_item = xbmcgui.Dialog().select(
        plugin.localize(LABELS['Select item to unmask']), hidden_items_labels)
    if seleted_item == -1:
        return

    menus_settings[menu_id][hidden_items[seleted_item]].pop('hidden')
    save_menus_settings(menus_settings)
def get_all_live_tv_channels():
    """Explore each live_tv skeleton files to retrieve all sorted live tv channels

    Returns:
        list: Format: (coutry_order, country_id, country_label, country_infos, [channels]),
                      Channel format: (channel_order, channel_id, channel_label, channel_infos, lang)
    """
    country_channels = []
    live_tv_dict = importlib.import_module(
        'resources.lib.skeletons.live_tv').menu
    for country_id, country_infos in live_tv_dict.items():
        channels = []
        channels_dict = importlib.import_module('resources.lib.skeletons.' +
                                                country_id).menu
        for channel_id, channel_infos in list(channels_dict.items()):
            # If this channel is disabled --> ignore this channel
            if not channel_infos.get('enabled', False):
                continue
            # If this channel is a folder (e.g. multi live) --> ignore this channel
            if 'resolver' not in channel_infos:
                continue
            # Check if this channel has multiple language
            if 'available_languages' in channel_infos:
                for lang in channel_infos['available_languages']:
                    label = '{} ({})'.format(
                        get_item_label(channel_id,
                                       channel_infos,
                                       append_selected_lang=False), lang)
                    channels.append((channel_infos['order'], channel_id, label,
                                     channel_infos, lang))
            else:
                channels.append(
                    (channel_infos['order'], channel_id,
                     get_item_label(channel_id,
                                    channel_infos), channel_infos, None))
        channels = sorted(channels, key=lambda x: x[0])
        country_channels.append(
            (country_infos['order'], country_id,
             get_item_label(country_id,
                            country_infos), country_infos, channels))
    return sorted(country_channels, key=lambda x: x[2])
示例#5
0
def generic_menu(plugin, item_id=None, **kwargs):
    """Build 'item_id' menu of the addon

    Args:
        plugin (codequick.script.Script)
        item_id (str): Menu to build (e.g. root)
    Returns:
        Iterator[codequick.listing.Listitem]: Kodi 'item_id' menu
    """

    if item_id is None:
        # Fix https://github.com/Catch-up-TV-and-More/plugin.video.catchuptvandmore/issues/304
        xbmc.executebuiltin("Action(Back,%s)" % xbmcgui.getCurrentWindowId())
        yield False

    else:
        menu_id = item_id

        # If 'menu_id' menu contains only one item, directly open this item
        plugin.redirect_single_item = True

        # Get ordered 'menu_id' menu
        # without disabled and hidden items
        menu = get_sorted_menu(plugin, menu_id)

        if not menu:
            # If the selected menu is empty just reload the current menu
            yield False

        for index, (item_order, item_id, item_infos) in enumerate(menu):

            item = Listitem()

            # Set item label
            item.label = get_item_label(item_id, item_infos)

            # Set item art
            if 'thumb' in item_infos:
                item.art["thumb"] = get_item_media_path(item_infos['thumb'])

            if 'fanart' in item_infos:
                item.art["fanart"] = get_item_media_path(
                    item_infos['fanart'])
示例#6
0
def unmask_items(plugin):
    """Callback function of 'Select items to unmask' setting button.

    Args:
        plugin (codequick.script.Script)
    """

    menus_settings = get_menus_settings()

    multiselect_map = []
    multiselect_items = []

    for menu_id, items in menus_settings.items():
        for item_id, item in items.items():
            if not item.get('hidden', False):
                continue

            current_lvl = menu_id
            last_item_id = item_id
            labels = []
            while current_lvl is not None:
                module = importlib.import_module('resources.lib.skeletons.' +
                                                 current_lvl)
                labels.insert(
                    0, get_item_label(last_item_id, module.menu[last_item_id]))
                last_item_id = current_lvl
                current_lvl = module.root
            multiselect_items.append(' - '.join(labels))
            multiselect_map.append((menu_id, item_id))

    seleted_items = xbmcgui.Dialog().multiselect(plugin.localize(30402),
                                                 multiselect_items)
    if seleted_items is None:
        return

    for seleted_item in seleted_items:
        (menu_id, item_id) = multiselect_map[seleted_item]
        menus_settings[menu_id][item_id].pop('hidden')
    save_menus_settings(menus_settings)
    def send_channels(self):
        """Return JSON-STREAMS formatted python datastructure to IPTV Manager"""
        channels_list = []

        # Grab all live TV channels
        country_channels = get_all_live_tv_channels()

        # Grab current user settings
        tv_integration_settings = get_tv_integration_settings()

        for (country_order, country_id, country_label, country_infos,
             channels) in country_channels:
            for (channel_order, channel_id, channel_label,
                 channel_infos) in channels:
                if not tv_integration_settings['enabled_channels'].get(
                        country_id, {}).get(channel_id, {}).get(
                            'enabled', False):
                    continue

                json_stream = {}
                json_stream['name'] = get_item_label(channel_id, channel_infos)
                resolver = channel_infos['resolver'].replace(':', '/')
                params = {'item_id': channel_id}
                query = urlencode(params)
                json_stream[
                    'stream'] = PLUGIN_KODI_PATH + resolver + '/?' + query
                if 'xmltv_id' in channel_infos:
                    json_stream['id'] = channel_infos['xmltv_id']
                if 'm3u_order' in channel_infos:
                    json_stream['preset'] = channel_infos['m3u_order']
                json_stream['logo'] = get_item_media_path(
                    channel_infos['thumb'])

                channels_list.append(json_stream)

        return dict(version=1, streams=channels_list)
示例#8
0
def add_item_to_favourites(plugin, is_playable=False, item_infos={}):
    """Callback function of the 'Add to add-on favourites' item context menu

    Args:
        plugin (codequick.script.Script)
        is_playable (bool): If 'item' is playable
        item_infos (dict)
    """

    # Need to use same keywords as
    # https://scriptmodulecodequick.readthedocs.io/en/latest/_modules/codequick/listing.html#Listitem.from_dict
    # in order to be able to directly use `Listitem.from_dict` later
    item_dict = {}

    # --> subtitles (TODO)
    # item_dict['subtitles'] = list(item.subtitles)

    # --> art
    item_dict['art'] = get_selected_item_art()

    # --> info
    item_dict['info'] = get_selected_item_info()

    # --> stream
    item_dict['stream'] = get_selected_item_stream()

    # --> context (TODO)
    item_dict['context'] = []

    # --> properties (TODO)
    item_dict['properties'] = {}

    # --> params
    item_dict['params'] = get_selected_item_params()

    # --> label
    item_dict['label'] = get_selected_item_label()

    if item_infos:
        # This item comes from tv_guide_menu
        # We need to remove guide TV related
        # elements

        item_id = item_dict['params']['item_id']
        item_dict['label'] = get_item_label(item_id, item_infos)

        item_dict['art']["thumb"] = ''
        if 'thumb' in item_infos:
            item_dict['art']["thumb"] = get_item_media_path(
                item_infos['thumb'])

        item_dict['art']["fanart"] = ''
        if 'fanart' in item_infos:
            item_dict['art']["fanart"] = get_item_media_path(
                item_infos['fanart'])

        item_dict['info']['plot'] = ''

    # Extract the callback
    item_path = xbmc.getInfoLabel('ListItem.Path')
    item_dict['callback'] = item_path.replace(
        'plugin://plugin.video.catchuptvandmore', '')

    s = mem_storage.MemStorage('fav')
    prefix = ''
    try:
        prefix = s['prefix']
    except KeyError:
        pass

    label_proposal = item_dict['label']
    if prefix != '':
        label_proposal = prefix + ' - ' + label_proposal

    # Ask the user to edit the label
    label = utils.keyboard(plugin.localize(30801), label_proposal)

    # If user aborded do not add this item to favourite
    if label == '':
        return False

    item_dict['label'] = label
    item_dict['params']['_title_'] = label
    item_dict['info']['title'] = label

    item_dict['params']['is_playable'] = is_playable
    item_dict['params']['is_folder'] = not is_playable

    # Compute fav hash
    item_hash = md5(str(item_dict).encode('utf-8')).hexdigest()

    # Add this item to favourites json file
    fav_dict = get_fav_dict_from_json()
    item_dict['params']['order'] = len(fav_dict)

    fav_dict[item_hash] = item_dict

    # Save json file with new fav_dict
    save_fav_dict_in_json(fav_dict)

    Script.notify(Script.localize(30033),
                  Script.localize(30805),
                  display_time=7000)
示例#9
0
文件: main.py 项目: akuala/repo.kuala
def generic_menu(plugin, item_id, **kwargs):
    """Build 'item_id' menu of the addon

    Args:
        plugin (codequick.script.Script)
        item_id (str): Menu to build (e.g. root)
    Returns:
        Iterator[codequick.listing.Listitem]: Kodi 'item_id' menu
    """

    menu_id = item_id

    # If 'menu_id' menu contains only one item, directly open this item
    plugin.redirect_single_item = True

    # Get ordered 'menu_id' menu
    # without disabled and hidden items
    menu = get_sorted_menu(plugin, menu_id)

    if not menu:
        # If the selected menu is empty just reload the current menu
        yield False

    for index, (item_order, item_id, item_infos) in enumerate(menu):

        item = Listitem()

        # Set item label
        item.label = get_item_label(item_id)

        # Set item art
        if 'thumb' in item_infos:
            item.art["thumb"] = get_item_media_path(item_infos['thumb'])

        if 'fanart' in item_infos:
            item.art["fanart"] = get_item_media_path(
                item_infos['fanart'])

        # Set item params
        # If this item requires a module to work, get
        # the module path to be loaded
        if 'module' in item_infos:
            item.params['item_module'] = item_infos['module']

        if 'xmltv_id' in item_infos:
            item.params['xmltv_id'] = item_infos['xmltv_id']

        item.params['item_id'] = item_id

        # Get cllback function of this item
        item_callback = eval(item_infos['callback'])
        item.set_callback(item_callback)

        # Add needed context menus to this item
        add_context_menus_to_item(item,
                                  item_id,
                                  index,
                                  menu_id,
                                  len(menu),
                                  is_playable=(item_infos['callback'] == 'live_bridge'),
                                  item_infos=item_infos)

        yield item
def generic_menu(plugin, item_id=None, **kwargs):
    """Build 'item_id' menu of the addon

    Args:
        plugin (codequick.script.Script)
        item_id (str): Menu to build (e.g. root)
    Returns:
        Iterator[codequick.listing.Listitem]: Kodi 'item_id' menu
    """

    if item_id is None:
        # Fix https://github.com/Catch-up-TV-and-More/plugin.video.catchuptvandmore/issues/304
        xbmc.executebuiltin("Action(Back,%s)" % xbmcgui.getCurrentWindowId())
        yield False

    else:
        menu_id = item_id

        # If 'menu_id' menu contains only one item, directly open this item
        plugin.redirect_single_item = True

        # Get ordered 'menu_id' menu
        # without disabled and hidden items
        menu = get_sorted_menu(plugin, menu_id)

        if not menu:
            # If the selected menu is empty just reload the current menu
            yield False

        for index, (item_order, item_id, item_infos) in enumerate(menu):

            item = Listitem()

            # Set item label
            item.label = get_item_label(item_id, item_infos)

            # Set item art
            if 'thumb' in item_infos:
                item.art["thumb"] = get_item_media_path(item_infos['thumb'])

            if 'fanart' in item_infos:
                item.art["fanart"] = get_item_media_path(
                    item_infos['fanart'])

            # Set item additional params
            if 'xmltv_id' in item_infos:
                item.params['xmltv_id'] = item_infos['xmltv_id']

            item.params['item_id'] = item_id

            # Set callback function for this item
            if 'route' in item_infos:
                item.set_callback((Route.ref(item_infos['route'])))
            elif 'resolver' in item_infos:
                item.set_callback((Resolver.ref(item_infos['resolver'])))
            else:
                # This case should not happen
                # Ignore this item to prevent any error for this menu
                continue

            # Add needed context menus to this item
            add_context_menus_to_item(item,
                                      item_id,
                                      index,
                                      menu_id,
                                      len(menu),
                                      is_playable='resolver' in item_infos,
                                      item_infos=item_infos)

            yield item