示例#1
0
    def list_channels(self, is_folder=False):
        from kodiwrapper import KodiWrapper
        import datetime
        import dateutil.parser
        from dateutil.tz import UTC

        listing = []

        tv_channels = self.get_channels()
        epg = self.get_epg(tv_channels, full=False)

        for tv_channel in tv_channels:
            name = tv_channel.get('channelIdentification').get('name')
            square_logo = tv_channel.get('channelProperties').get('squareLogo')
            channel_id = tv_channel.get('channelIdentification').get(
                'stbUniqueName')

            poster = ""
            guide = ""

            for index, item in enumerate(epg[name]):
                now = datetime.datetime.utcnow().replace(second=0,
                                                         microsecond=0,
                                                         tzinfo=UTC)

                end = dateutil.parser.parse(item.get('stop'))
                if end <= now:
                    continue

                start = dateutil.parser.parse(item.get('start'))
                if start >= now:
                    continue

                try:
                    prev_title = epg.get(name, [])[index - 1].get('title', '')
                except IndexError:
                    prev_title = ''

                try:
                    next_title = epg.get(name, [])[index + 1].get('title', '')
                except IndexError:
                    next_title = ''

                title = item.get('title', '')
                guide = self._create_guide_from_channel_info(
                    prev_title, title, next_title)
                poster = item.get('image', '')
                break

            list_item = KodiWrapper.create_list_item(name, square_logo, poster,
                                                     {"plot": guide}, True,
                                                     True)
            url = KodiWrapper.url_for('play_id', channel_id=channel_id)
            listing.append((url, list_item, is_folder))

        KodiWrapper.add_dir_items(listing)
        KodiWrapper.end_directory()
示例#2
0
    def get_channels_iptv(self):
        allowed_tv_channels = self.get_channels()

        channels = []
        for channel in allowed_tv_channels:
            name = channel.get('channelIdentification', {}).get('name')
            epg_id = channel.get('channelIdentification', {}).get('name')
            channel_id = channel.get('channelIdentification', {}).get('stbUniqueName')
            logo = channel.get('channelProperties', {}).get('squareLogo')
            channels.append(dict(
                name=name,
                id=epg_id,
                logo=logo,
                stream=KodiWrapper.url_for('play_id', channel_id=channel_id),
            ))
        return channels
示例#3
0
    def list_channels_without_epg(self, is_folder=False):
        from kodiwrapper import KodiWrapper

        listing = []

        tv_channels = self.get_channels()

        for tv_channel in tv_channels:
            name = tv_channel.get('channelIdentification').get('name')
            square_logo = tv_channel.get('channelProperties').get('squareLogo')
            channel_id = tv_channel.get('channelIdentification').get('stbUniqueName')

            list_item = KodiWrapper.create_list_item(name, square_logo, "", {"plot": ""}, True, True)
            url = KodiWrapper.url_for('play_id', channel_id=channel_id)
            listing.append((url, list_item, is_folder))

        KodiWrapper.add_dir_items(listing)
        KodiWrapper.end_directory()