Esempio n. 1
0
def change_order(id, type_tv_radio, **kwargs):
    if not id or len(str(id)) == 0:
        return False

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

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

    selected = gui.numeric(_.SELECT_ORDER, order[id])
    double = None
    double_query = ''

    if selected and selected >= 0:
        for currow in order:
            if id == str(currow):
                continue

            if int(order[currow]) == int(selected):
                double = currow
                break

        order[id] = selected

    if type_tv_radio == 'live':
        save_order(profile_id=1, order=order)
    else:
        save_radio_order(profile_id=1, order=order)

    if double:
        double_query = '&double={double}&primary={primary}'.format(
            double=double, primary=id)

    method = 'GUI.ActivateWindow'
    json_rpc(
        method, {
            "window":
            "videos",
            "parameters": [
                'plugin://' + str(ADDON_ID) + '/?_=order_picker_menu' +
                double_query + '&type_tv_radio=' + type_tv_radio
            ]
        })
Esempio n. 2
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
Esempio n. 3
0
def change_order(id, type_tv_radio, **kwargs):
    if not id or len(unicode(id)) == 0:
        return False

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

    id = unicode(id)
    type_tv_radio = unicode(type_tv_radio)

    selected = gui.numeric(_.SELECT_ORDER, order[id])
    double = None
    double_query = ''

    if selected and selected >= 0:
        for currow in order:
            if id == unicode(currow):
                continue

            if int(order[currow]) == int(selected):
                double = currow
                break

        order[id] = selected

    if type_tv_radio == 'live':
        save_order(profile_id=1, order=order)
    else:
        save_radio_order(profile_id=1, order=order)

    if double:
        double_query = '&double={double}&primary={primary}'.format(
            double=double, primary=id)

    xbmc.executeJSONRPC(
        '{"jsonrpc":"2.0","id":1,"method":"GUI.ActivateWindow","params":{"window":"videos","parameters":["plugin://'
        + unicode(ADDON_ID) + '/?_=order_picker_menu' + double_query +
        '&type_tv_radio=' + type_tv_radio + '"]}}')
Esempio n. 4
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)
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
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
Esempio n. 8
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)