def process_replaytv_search(search):
    now = datetime.datetime.now(pytz.timezone("Europe/Amsterdam"))
    sevendays = datetime.datetime.now(pytz.timezone("Europe/Amsterdam")) - datetime.timedelta(days=7)
    nowstamp = int((now - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds())
    sevendaysstamp = int((sevendays - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds())

    search = unicode(search)

    data = api_get_channels()

    prefs = load_prefs(profile_id=1)
    channels_ar = []

    if prefs:
        for row in prefs:
            currow = prefs[row]

            if not check_key(data, unicode(row)):
                continue

            if int(currow['replay']) == 1:
                channels_ar.append(row)

    data = api_get_list(start=nowstamp, end=sevendaysstamp, channels=channels_ar)

    items = []

    if not data:
        return {'items': items}

    for currow in data:
        row = data[currow]

        title = unicode(row['title'])
        icon = unicode(row['icon'])

        fuzz_set = fuzz.token_set_ratio(title, search)
        fuzz_partial = fuzz.partial_ratio(title, search)
        fuzz_sort = fuzz.token_sort_ratio(title, search)

        if (fuzz_set + fuzz_partial + fuzz_sort) > 160:
            label = title + ' (ReplayTV)'
            idtitle = unicode(currow)

            items.append(plugin.Item(
                label = label,
                info = {
                    'sorttitle': label.upper(),
                },
                art = {
                    'thumb': icon,
                    'fanart': icon
                },
                properties = {"fuzz_set": fuzz_set, "fuzz_sort": fuzz_sort, "fuzz_partial": fuzz_partial, "fuzz_total": fuzz_set + fuzz_partial + fuzz_sort},
                path = plugin.url_for(func_or_url=replaytv_item, label=label, idtitle=idtitle, start=0),
            ))

    returnar = {'items': items}

    return returnar
def get_replay_channels(all=False):
    channels = []

    data = api_get_channels()

    prefs = load_prefs(profile_id=1)

    if data:
        for currow in data:
            row = data[currow]

            id = unicode(row['id'])

            if all or not prefs or not check_key(prefs, id) or int(prefs[id]['replay']) == 1:
                channels.append({
                    'label': unicode(row['name']),
                    'channel': id,
                    'chno': unicode(row['channelno']),
                    'description': unicode(row['description']),
                    'image': unicode(row['icon']),
                    'path': plugin.url_for(func_or_url=replaytv_by_day, image=unicode(row['icon']), description=unicode(row['description']), label=unicode(row['name']), station=id),
                    'playable': False,
                    'context': [],
                })

    return channels
def get_live_channels(all=False):
    global backend
    channels = []

    data = api_get_channels()

    prefs = load_prefs(profile_id=1)

    if data:
        for currow in data:
            row = data[currow]

            path = plugin.url_for(func_or_url=play_video, type='channel', channel=row['id'], id=row['assetid'], _is_live=True)
            playable = True

            id = unicode(row['id'])

            if all or not prefs or not check_key(prefs, id) or prefs[id]['live'] == 1:
                channels.append({
                    'label': unicode(row['name']),
                    'channel': id,
                    'chno': unicode(row['channelno']),
                    'description': unicode(row['description']),
                    'image': unicode(row['icon']),
                    'path':  path,
                    'playable': playable,
                    'context': [
                        (_.START_BEGINNING, 'RunPlugin({context_url})'.format(context_url=plugin.url_for(func_or_url=play_video, type='channel', channel=id, id=unicode(row['assetid']), from_beginning=1, _is_live=True)), ),
                    ],
                })

    return channels
def channel_picker(type, **kwargs):
    if type=='live':
        title = _.LIVE_TV
        rows = get_live_channels(all=True)
    elif type=='replay':
        title = _.CHANNELS
        rows = get_replay_channels(all=True)

    folder = plugin.Folder(title=title)
    prefs = load_prefs(profile_id=1)
    type = unicode(type)

    for row in rows:
        id = unicode(row['channel'])

        if not prefs or not check_key(prefs, id) or prefs[id][type] == 1:
            color = 'green'
        else:
            color = 'red'

        label = _(unicode(row['label']), _bold=True, _color=color)

        folder.add_item(
            label = label,
            art = {'thumb': unicode(row['image'])},
            path = plugin.url_for(func_or_url=change_channel, type=type, id=id, change=0),
            playable = False,
        )

    return folder
def change_channel(type, id, change, **kwargs):
    change = int(change)

    if not id or len(unicode(id)) == 0 or not type or len(unicode(type)) == 0:
        return False

    prefs = load_prefs(profile_id=1)
    id = unicode(id)
    type = unicode(type)

    data = api_get_channels()

    if data and check_key(data, id) and prefs and check_key(prefs, id) and int(prefs[id][type]) == 0:
        if type == 'replay' and int(data[id]['replay']) == 0:
            gui.ok(message=_.EXPLAIN_NO_REPLAY)
            return False
        elif settings.getBool(key='homeConnection') == False and int(data[id]['home_only']) == 1:
            gui.ok(message=_.EXPLAIN_HOME_CONNECTION)
            return False

    keys = ['live', 'replay']

    mod_pref = {
        'live': 1,
        'replay': 1,
    }

    if prefs and check_key(prefs, id):
        for key in keys:
            if key == type:
                continue

            mod_pref[key] = prefs[id][key]

    if change == 0:
        if not check_key(prefs, id):
            mod_pref[type] = 0
        else:
            if prefs[id][type] == 1:
                mod_pref[type] = 0
            else:
                mod_pref[type] = 1
    else:
        mod_pref[type] = 1

    prefs[id] = mod_pref
    save_prefs(profile_id=1, prefs=prefs)

    xbmc.executeJSONRPC('{{"jsonrpc":"2.0","id":1,"method":"GUI.ActivateWindow","params":{{"window":"videos","parameters":["plugin://' + unicode(ADDON_ID) + '/?_=channel_picker&type=' + type + '"]}}}}')
Exemple #6
0
def change_group(id, type_tv_radio, **kwargs):
    if not id or len(str(id)) == 0:
        return False

    id = str(id)
    type_tv_radio = str(type_tv_radio)

    select_list = []

    if type_tv_radio == 'radio':
        groups = load_file('radio_groups.json', ext=False, isJSON=True)
        typestr = 'Radio'
    else:
        groups = load_file('tv_groups.json', ext=False, isJSON=True)
        typestr = 'TV'

    select_list.append(typestr)

    for group in groups:
        select_list.append(group)

    selected = gui.select(_.SELECT_GROUP, select_list)

    if type_tv_radio == 'radio':
        prefs = load_radio_prefs(profile_id=1)
    else:
        prefs = load_prefs(profile_id=1)

    try:
        prefs[id]['group'] = select_list[selected]
    except:
        pass

    if type_tv_radio == 'radio':
        save_radio_prefs(profile_id=1, prefs=prefs)
    else:
        save_prefs(profile_id=1, prefs=prefs)

    method = 'GUI.ActivateWindow'
    json_rpc(
        method, {
            "window":
            "videos",
            "parameters": [
                'plugin://' + str(ADDON_ID) +
                '/?_=group_picker_menu&type_tv_radio=' + type_tv_radio
            ]
        })
Exemple #7
0
def order_picker_menu(type_tv_radio, double=None, primary=None, **kwargs):
    type_tv_radio = str(type_tv_radio)

    save_all_order(type_tv_radio=type_tv_radio, double=double, primary=primary)

    folder = plugin.Folder(title=_.SELECT_ORDER)

    desc2 = _.NEXT_SETUP_GROUPS
    folder.add_item(label=_(_.NEXT, _bold=True),
                    info={'plot': desc2},
                    path=plugin.url_for(func_or_url=group_picker_menu,
                                        type_tv_radio=type_tv_radio))

    if type_tv_radio == 'live':
        prefs = load_prefs(profile_id=1)
        order = load_order(profile_id=1)
    else:
        prefs = load_radio_prefs(profile_id=1)
        order = load_radio_order(profile_id=1)

    if order:
        for currow in order:
            row = prefs[currow]

            if int(row[type_tv_radio]) == 0:
                continue

            label = _(row['name'] + ": " + str(order[str(currow)]), _bold=True)

            folder.add_item(
                label=label,
                path=plugin.url_for(func_or_url=change_order,
                                    id=currow,
                                    type_tv_radio=type_tv_radio),
                playable=False,
            )

    desc2 = _.NEXT_SETUP_GROUPS
    folder.add_item(label=_(_.NEXT, _bold=True),
                    info={'plot': desc2},
                    path=plugin.url_for(func_or_url=group_picker_menu,
                                        type_tv_radio=type_tv_radio))

    return folder
Exemple #8
0
def change_channel(id, type_tv_radio, **kwargs):
    if not id or len(str(id)) == 0:
        return False

    id = str(id)
    type_tv_radio = str(type_tv_radio)

    if type_tv_radio == 'radio':
        prefs = load_radio_prefs(profile_id=1)

        mod_pref = prefs[id]

        if int(mod_pref['radio']) == 0:
            mod_pref['radio'] = 1
        else:
            mod_pref['radio'] = 0

        prefs[id] = mod_pref
        save_radio_prefs(profile_id=1, prefs=prefs)

        method = 'GUI.ActivateWindow'
        json_rpc(
            method, {
                "window":
                "videos",
                "parameters": [
                    'plugin://' + str(ADDON_ID) +
                    '/?_=channel_picker_menu&type_tv_radio=radio&save_all=0'
                ]
            })
    else:
        profile_settings = load_profile(profile_id=1)
        prefs = load_prefs(profile_id=1)
        all_channels = load_channels(type='all')
        type_tv_radio = str(type_tv_radio)

        select_list = []
        num = 0

        for x in range(1, 6):
            if len(profile_settings['addon' + str(x)]) > 0:
                video_addon = profile_settings['addon' + str(x)]

                type_channels = load_channels(
                    type=video_addon.replace('plugin.video.', ''))

                VIDEO_ADDON_PROFILE = ADDON_PROFILE.replace(
                    ADDON_ID, video_addon)
                addon_prefs = load_file(VIDEO_ADDON_PROFILE + 'prefs.json',
                                        ext=True,
                                        isJSON=True)

                row2 = all_channels[id]

                type_id = str(row2[video_addon + '_id'])

                if len(type_id) > 0:
                    row = type_channels[type_id]

                    disabled = False

                    if addon_prefs:
                        try:
                            if check_key(addon_prefs, str(row['id'])) and int(
                                    addon_prefs[str(
                                        row['id'])][type_tv_radio]) == 0:
                                disabled = True
                        except:
                            pass

                    if disabled == False:
                        select_list.append(
                            profile_settings['addon' + str(x)].replace(
                                'plugin.video.', ''))
                        num += 1

        select_list.append(_.DISABLED)

        selected = gui.select(_.SELECT_ADDON, select_list)
        mod_pref = prefs[id]

        if selected and selected >= 0:
            mod_pref[type_tv_radio + '_auto'] = 0

            if selected == num:
                mod_pref[type_tv_radio] = 0
                mod_pref[type_tv_radio + '_addonid'] = ''
                mod_pref[type_tv_radio + '_channelid'] = ''
                mod_pref[type_tv_radio + '_channelassetid'] = ''

                if type_tv_radio == 'live':
                    mod_pref['channelname'] = ''
                    mod_pref['channelicon'] = ''
            else:
                mod_pref[type_tv_radio] = 1
                mod_pref[type_tv_radio +
                         '_addonid'] = 'plugin.video.' + select_list[selected]
                mod_pref[type_tv_radio + '_channelid'] = ''
                mod_pref[type_tv_radio + '_channelassetid'] = ''
                if type_tv_radio == 'live':
                    mod_pref['channelname'] = ''
                    mod_pref['channelicon'] = ''

                type_channels = load_channels(type=select_list[selected])
                row2 = all_channels[id]

                type_id = str(row2[mod_pref[type_tv_radio + '_addonid'] +
                                   '_id'])

                if len(type_id) > 0:
                    row = type_channels[type_id]

                    mod_pref[type_tv_radio + '_channelid'] = row['id']
                    mod_pref[type_tv_radio +
                             '_channelassetid'] = row['assetid']

                    if type_tv_radio == 'live':
                        mod_pref['channelname'] = row['name']
                        mod_pref['channelicon'] = row['icon']

            prefs[id] = mod_pref
            save_prefs(profile_id=1, prefs=prefs)

        method = 'GUI.ActivateWindow'
        json_rpc(
            method, {
                "window":
                "videos",
                "parameters": [
                    'plugin://' + str(ADDON_ID) +
                    '/?_=channel_picker_menu&type_tv_radio=' + type_tv_radio +
                    '&save_all=0'
                ]
            })
Exemple #9
0
def save_all_order(type_tv_radio, double=None, primary=None):
    if type_tv_radio == 'live':
        prefs = load_prefs(profile_id=1)
        order = load_order(profile_id=1)
    else:
        prefs = load_radio_prefs(profile_id=1)
        order = load_radio_order(profile_id=1)

    found_ar = []
    last_id = None

    for currow in prefs:
        row = prefs[currow]

        if int(row[type_tv_radio]) == 0:
            continue

        found_ar.append(currow)

        if not check_key(order, str(currow)):
            if not last_id:
                order[str(currow)] = 1
            else:
                order[str(currow)] = order[last_id] + 1

        last_id = str(currow)

    order2 = order.copy()

    for currow in order:
        if not currow in found_ar:
            del order2[currow]

    order2 = collections.OrderedDict(sorted(order2.items(),
                                            key=lambda x: x[1]))
    order3 = order2.copy()

    last_value = 0

    for currow in order2:
        cur_value = order2[currow]

        if cur_value == last_value:
            cur_value += 1

        order3[currow] = cur_value
        last_value = cur_value

    order3 = collections.OrderedDict(sorted(order3.items(),
                                            key=lambda x: x[1]))

    if double and primary:
        tmp_primary = order3[primary]
        order3[primary] = order3[double]
        order3[double] = tmp_primary
        order3 = collections.OrderedDict(
            sorted(order3.items(), key=lambda x: x[1]))

    if type_tv_radio == 'live':
        save_order(profile_id=1, order=order3)
    else:
        save_radio_order(profile_id=1, order=order3)
Exemple #10
0
def save_all_prefs(type_tv_radio):
    if api_get_channels() == True:
        if type_tv_radio == 'radio':
            type_channels = load_channels(type='radio')
            prefs = load_radio_prefs(profile_id=1)
            found_ar = []

            for currow in type_channels:
                row = type_channels[currow]
                all_id = str(row['id'])
                name = str(row['name'])

                if not prefs or not check_key(prefs, all_id):
                    prefs[all_id] = {'radio': 1, 'name': name}

                found_ar.append(all_id)

            prefs2 = prefs.copy()

            for currow in prefs:
                if not currow in found_ar:
                    del prefs2[currow]

            save_radio_prefs(profile_id=1, prefs=prefs2)
        else:
            profile_settings = load_profile(profile_id=1)

            all_channels = load_channels(type='all')
            prefs = load_prefs(profile_id=1)
            found_ar = []
            addon_list = []

            for x in range(1, 6):
                if len(profile_settings['addon' + str(x)]) > 0:
                    addon_list.append(profile_settings['addon' + str(x)])

            prefs2 = prefs.copy()

            for all_id in prefs2:
                pref = prefs2[all_id]

                if len(pref['live_addonid']) > 0:
                    if not pref['live_addonid'] in addon_list:
                        del prefs[all_id]
                        continue

                if check_key(
                        pref,
                        'replay_addonid') and len(pref['replay_addonid']) > 0:
                    if not pref['replay_addonid'] in addon_list:
                        del prefs[all_id]['replay']
                        del prefs[all_id]['replay_addonid']
                        del prefs[all_id]['replay_auto']
                        del prefs[all_id]['replay_channelid']
                        del prefs[all_id]['replay_channelassetid']

            for x in range(1, 6):
                if len(profile_settings['addon' + str(x)]) > 0:
                    video_addon = profile_settings['addon' + str(x)]

                    type_channels = load_channels(
                        type=video_addon.replace('plugin.video.', ''))

                    VIDEO_ADDON_PROFILE = ADDON_PROFILE.replace(
                        ADDON_ID, video_addon)
                    addon_prefs = load_file(VIDEO_ADDON_PROFILE + 'prefs.json',
                                            ext=True,
                                            isJSON=True)

                    for currow in type_channels:
                        row = type_channels[currow]

                        all_id = None

                        for currow2 in all_channels:
                            row2 = all_channels[currow2]

                            if str(row2[video_addon + '_id']) == str(
                                    row['id']):
                                all_id = str(currow2)

                        if not all_id:
                            continue

                        if type_tv_radio == 'replay' and not check_key(
                                prefs, all_id):
                            continue

                        disabled = False

                        if addon_prefs:
                            try:
                                if int(addon_prefs[str(
                                        row['id'])][type_tv_radio]) == 0:
                                    disabled = True
                            except:
                                pass

                        if disabled == True:
                            if type_tv_radio == 'live':
                                if all_id and check_key(
                                        prefs, all_id) and prefs[all_id][
                                            'live_addonid'] == video_addon:
                                    del prefs[all_id]
                            else:
                                try:
                                    if all_id and check_key(
                                            prefs, all_id
                                    ) and prefs[all_id][
                                            'replay_addonid'] == video_addon:
                                        del prefs[all_id]['replay']
                                        del prefs[all_id]['replay_addonid']
                                        del prefs[all_id]['replay_auto']
                                        del prefs[all_id]['replay_channelid']
                                        del prefs[all_id][
                                            'replay_channelassetid']
                                except:
                                    pass

                            continue

                        if type_tv_radio == 'live':
                            if not prefs or not check_key(prefs, all_id):
                                prefs[all_id] = {
                                    'live': 1,
                                    'live_addonid': video_addon,
                                    'live_auto': 1,
                                    'name': row['name'],
                                    'live_channelid': row['id'],
                                    'live_channelassetid': row['assetid'],
                                    'channelname': row['name'],
                                    'channelicon': row['icon']
                                }
                            elif int(
                                    prefs[all_id]['live_auto']
                            ) == 1 and all_id and not all_id in found_ar:
                                prefs[all_id]['live'] = 1
                                prefs[all_id]['live_addonid'] = video_addon
                                prefs[all_id]['live_auto'] = 1
                                prefs[all_id]['live_channelid'] = row['id']
                                prefs[all_id]['live_channelassetid'] = row[
                                    'assetid']
                        else:
                            try:
                                if (not prefs or not check_key(prefs, all_id)
                                    ) or (int(prefs[all_id]['replay_auto'])
                                          == 1 and all_id
                                          and not all_id in found_ar):
                                    prefs[all_id]['replay'] = 1
                                    prefs[all_id][
                                        'replay_addonid'] = video_addon
                                    prefs[all_id]['replay_auto'] = 1
                                    prefs[all_id]['replay_channelid'] = row[
                                        'id']
                                    prefs[all_id][
                                        'replay_channelassetid'] = row[
                                            'assetid']
                            except:
                                prefs[all_id]['replay'] = 1
                                prefs[all_id]['replay_addonid'] = video_addon
                                prefs[all_id]['replay_auto'] = 1
                                prefs[all_id]['replay_channelid'] = row['id']
                                prefs[all_id]['replay_channelassetid'] = row[
                                    'assetid']

                        found_ar.append(all_id)

            prefs2 = prefs.copy()

            if type_tv_radio == 'live':
                for currow in prefs:
                    if not currow in found_ar:
                        del prefs2[currow]

            save_prefs(profile_id=1, prefs=prefs2)
Exemple #11
0
def group_picker_menu(type_tv_radio, **kwargs):
    type_tv_radio = str(type_tv_radio)

    folder = plugin.Folder(title=_.SELECT_GROUP)

    if type_tv_radio == 'live':
        profile_settings = load_profile(profile_id=1)

        if int(profile_settings['radio']) == 1:
            desc2 = _.NEXT_SETUP_RADIO
            path = plugin.url_for(func_or_url=channel_picker_menu,
                                  type_tv_radio='radio',
                                  save_all=1)
        else:
            desc2 = _.NEXT_SETUP_IPTV
            path = plugin.url_for(func_or_url=simple_iptv_menu)

        folder.add_item(label=_(_.NEXT, _bold=True),
                        info={'plot': desc2},
                        path=path)

        prefs = load_prefs(profile_id=1)
        groups = load_file('tv_groups.json', ext=False, isJSON=True)
    else:
        desc2 = _.NEXT_SETUP_IPTV

        folder.add_item(label=_(_.NEXT, _bold=True),
                        info={'plot': desc2},
                        path=plugin.url_for(func_or_url=simple_iptv_menu))

        prefs = load_radio_prefs(profile_id=1)
        groups = load_file('radio_groups.json', ext=False, isJSON=True)

    if not groups:
        groups = []
    else:
        groups = list(groups)

    if prefs:
        for currow in prefs:
            row = prefs[currow]

            if int(row[type_tv_radio]) == 0:
                continue

            if check_key(row, 'group'):
                label = _(row['name'] + ": " + str(row['group']), _bold=True)
            else:
                if type_tv_radio == 'live':
                    label = _(row['name'] + ": TV", _bold=True)
                else:
                    label = _(row['name'] + ": Radio", _bold=True)

            folder.add_item(
                label=label,
                path=plugin.url_for(func_or_url=change_group,
                                    id=currow,
                                    type_tv_radio=type_tv_radio),
                playable=False,
            )

    if type_tv_radio == 'live':
        folder.add_item(label=_(_.NEXT, _bold=True),
                        info={'plot': desc2},
                        path=path)
    else:
        folder.add_item(label=_(_.NEXT, _bold=True),
                        info={'plot': desc2},
                        path=plugin.url_for(func_or_url=simple_iptv_menu))

    return folder
Exemple #12
0
def process_replaytv_list_content(label, idtitle, start=0):
    start = int(start)

    now = datetime.datetime.now(pytz.timezone("Europe/Amsterdam"))
    sevendays = datetime.datetime.now(pytz.timezone("Europe/Amsterdam")) - datetime.timedelta(days=7)
    nowstamp = int((now - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds())
    sevendaysstamp = int((sevendays - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds())

    data = api_get_channels()

    prefs = load_prefs(profile_id=1)
    channels_ar = []
    channels_ar2 = {}

    if prefs:
        for row in prefs:
            currow = prefs[row]

            if not check_key(data, unicode(row)):
                continue

            channels_ar2[unicode(row)] = data[unicode(row)]['name']

            if int(currow['replay']) == 1:
                channels_ar.append(row)

    data = api_get_epg_by_idtitle(idtitle=idtitle, start=nowstamp, end=sevendaysstamp, channels=channels_ar)

    items = []
    count = 0
    item_count = 0

    if not data:
        return {'items': items, 'count': item_count, 'count2': count, 'total': 0}

    for currow in data:
        row = data[currow]

        if item_count == 51:
            break

        count += 1

        if count < start + 1:
            continue

        context = []
        item_count += 1

        channel = unicode(row['channel'])

        startT = datetime.datetime.fromtimestamp(int(row['start']))
        startT = convert_datetime_timezone(startT, "Europe/Amsterdam", "Europe/Amsterdam")
        endT = datetime.datetime.fromtimestamp(int(row['end']))
        endT = convert_datetime_timezone(endT, "Europe/Amsterdam", "Europe/Amsterdam")

        if xbmc.getLanguage(xbmc.ISO_639_1) == 'nl':
            itemlabel = '{weekday} {day} {month} {yearhourminute} '.format(weekday=date_to_nl_dag(startT), day=startT.strftime("%d"), month=date_to_nl_maand(startT), yearhourminute=startT.strftime("%Y %H:%M"))
        else:
            itemlabel = startT.strftime("%A %d %B %Y %H:%M ").capitalize()

        itemlabel += unicode(row['title'])

        try:
            itemlabel += " (" + unicode(channels_ar2[channel]) + ")"
        except:
            pass

        description = unicode(row['description'])
        duration = int((endT - startT).total_seconds())
        program_image = unicode(row['icon'])
        program_image_large = unicode(row['icon'])
        program_id = unicode(row['program_id'])

        if CONST_WATCHLIST:
            context.append((_.ADD_TO_WATCHLIST, 'RunPlugin({context_url})'.format(context_url=plugin.url_for(func_or_url=add_to_watchlist, id=program_id, type='item')), ))

        items.append(plugin.Item(
            label = itemlabel,
            info = {
                'plot': description,
                'duration': duration,
                'mediatype': 'video',
                'sorttitle': itemlabel.upper(),
            },
            art = {
                'thumb': program_image,
                'fanart': program_image_large
            },
            path = plugin.url_for(func_or_url=play_video, type='program', channel=channel, id=program_id),
            playable = True,
            context = context
        ))

    returnar = {'items': items, 'count': item_count, 'count2': count, 'total': len(data)}

    return returnar
Exemple #13
0
def order_picker_menu(type_tv_radio, double=None, primary=None, **kwargs):
    type_tv_radio = unicode(type_tv_radio)

    save_all_order(type_tv_radio=type_tv_radio, double=double, primary=primary)

    folder = plugin.Folder(title=_.SELECT_ORDER)

    if type_tv_radio == 'live':
        profile_settings = load_profile(profile_id=1)

        if int(profile_settings['radio']) == 1:
            desc2 = _.NEXT_SETUP_RADIO
            path = plugin.url_for(func_or_url=channel_picker_menu,
                                  type_tv_radio='radio',
                                  save_all=1)
        else:
            desc2 = _.NEXT_SETUP_IPTV
            path = plugin.url_for(func_or_url=simple_iptv_menu)

        folder.add_item(label=_(_.NEXT, _bold=True),
                        info={'plot': desc2},
                        path=path)

        prefs = load_prefs(profile_id=1)
        order = load_order(profile_id=1)
    else:
        desc2 = _.NEXT_SETUP_IPTV

        folder.add_item(label=_(_.NEXT, _bold=True),
                        info={'plot': desc2},
                        path=plugin.url_for(func_or_url=simple_iptv_menu))

        prefs = load_radio_prefs(profile_id=1)
        order = load_radio_order(profile_id=1)

    if order:
        for currow in order:
            row = prefs[currow]

            if int(row[type_tv_radio]) == 0:
                continue

            label = _(row['name'] + ": " + unicode(order[unicode(currow)]),
                      _bold=True)

            folder.add_item(
                label=label,
                path=plugin.url_for(func_or_url=change_order,
                                    id=currow,
                                    type_tv_radio=type_tv_radio),
                playable=False,
            )

    if type_tv_radio == 'live':
        folder.add_item(label=_(_.NEXT, _bold=True),
                        info={'plot': desc2},
                        path=path)
    else:
        folder.add_item(label=_(_.NEXT, _bold=True),
                        info={'plot': desc2},
                        path=plugin.url_for(func_or_url=simple_iptv_menu))

    return folder
Exemple #14
0
def process_replaytv_list(character, start=0):
    now = datetime.datetime.now(pytz.timezone("Europe/Amsterdam"))
    sevendays = datetime.datetime.now(pytz.timezone("Europe/Amsterdam")) - datetime.timedelta(days=7)
    nowstamp = int((now - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds())
    sevendaysstamp = int((sevendays - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds())

    data = api_get_channels()

    prefs = load_prefs(profile_id=1)
    channels_ar = []

    if prefs:
        for row in prefs:
            currow = prefs[row]

            if not check_key(data, unicode(row)):
                continue

            if int(currow['replay']) == 1:
                channels_ar.append(row)

    data = api_get_list_by_first(first=character, start=nowstamp, end=sevendaysstamp, channels=channels_ar)

    start = int(start)
    items = []
    count = 0
    item_count = 0

    if not data:
        return {'items': items, 'count': item_count, 'count2': count, 'total': 0}

    for currow in data:
        row = data[currow]

        if item_count == 51:
            break

        count += 1

        if count < start + 1:
            continue

        item_count += 1

        label = unicode(row['title'])
        idtitle = unicode(currow)
        icon = unicode(row['icon'])

        items.append(plugin.Item(
            label = label,
            info = {
                'sorttitle': label.upper(),
            },
            art = {
                'thumb': icon,
                'fanart': icon
            },
            path = plugin.url_for(func_or_url=replaytv_item, label=label, idtitle=idtitle, start=0),
        ))

    returnar = {'items': items, 'count': item_count, 'count2': count, 'total': len(data)}

    return returnar
Exemple #15
0
def create_playlist():
    playlist = u'#EXTM3U\n'

    order = load_order(profile_id=1)
    prefs = load_prefs(profile_id=1)

    for currow in order:
        ch_no = unicode(order[currow])
        row = prefs[unicode(currow)]

        if not check_key(row, 'live') or not check_key(
                row, 'live_channelid') or not check_key(
                    row, 'live_channelassetid') or not check_key(
                        row, 'live_addonid') or not check_key(
                            row, 'channelname') or not int(row['live']) == 1:
            continue

        live_id = unicode(row['live_channelid'])

        if len(live_id) > 0:
            if not check_key(row, 'channelicon'):
                image = ''
            else:
                image = row['channelicon']

            path = unicode(
                'plugin://{addonid}/?_=play_video&channel={channel}&id={asset}&type=channel&pvr=1&_l=.pvr'
                .format(addonid=row['live_addonid'],
                        channel=row['live_channelid'],
                        asset=row['live_channelassetid']))

            if not check_key(row, 'replay'):
                replay = 0
            else:
                replay = int(row['replay'])

            if not check_key(row, 'replay_channelid'):
                replay_id = ''
            else:
                replay_id = unicode(row['replay_channelid'])

            try:
                if replay == 1 and len(replay_id) > 0:
                    catchup = unicode('plugin://' + row['replay_addonid'] +
                                      '/?_=play_video&type=program&channel=' +
                                      row['replay_channelid'] +
                                      '&id={catchup-id}')
                    playlist += u'#EXTINF:0 tvg-id="{id}" tvg-chno="{channel}" tvg-name="{name}" tvg-logo="{logo}" catchup="default" catchup-source="{catchup}" catchup-days="7" group-title="TV" radio="false",{name}\n{path}\n'.format(
                        id=unicode(row['replay_channelid']),
                        channel=ch_no,
                        name=unicode(row['channelname']),
                        logo=image,
                        catchup=catchup,
                        path=path)
                else:
                    playlist += u'#EXTINF:0 tvg-id="{id}" tvg-chno="{channel}" tvg-name="{name}" tvg-logo="{logo}" group-title="TV" radio="false",{name}\n{path}\n'.format(
                        id=unicode(row['live_channelid']),
                        channel=ch_no,
                        name=unicode(row['channelname']),
                        logo=image,
                        path=path)
            except:
                pass

    profile_settings = load_profile(profile_id=1)

    if check_key(profile_settings, 'radio') and int(
            profile_settings['radio']) == 1:
        order = load_radio_order(profile_id=1)
        prefs = load_radio_prefs(profile_id=1)
        radio = load_channels(type='radio')

        for currow in order:
            ch_no = unicode(order[currow])
            row = prefs[unicode(currow)]

            if not check_key(row, 'radio') or int(row['radio']) == 0:
                continue

            id = unicode(currow)

            if len(id) > 0:
                if not radio or not check_key(radio, id) or not check_key(
                        radio[id], 'name') or not check_key(radio[id], 'url'):
                    continue

                if check_key(radio[id], 'mod_name') and len(
                        unicode(radio[id]['mod_name'])) > 0:
                    label = unicode(radio[id]['mod_name'])
                else:
                    label = unicode(radio[id]['name'])

                path = unicode(radio[id]['url'])

                if check_key(radio[id],
                             'icon') and len(unicode(radio[id]['icon'])) > 0:
                    image = unicode(radio[id]['icon'])
                else:
                    image = ''

                playlist += u'#EXTINF:0 tvg-id="{id}" tvg-chno="{channel}" tvg-name="{name}" tvg-logo="{logo}" group-title="Radio" radio="true",{name}\n{path}\n'.format(
                    id=id, channel=ch_no, name=label, logo=image, path=path)

    write_file(file="playlist.m3u8", data=playlist, isJSON=False)
Exemple #16
0
def channel_picker_menu(type_tv_radio, save_all=0, radio=None, **kwargs):
    type_tv_radio = str(type_tv_radio)
    save_all = int(save_all)

    if not radio == None:
        radio = int(radio)
        profile_settings = load_profile(profile_id=1)
        profile_settings['radio'] = radio
        save_profile(profile_id=1, profile=profile_settings)

    if save_all == 1:
        save_all_prefs(type_tv_radio)

    if type_tv_radio == 'live':
        folder = plugin.Folder(title=_.SELECT_LIVE)
        desc2 = _.NEXT_SETUP_REPLAY
        folder.add_item(label=_(_.NEXT, _bold=True),
                        info={'plot': desc2},
                        path=plugin.url_for(func_or_url=channel_picker_menu,
                                            type_tv_radio='replay',
                                            save_all=1))
        prefs = load_prefs(profile_id=1)
    elif type_tv_radio == 'replay':
        folder = plugin.Folder(title=_.SELECT_REPLAY)
        desc2 = _.NEXT_SETUP_ORDER
        prefs = load_prefs(profile_id=1)
        folder.add_item(label=_(_.NEXT, _bold=True),
                        info={'plot': desc2},
                        path=plugin.url_for(func_or_url=order_picker_menu,
                                            type_tv_radio='live'))
    else:
        folder = plugin.Folder(title=_.SELECT_RADIO)
        desc2 = _.NEXT_SETUP_ORDER
        folder.add_item(label=_(_.NEXT, _bold=True),
                        info={'plot': desc2},
                        path=plugin.url_for(func_or_url=order_picker_menu,
                                            type_tv_radio='radio'))
        prefs = load_radio_prefs(profile_id=1)

    if prefs:
        for currow in prefs:
            row = prefs[currow]

            if not check_key(row, type_tv_radio):
                continue

            if row[type_tv_radio] == 1:
                color = 'green'

                if not type_tv_radio == 'radio':
                    addon_type = row[type_tv_radio + '_addonid'].replace(
                        'plugin.video.', '')
            else:
                color = 'red'

                if not type_tv_radio == 'radio':
                    addon_type = _.DISABLED

            if not type_tv_radio == 'radio':
                label = _(row['name'] + ": " + addon_type,
                          _bold=True,
                          _color=color)
            else:
                label = _(row['name'], _bold=True, _color=color)

            folder.add_item(
                label=label,
                path=plugin.url_for(func_or_url=change_channel,
                                    id=currow,
                                    type_tv_radio=type_tv_radio),
                playable=False,
            )

    if type_tv_radio == 'live':
        folder.add_item(label=_(_.NEXT, _bold=True),
                        info={'plot': desc2},
                        path=plugin.url_for(func_or_url=channel_picker_menu,
                                            type_tv_radio='replay',
                                            save_all=1))
    elif type_tv_radio == 'replay':
        folder.add_item(label=_(_.NEXT, _bold=True),
                        info={'plot': desc2},
                        path=plugin.url_for(func_or_url=order_picker_menu,
                                            type_tv_radio='live'))
    else:
        folder.add_item(label=_(_.NEXT, _bold=True),
                        info={'plot': desc2},
                        path=plugin.url_for(func_or_url=order_picker_menu,
                                            type_tv_radio='radio'))

    return folder
Exemple #17
0
def create_epg():
    order = load_order(profile_id=1)
    prefs = load_prefs(profile_id=1)

    new_xml_start = '<?xml version="1.0" encoding="utf-8" ?><tv generator-info-name="{addonid}">'.format(
        addonid=ADDON_ID)
    new_xml_end = '</tv>'
    new_xml_channels = ''
    new_xml_epg = ''

    for currow in order:
        ch_no = unicode(order[currow])
        row = prefs[unicode(currow)]

        if not check_key(row, 'live') or not check_key(
                row, 'live_channelid') or not check_key(
                    row, 'live_addonid') or not check_key(
                        row, 'channelname') or not int(row['live']) == 1:
            continue

        live_id = unicode(row['live_channelid'])

        if not check_key(row, 'replay'):
            replay = 0
        else:
            replay = int(row['replay'])

        if not check_key(row, 'replay_channelid'):
            replay_id = ''
        else:
            replay_id = unicode(row['replay_channelid'])

        if not check_key(row, 'replay_addonid'):
            replay_addonid = ''
        else:
            replay_addonid = unicode(row['replay_addonid'])

        if replay == 1 and len(replay_id) > 0 and len(replay_addonid) > 0:
            directory = "cache" + os.sep + replay_addonid.replace(
                'plugin.video.', '') + os.sep
            encodedBytes = base64.b32encode(replay_id.encode("utf-8"))
            replay_id = unicode(encodedBytes, "utf-8")

            data = load_file(directory + replay_id + '.xml',
                             ext=False,
                             isJSON=False)
        else:
            directory = "cache" + os.sep + unicode(row['live_addonid'].replace(
                'plugin.video.', '')) + os.sep
            encodedBytes = base64.b32encode(live_id.encode("utf-8"))
            live_id = unicode(encodedBytes, "utf-8")

            data = load_file(directory + live_id + '.xml',
                             ext=False,
                             isJSON=False)

        if data:
            new_xml_epg += data

            try:
                if replay == 1 and len(replay_id) > 0 and len(
                        replay_addonid) > 0:
                    new_xml_channels += '<channel id="{channelid}"><display-name>{channelname}</display-name><icon-name src="{channelicon}"></icon-name><desc></desc></channel>'.format(
                        channelid=unicode(row['replay_channelid']),
                        channelname=unicode(row['channelname']),
                        channelicon=unicode(row['channelicon']))
                else:
                    new_xml_channels += '<channel id="{channelid}"><display-name>{channelname}</display-name><icon-name src="{channelicon}"></icon-name><desc></desc></channel>'.format(
                        channelid=unicode(row['live_channelid']),
                        channelname=unicode(row['channelname']),
                        channelicon=unicode(row['channelicon']))
            except:
                pass

    write_file(file='epg.xml',
               data=new_xml_start + new_xml_channels + new_xml_epg +
               new_xml_end,
               isJSON=False)
Exemple #18
0
def create_epg():
    order = load_order(profile_id=1)
    prefs = load_prefs(profile_id=1)

    new_xml_start = '<?xml version="1.0" encoding="utf-8" ?><tv generator-info-name="{addonid}">'.format(addonid=ADDON_ID)
    new_xml_end = '</tv>'
    new_xml_channels = ''
    new_xml_epg = ''
    addon_id = ''

    for currow in order:
        try:
            ch_no = str(order[currow])
            row = prefs[str(currow)]

            if not check_key(row, 'live') or not check_key(row, 'live_channelid') or not check_key(row, 'live_addonid') or not check_key(row, 'channelname') or not int(row['live']) == 1:
                continue

            live_id = str(row['live_channelid'])

            if not check_key(row, 'replay'):
                replay = 0
            else:
                replay = int(row['replay'])

            if not check_key(row, 'replay_channelid'):
                replay_id = ''
            else:
                replay_id = str(row['replay_channelid'])

            if not check_key(row, 'replay_addonid'):
                replay_addonid = ''
            else:
                replay_addonid = str(row['replay_addonid'])

            if replay == 1 and len(replay_id) > 0 and len(replay_addonid) > 0:
                directory = os.path.join("cache", replay_addonid.replace('plugin.video.', ''), "")
                replay_id = encode32(replay_id)

                addon_id = replay_addonid
                data = load_file(os.path.join(directory, replay_id + '.xml'), ext=False, isJSON=False)
            else:
                directory = os.path.join("cache", str(row['live_addonid'].replace('plugin.video.', '')), "")
                live_id = encode32(live_id)

                addon_id = row['live_addonid']
                data = load_file(os.path.join(directory, live_id + '.xml'), ext=False, isJSON=False)

            if data:
                if len(addon_id) > 0:
                    try:
                        if settings.getBool('use_small_images', default=False, addon=addon_id):
                            data = data.replace(CONST_IMAGES[addon_id]['replace'], CONST_IMAGES[addon_id]['small'])
                        else:
                            data = data.replace(CONST_IMAGES[addon_id]['replace'], CONST_IMAGES[addon_id]['large'])
                    except:
                        pass

                new_xml_epg += data

                try:
                    if replay == 1 and len(replay_id) > 0 and len(replay_addonid) > 0:
                        new_xml_channels += '<channel id="{channelid}"><display-name>{channelname}</display-name><icon src="{channelicon}"></icon><desc></desc></channel>'.format(channelid=str(row['replay_channelid']), channelname=str(row['channelname']), channelicon=str(row['channelicon']))
                    else:
                        new_xml_channels += '<channel id="{channelid}"><display-name>{channelname}</display-name><icon src="{channelicon}"></icon><desc></desc></channel>'.format(channelid=str(row['live_channelid']), channelname=str(row['channelname']), channelicon=str(row['channelicon']))
                except:
                    pass
        except:
            pass

    write_file(file='epg.xml', data=new_xml_start + new_xml_channels + new_xml_epg + new_xml_end, isJSON=False)