def channels(plugin, **kwargs):
    """
    List all france.tv channels
    """
    # (item_id, label, thumb, fanart)
    channels = [('birminghamlocal', 'Birmingham Local TV',
                 'birminghamlocal.png', 'birminghamlocal_fanart.jpg'),
                ('bristollocal', 'Bristol Local TV', 'bristollocal.png',
                 'bristollocal_fanart.jpg'),
                ('cardifflocal', 'Cardiff Local TV', 'cardifflocal.png',
                 'cardifflocal_fanart.jpg'),
                ('leedslocal', 'Leeds Local TV', 'leedslocal.png',
                 'leedslocal_fanart.jpg'),
                ('liverpoollocal', 'Liverpool Local TV', 'liverpoollocal.png',
                 'liverpoollocal_fanart.jpg'),
                ('northwaleslocal', 'North Whales Local TV',
                 'northwaleslocal.png', 'northwaleslocal_fanart.jpg'),
                ('teessidelocal', 'Teesside Local TV', 'teessidelocal.png',
                 'teessidelocal_fanart.jpg'),
                ('twlocal', 'Tyne & Wear Local TV', 'twlocal.png',
                 'twlocal_fanart.jpg')]

    for channel_infos in channels:
        item = Listitem()
        item.label = channel_infos[1]
        item.art["thumb"] = get_item_media_path('channels/uk/' +
                                                channel_infos[2])
        item.art["fanart"] = get_item_media_path('channels/uk/' +
                                                 channel_infos[3])
        item.set_callback(list_categories, channel_infos[0])
        item_post_treatment(item)
        yield item
def mycanal_root(plugin, **kwargs):

    # (item_id, label, thumb, fanart)
    channels = [
        ('canalplus', 'Canal +', 'canalplus.png', 'canalplus_fanart.jpg'),
        ('c8', 'C8', 'c8.png', 'c8_fanart.jpg'),
        ('cstar', 'CStar', 'cstar.png', 'cstar_fanart.jpg'),
        ('seasons', 'Seasons', 'seasons.png', 'seasons_fanart.jpg'),
        ('comedie', 'Comédie +', 'comedie.png', 'comedie_fanart.jpg'),
        ('les-chaines-planete', 'Les chaînes planètes +', 'leschainesplanete.png', 'leschainesplanete_fanart.jpg'),
        ('golfplus', 'Golf +', 'golfplus.png', 'golfplus_fanart.jpg'),
        ('cineplus', 'Ciné +', 'cineplus.png', 'cineplus_fanart.jpg'),
        ('infosportplus', 'INFOSPORT+', 'infosportplus.png', 'infosportplus_fanart.jpg'),
        ('polar-plus', 'Polar+', 'polarplus.png', 'polarplus_fanart.jpg'),
        ('cliquetv', 'Clique TV', 'cliquetv.png', 'cliquetv_fanart.jpg'),
        ('piwiplus', 'Piwi +', 'piwiplus.png', 'piwiplus_fanart.jpg'),
        ('teletoonplus', 'TéléToon +', 'teletoonplus.png', 'teletoonplus_fanart.jpg'),
    ]

    for channel_infos in channels:
        item = Listitem()
        item.label = channel_infos[1]
        item.art["thumb"] = get_item_media_path('channels/fr/' + channel_infos[2])
        item.art["fanart"] = get_item_media_path('channels/fr/' + channel_infos[3])
        item.set_callback(list_categories, channel_infos[0])
        item_post_treatment(item)
        yield item
