Exemplo n.º 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()
Exemplo n.º 2
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()