Exemplo n.º 1
0
def get_iptv_epg():
    """Get the EPG Data."""
    live = LiveChannels()
    channels = live.get_live_channels()
    blocked = live.get_blocked_iptv_channels()
    unblocked = []
    for channel in channels:
        callsign = CBC.get_callsign(channel)
        if callsign not in blocked:
            unblocked.append(channel)
    channel_map = map_channel_ids(unblocked)
    epg_data = {}

    future_to_callsign = {}
    log('Starting EPG update')
    with futures.ThreadPoolExecutor(max_workers=20) as executor:
        for callsign, guide_id in channel_map.items():

            # determine if we're dealing with news network
            newsnetwork = callsign == 'NN'

            # add empty array of programs
            epg_data[callsign] = []

            # submit three concurrent requests for a days guide data
            for day_offset in [0, 1, 2]:
                dttm = datetime.now() + timedelta(days=day_offset)
                future = executor.submit(get_channel_data, dttm, guide_id, newsnetwork)
                future_to_callsign[future] = callsign

        for future in futures.as_completed(future_to_callsign):
            callsign = future_to_callsign[future]
            epg_data[callsign].extend(future.result())
    log('EPG update complete.')
    return epg_data
Exemplo n.º 2
0
    def get_iptv_channels(self):
        """Get the channels in a IPTV Manager compatible list."""
        cbc = CBC()
        channels = self.get_live_channels()
        blocked = self.get_blocked_iptv_channels()
        result = []
        for channel in channels:
            callsign = CBC.get_callsign(channel)

            # if the user has omitted this from the list of their channels, don't populate it
            if callsign in blocked:
                continue

            labels = CBC.get_labels(channel)
            image = cbc.getImage(channel)
            values = {
                'url': channel['content'][0]['url'],
                'image': image,
                'labels': urlencode(labels)
            }
            channel_dict = {
                'name': channel['title'],
                'stream': 'plugin://plugin.video.cbc/smil?' + urlencode(values),
                'id': callsign,
                'logo': image
            }

            # Use "CBC Toronto" instead of "Toronto"
            if len(channel_dict['name']) < 4 or channel_dict['name'][0:4] != 'CBC ':
                channel_dict['name'] = 'CBC {}'.format(channel_dict['name'])
            result.append(channel_dict)

        return result
Exemplo n.º 3
0
def live_channels_menu():
    """Populate the menu with live channels."""
    xbmcplugin.setContent(plugin.handle, 'videos')
    chans = LiveChannels()
    chan_list = chans.get_live_channels()
    cbc = CBC()
    for channel in chan_list:
        labels = CBC.get_labels(channel)
        callsign = cbc.get_callsign(channel)
        image = cbc.getImage(channel)
        item = xbmcgui.ListItem(labels['title'])
        item.setArt({'thumb': image, 'poster': image})
        item.setInfo(type="Video", infoLabels=labels)
        item.setProperty('IsPlayable', 'true')
        item.addContextMenuItems([
            (getString(30014),
             'RunPlugin({})'.format(plugin.url_for(live_channels_add_all))),
            (getString(30015),
             'RunPlugin({})'.format(plugin.url_for(live_channels_add,
                                                   callsign))),
            (getString(30016), 'RunPlugin({})'.format(
                plugin.url_for(live_channels_remove, callsign))),
            (getString(30017), 'RunPlugin({})'.format(
                plugin.url_for(live_channels_add_only, callsign))),
        ])
        xbmcplugin.addDirectoryItem(
            plugin.handle,
            plugin.url_for(play_smil,
                           url=channel['content'][0]['url'],
                           labels=urlencode(labels),
                           image=image), item, False)
    xbmcplugin.endOfDirectory(plugin.handle)
Exemplo n.º 4
0
def map_channel_ids(unblocked):
    """Map channel IDs to guide names."""
    data = call_guide_url(datetime.now())
    soup = BeautifulSoup(data, features="html.parser")
    select = soup.find('select', id="selectlocation-tv")
    options = select.find_all('option')
    channel_map = {'NN': None}
    for option in options:
        title = option.get_text()
        value = option['value']
        for channel in unblocked:
            if unidecode(channel['title']).lower() == unidecode(title).lower():
                channel_map[CBC.get_callsign(channel)] = value
    return channel_map
Exemplo n.º 5
0
    def add_only_iptv_channel(channel):
        """
        Add only a single specified channel to the list of IPTV channels.

        This method gets the list of all channels, and removes the only one the user wants, leaving the rest as an
        extensive filter.
        """
        blocked = [CBC.get_callsign(chan) for chan in LiveChannels().get_live_channels()]

        if channel in blocked:
            blocked.remove(channel)

        with open(get_iptv_channels_file(), 'w') as chan_file:
            json.dump(blocked, chan_file)