def channels(plugin, **kwargs):
    """
    List all france.tv channels
    """
    # (item_id, label, thumb, fanart)
    channels = [
        ('channels/france-2', 'France 2', 'france2.png', 'france2_fanart.jpg'),
        ('channels/france-3', 'France 3', 'france3.png', 'france3_fanart.jpg'),
        ('channels/france-4', 'France 4', 'france4.png', 'france4_fanart.jpg'),
        ('channels/france-5', 'France 5', 'france5.png', 'france5_fanart.jpg'),
        ('channels/france-o', 'France Ô', 'franceo.png', 'franceo_fanart.jpg'),
        ('regions/outre-mer', 'Outre-mer la 1ère', 'la1ere.png',
         'la1ere_fanart.jpg'),
        ('channels/franceinfo', 'franceinfo:', 'franceinfo.png',
         'franceinfo_fanart.jpg'),
        ('channels/slash', 'France tv Slash', 'slash.png', 'slash_fanart.jpg'),
        ('categories/enfants', 'Okoo', 'okoo.png', 'okoo_fanart.jpg'),
        ('channels/spectacles-et-culture', 'Culturebox', 'culturebox.png',
         'culturebox_fanart.jpg')
    ]

    for channel_infos in channels:
        item = Listitem()
        item.label = channel_infos[1]
        item.art["thumb"] = get_item_media_path('channels/fr/' +
                                                channel_infos[2])
        item.art["fanart"] = get_item_media_path('channels/fr/' +
                                                 channel_infos[3])
        item.set_callback(channel_homepage, channel_infos[0])
        item_post_treatment(item)
        yield item
def sixplay_root(plugin, **kwargs):
    # (item_id, label, thumb, fanart)
    channels = [
        ('m6', 'M6', 'm6.png', 'm6_fanart.jpg'),
        ('w9', 'W9', 'w9.png', 'w9_fanart.jpg'),
        ('6ter', '6ter', '6ter.png', '6ter_fanart.jpg'),
        ('gulli', 'Gulli', 'gulli.png', 'gulli_fanart.jpg'),
        ('fun_radio', 'Fun Radio', 'funradio.png', 'funradio_fanart.jpg'),
        ('rtl2', 'RTL 2', 'rtl2.png', 'rtl2_fanart.jpg'),
        ('courses', 'Cage Warriors', 'cagewarriors.png', 'cagewarriors_fanart.jpg')
    ]

    for channel_infos in channels:
        item = Listitem()
        item.label = channel_infos[1]
        item.art["thumb"] = get_item_media_path('channels/fr/' + channel_infos[2])
        item.art["fanart"] = get_item_media_path('channels/fr/' + channel_infos[3])
        item.set_callback(list_categories, channel_infos[0])
        item_post_treatment(item)
        yield item

    # all programs
    item = Listitem()
    item.label = plugin.localize(30717)
    item.art["thumb"] = get_item_media_path('channels/fr/m6.png')
    item.art["fanart"] = get_item_media_path('channels/fr/m6_fanart.jpg')
    item.set_callback(list_all_programs, 'm6')
    item_post_treatment(item)
    yield item
示例#5
0
def tva_root(plugin, **kwargs):

    # (item_id, label, thumb, fanart)
    channels = [
        ('tva', 'TVA', 'tva.png', 'tva_fanart.jpg'),
        ('addiktv', 'addikTV', 'addiktv.png', 'addiktv_fanart.jpg'),
        ('casa', 'Casa', 'casa.png', 'casa_fanart.jpg'),
        ('evasion', 'Evasion', 'evasion.png', 'evasion_fanart.jpg'),
        ('moi-et-cie', 'MOI ET CIE', 'moietcie.png', 'moietcie_fanart.jpg'),
        ('prise2', 'PRISE2', 'prise2.png', 'prise2_fanart.jpg'),
        ('yoopa', 'Yoopa', 'yoopa.png', 'yoopa_fanart.jpg'),
        ('zeste', 'Zeste', 'zeste.png', 'zeste_fanart.jpg'),
        ('tva-sports', 'TVA Sports', 'tvasports.png', 'tvasports_fanart.jpg'),
        ('lcn', 'LCN', 'lcn.png', 'lcn_fanart.jpg')
    ]

    for channel_infos in channels:
        item = Listitem()
        item.label = channel_infos[1]
        item.art["thumb"] = get_item_media_path('channels/ca/' +
                                                channel_infos[2])
        item.art["fanart"] = get_item_media_path('channels/ca/' +
                                                 channel_infos[3])
        item.set_callback(list_categories, channel_infos[0])
        item_post_treatment(item)
        yield item
