Exemplo n.º 1
0
def guess_fav_prefix(item_id):
    """Keep in memory the current main category (e.g. Live TV, Catch-up TV, ...)
    This category label will be used as a prefix when the user add a favourite

    """
    prefixes = {
        'root': '',
        'live_tv': Script.localize(30030),
        'replay': Script.localize(30031),
        'websites': Script.localize(30032)
    }
    if item_id in prefixes:
        s = mem_storage.MemStorage('fav')
        s['prefix'] = prefixes[item_id]
Exemplo n.º 2
0
def guess_fav_prefix(item_id):
    """Keep in memory the current main category (e.g. Live TV, Catch-up TV, ...)
    This category label will be used as a prefix when the user add a favourite

    """

    prefix = 'empty'
    if item_id == 'live_tv':
        prefix = Script.localize(30030)
    elif item_id == 'replay':
        prefix = Script.localize(30031)
    elif item_id == 'websites':
        prefix = Script.localize(30032)
    elif item_id == 'root':
        prefix = ''
    if prefix != 'empty':
        s = mem_storage.MemStorage('fav')
        s['prefix'] = prefix
def guess_fav_prefix(item_id):
    """
    When the use add a favourite,
    guess the prefix to add for the
    favourite label according to the
    current main category
    """
    prefix = 'empty'
    if item_id == 'live_tv':
        prefix = Script.localize(LABELS['live_tv'])
    elif item_id == 'replay':
        prefix = Script.localize(LABELS['replay'])
    elif item_id == 'websites':
        prefix = Script.localize(LABELS['websites'])
    elif item_id == 'root':
        prefix = ''
    if prefix != 'empty':
        s = mem_storage.MemStorage('fav')
        s['prefix'] = prefix
Exemplo n.º 4
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)
def add_item_to_favourites(plugin, item_dict={}, **kwargs):
    """
    Callback function called when the user click
    on 'add item to favourite' from an item
    context menu
    """

    if 'channel_infos' in kwargs and \
            kwargs['channel_infos'] is not None:

        # This item come from tv_guide_menu
        # We need to remove guide TV related
        # elements

        item_id = item_dict['params']['item_id']
        label = item_id
        if item_id in LABELS:
            label = LABELS[item_id]
            if isinstance(label, int):
                label = Script.localize(label)
        item_dict['label'] = label

        if 'thumb' in kwargs['channel_infos']:
            item_dict['art']["thumb"] = common.get_item_media_path(
                kwargs['channel_infos']['thumb'])

        if 'fanart' in kwargs['channel_infos']:
            item_dict['art']["fanart"] = common.get_item_media_path(
                kwargs['channel_infos']['fanart'])

        item_dict['info'] = {}

    # 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
    item_dict['label'] = utils.keyboard(
        plugin.localize(LABELS['Favorite name']), label_proposal)

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

    # Add this item to favourite db
    with storage.PersistentDict("favourites.pickle") as db:

        # Compute hash value used as key in the DB
        item_hash = md5(str(item_dict)).hexdigest()

        item_dict['params']['order'] = len(db)

        db[item_hash] = item_dict

    Script.notify(Script.localize(30033),
                  Script.localize(30805),
                  display_time=7000)
# The unicode_literals import only has
# an effect on Python 2.
# It makes string literals as unicode like in Python 3
from __future__ import unicode_literals

from codequick import Script, utils

import resources.lib.mem_storage as mem_storage
"""
LABELS dict is only used to
retrieve correct element in strings.po.
If the item has no translation just use a string.
"""

s = mem_storage.MemStorage('cutv_labels')


def save_labels_in_mem_storage():
    """Evaluate LABELS dict and save it in mem storage

    Returns:
        dict: LABELS dict
    """
    LABELS = {
        # Settings
        'Main menu':
        30000,
        'Countries':
        30001,
        'Quality and content':
Exemplo n.º 7
0
        prefix = Script.localize(30031)
    elif item_id == 'websites':
        prefix = Script.localize(30032)
    elif item_id == 'root':
        prefix = ''
    if prefix != 'empty':
=======
    prefixes = {
        'root': '',
        'live_tv': Script.localize(30030),
        'replay': Script.localize(30031),
        'websites': Script.localize(30032)
    }
    if item_id in prefixes:
>>>>>>> cf69920d1ba10a4558544c5d79d7c35f56d3e2c3:resources/lib/favourites.py
        s = mem_storage.MemStorage('fav')
        s['prefix'] = prefixes[item_id]


@Script.register
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