Beispiel #1
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'
                ]
            })
Beispiel #2
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)
Beispiel #3
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)