def list_all_programs(plugin, item_id, **kwargs):
    letters = ['@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
               'u', 'v', 'w', 'y', 'z']

    for letter in letters:
        item = Listitem()
        item.label = plugin.localize(30717) + ' : ' + letter
        item.art["thumb"] = get_item_media_path('channels/fr/m6.png')
        item.art["fanart"] = get_item_media_path('channels/fr/m6_fanart.jpg')
        item.set_callback(list_all_programs_by_letter, item_id, letter)
        item_post_treatment(item)
        yield item
def nrjplay_root(plugin, **kwargs):

    # (item_id, label, thumb, fanart)
    channels = [('nrj12', 'NRJ 12', 'nrj12.png', 'nrj12_fanart.jpg'),
                ('cherie25', 'Chérie 25', 'cherie25.png',
                 'cherie25_fanart.jpg')]

    for channel_infos in channels:
        item = Listitem()
        item.label = channel_infos[1]
        item.art["thumb"] = get_item_media_path('channels/fr/' +
                                                channel_infos[2])
        item.art["fanart"] = get_item_media_path('channels/fr/' +
                                                 channel_infos[3])
        item.set_callback(list_categories, channel_infos[0])
        item_post_treatment(item)
        yield item
示例#8
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'])
示例#9
0
def discoveryplus_root(plugin, **kwargs):

    # (item_id, label, thumb, fanart)
    channels = [
        ('quest', 'Quest', 'questtv.png', 'questtv_fanart.jpg'),
        ('really', 'Really', 'really.png', 'really_fanart.jpg'),
        ('quest-red', 'Quest Red', 'questred.png', 'questred_fanart.jpg'),
        ('food-network', 'Food Network', 'foodnetwork.png', 'foodnetwork_fanart.jpg'),
        ('dmax', 'DMAX', 'dmax.png', 'dmax_fanart.jpg'),
        ('home', 'HGTV', 'hgtv.png', 'hgtv_fanart.jpg')
    ]

    for channel_infos in channels:
        item = Listitem()
        item.label = channel_infos[1]
        item.art["thumb"] = get_item_media_path('channels/uk/' + channel_infos[2])
        item.art["fanart"] = get_item_media_path('channels/uk/' + channel_infos[3])
        item.set_callback(list_categories, channel_infos[0])
        item_post_treatment(item)
        yield item
示例#10
0
def rtlplay_root(plugin, **kwargs):

    # (item_id, label, thumb, fanart)
    channels = [
        ('rtl_tvi', 'RTL TVI', 'rtltvi.png', 'rtltvi_fanart.jpg'),
        ('club_rtl', 'CLUB RTL', 'clubrtl.png', 'clubrtl_fanart.jpg'),
        ('plug_rtl', 'PLUG RTL', 'plugrtl.png', 'plugrtl_fanart.jpg'),
        ('rtl_info', 'RTL INFO', 'rtlinfo.png', 'rtlinfo_fanart.jpg'),
        ('rtl_sport', 'RTL Sport', 'rtlsport.png', 'rtlsport_fanart.jpg'),
        ('bel_rtl', 'BEL RTL', 'belrtl.png', 'belrtl_fanart.jpg'),
        ('contact', 'Contact', 'contact.png', 'contact_fanart.jpg')
    ]

    for channel_infos in channels:
        item = Listitem()
        item.label = channel_infos[1]
        item.art["thumb"] = get_item_media_path('channels/be/' + channel_infos[2])
        item.art["fanart"] = get_item_media_path('channels/be/' + channel_infos[3])
        item.set_callback(list_categories, channel_infos[0])
        item_post_treatment(item)
        yield item
示例#11
0
def sixplay_root(plugin, **kwargs):

    # (item_id, label, thumb, fanart)
    channels = [
        ('m6', 'M6', 'm6.png', 'm6_fanart.jpg'),
        ('w9', 'W9', 'w9.png', 'w9_fanart.jpg'),
        ('6ter', '6ter', '6ter.png', '6ter_fanart.jpg'),
        ('fun_radio', 'Fun Radio', 'funradio.png', 'funradio_fanart.jpg'),
        ('rtl2', 'RTL 2', 'rtl2.png', 'rtl2_fanart.jpg')
        # ('courses', 'M6 Courses', 'm6courses.png', 'm6courses_fanart.jpg'),
        # ('100foot', '100%% Foot', '100foot.png', '100foot_fanart.jpg')
    ]

    for channel_infos in channels:
        item = Listitem()
        item.label = channel_infos[1]
        item.art["thumb"] = get_item_media_path('channels/fr/' + channel_infos[2])
        item.art["fanart"] = get_item_media_path('channels/fr/' + channel_infos[3])
        item.set_callback(list_categories, channel_infos[0])
        item_post_treatment(item)
        yield item
示例#12
0
def channels(plugin, **kwargs):
    """
    List all france.tv channels
    """
    # (item_id, label, thumb, fanart)
    channels = [
        ('timeline', 'Channel Timeline', 'timeline.png', 'timeline_fanart.jpg'),
        ('plutotvparanormal', 'Pluto TV Paranormal', 'plutotvparanormal.png', 'plutotvparanormal_fanart.jpg'),
        ('plutotvretro', 'Pluto TV Retro', 'plutotvretro.png', 'plutotvretro_fanart.jpg'),
        ('reeltruthcrime', 'Reel Truth Crime', 'reeltruthcrime.png', 'reeltruthcrime_fanart.jpg'),
        ('five', 'Channel 5', 'five.png', 'five_fanart.jpg'),
        ('fiveusa', '5 USA', 'fiveusa.png', 'fiveusa_fanart.jpg'),
        ('fivestar', '5 Star', 'fivestar.png', 'fivestar_fanart.jpg'),
        ('spike', 'Spike', 'spike.png', 'spike_fanart.jpg'),
        ('blaze', 'Blaze', 'blaze.png', 'blaze_fanart.jpg'),
        ('5spike', '5Spike', '5spike.png', '5spike_fanart.jpg'),
        ('5select', '5Select', '5select.png', '5select_fanart.jpg'),
        ('bet', 'Channel BET', 'bet.png', 'bet_fanart.jpg'),
        ('paramount', 'Channel Paramount Network', 'paramount.png', 'paramount_fanart.jpg'),
        ('pbsamerica', 'Channel PBS America', 'pbsamerica.png', 'pbsamerica_fanart.jpg'),
        ('realstories', 'Channel Real Stories', 'realstories.png', 'realstories_fanart.jpg'),
        ('plutotvchristmas', 'Pluto TV Christmas', 'plutotvchristmas.png', 'plutotvchristmas_fanart.jpg'),
        ('togethertv', 'Channel Together TV', 'togethertv.png', 'togethertv_fanart.jpg'),
        ('nextbyhot', 'NEXT by HOT', 'nextbyhot.png', 'nextbyhot_fanart.jpg'),
        ('plutotvdrama', 'PLUTO TV DRAMA', 'plutotvdrama.png', 'plutotvdrama_fanart.jpg'),
        ('plutotvmovies', 'PLUTO TV MOVIES', 'plutotvmovies.png', 'plutotvmovies_fanart.jpg'),
        ('plutotvfood', 'PLUTO TV Food', 'plutotvfood.png', 'plutotvfood_fanart.jpg'),
        ('mastersoffood', 'Masters of Food', 'mastersoffood.png', 'mastersoffood_fanart.jpg'),
        ('wwe', 'WWE', 'wwe.png', 'wwe_fanart.jpg'),
        ('smithsonian', 'Smithsonian', 'smithsonian.png', 'smithsonian_fanart.jpg')
    ]

    for channel_infos in channels:
        item = Listitem()
        item.label = channel_infos[1]
        item.art["thumb"] = get_item_media_path('channels/uk/' + channel_infos[2])
        item.art["fanart"] = get_item_media_path('channels/uk/' + channel_infos[3])
        item.set_callback(list_programs, channel_infos[0])
        item_post_treatment(item)
        yield item
def mytf1_root(plugin, **kwargs):

    # (item_id, label, thumb, fanart)
    channels = [
        ('tf1', 'TF1', 'tf1.png', 'tf1_fanart.jpg'),
        ('tmc', 'TMC', 'tmc.png', 'tmc_fanart.jpg'),
        ('tfx', 'TFX', 'tfx.png', 'tfx_fanart.jpg'),
        ('tf1-series-films', 'TF1 Séries Films', 'tf1seriesfilms.png', 'tf1seriesfilms_fanart.jpg')
    ]

    for channel_infos in channels:
        item = Listitem()
        item.label = channel_infos[1]
        item.art["thumb"] = get_item_media_path('channels/fr/' + channel_infos[2])
        item.art["fanart"] = get_item_media_path('channels/fr/' + channel_infos[3])
        item.set_callback(list_categories, channel_infos[0])
        item_post_treatment(item)
        yield item

    # Search feature
    item = Listitem.search(search)
    item_post_treatment(item)
    yield item
示例#14
0
def rtlplay_root(plugin, **kwargs):
    # (item_id, label, thumb, fanart)
    channels = [('rtl_tvi', 'RTL TVI', 'rtltvi.png', 'rtltvi_fanart.jpg'),
                ('club_rtl', 'CLUB RTL', 'clubrtl.png', 'clubrtl_fanart.jpg'),
                ('plug_rtl', 'PLUG RTL', 'plugrtl.png', 'plugrtl_fanart.jpg'),
                ('rtl_info', 'RTL INFO', 'rtlinfo.png', 'rtlinfo_fanart.jpg'),
                ('rtl_sport', 'RTL Sport', 'rtlsport.png',
                 'rtlsport_fanart.jpg'),
                ('bel_rtl', 'BEL RTL', 'belrtl.png', 'belrtl_fanart.jpg'),
                ('contact', 'Contact', 'contact.png', 'contact_fanart.jpg'),
                ('rtl_play', 'RTL Play', 'rtlplay.png', 'rtlplay_fanart.jpg')]

    for channel_infos in channels:
        item = Listitem()
        item.label = channel_infos[1]
        item.art["thumb"] = get_item_media_path('channels/be/' +
                                                channel_infos[2])
        item.art["fanart"] = get_item_media_path('channels/be/' +
                                                 channel_infos[3])
        item.set_callback(list_categories, channel_infos[0])
        item_post_treatment(item)
        yield item

    # all programs
    item = Listitem()
    item.label = plugin.localize(30717)
    item.art["thumb"] = get_item_media_path('channels/be/rtlplay.png')
    item.art["fanart"] = get_item_media_path('channels/be/rtlplay_fanart.jpg')
    item.set_callback(list_all_programs, 'rtl_play')
    item_post_treatment(item)
    yield item

    item = Listitem.search(list_videos_search, item_id='rtl_play', page='0')
    item.label = plugin.localize(30715)
    item_post_treatment(item)
    yield item
    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,
                 lang) in channels:
                channel_key = channel_id if not lang else channel_id + ' ' + lang
                if not tv_integration_settings['enabled_channels'].get(
                        country_id, {}).get(channel_key, {}).get(
                            'enabled', False):
                    continue

                json_stream = {}
                json_stream['name'] = channel_label
                resolver = channel_infos['resolver'].replace(':', '/')
                params = {'item_id': channel_id}
                if lang:
                    params['language'] = lang
                    lang_infos = channel_infos['available_languages'][lang]
                    json_stream['id'] = lang_infos.get('xmltv_id')
                    json_stream['preset'] = lang_infos.get('m3u_order')
                else:
                    json_stream['id'] = channel_infos.get('xmltv_id')
                    json_stream['preset'] = channel_infos.get('m3u_order')

                # It seems that in Python 2 urlencode doesn't deal well with unicode data
                # (see https://stackoverflow.com/a/3121311)
                for k, v in params.items():
                    params[k] = utils.ensure_native_str(v)

                json_stream['stream'] = utils.ensure_native_str(
                    PLUGIN_KODI_PATH + resolver + '/?') + urlencode(params)
                json_stream['logo'] = get_item_media_path(
                    channel_infos['thumb'])

                channels_list.append(json_stream)

        return dict(version=1, streams=channels_list)
    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)
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
示例#18
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)
示例#19
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