Пример #1
0
    def get_epg_data(self):
        """Return EPG data"""
        now = datetime.now(dateutil.tz.tzlocal())

        epg_data = {}
        for date in ['yesterday', 'today', 'tomorrow']:
            epg = self.parse(date, now)
            epg_url = epg.strftime(self.VRT_TVGUIDE)
            schedule = get_url_json(url=epg_url, fail={})
            for channel_id, episodes in list(schedule.items()):
                channel = find_entry(CHANNELS, 'id', channel_id)
                epg_id = channel.get('epg_id')
                if epg_id not in epg_data:
                    epg_data[epg_id] = []
                for episode in episodes:
                    if episode.get('url') and episode.get('vrt.whatson-id'):
                        path = url_for(
                            'play_whatson_id',
                            whatson_id=episode.get('vrt.whatson-id'))
                    else:
                        path = None
                    epg_data[epg_id].append(
                        dict(
                            start=episode.get('startTime'),
                            stop=episode.get('endTime'),
                            image=add_https_proto(episode.get('image', '')),
                            title=episode.get('title'),
                            subtitle=html_to_kodi(episode.get('subtitle', '')),
                            description=html_to_kodi(
                                episode.get('description', '')),
                            stream=path,
                        ))
        return epg_data
Пример #2
0
    def get_episode_items(self, date, channel):
        """Show episodes for a given date and channel"""
        now = datetime.now(dateutil.tz.tzlocal())
        epg = self.parse(date, now)
        epg_url = epg.strftime(self.VRT_TVGUIDE)

        self._favorites.refresh(ttl=ttl('indirect'))
        self._resumepoints.refresh(ttl=ttl('indirect'))

        cache_file = 'schedule.{date}.json'.format(date=date)
        if date in ('today', 'yesterday', 'tomorrow'):
            schedule = get_cached_url_json(url=epg_url,
                                           cache=cache_file,
                                           ttl=ttl('indirect'),
                                           fail={})
        else:
            schedule = get_url_json(url=epg_url, fail={})

        entry = find_entry(CHANNELS, 'name', channel)
        if entry:
            episodes = schedule.get(entry.get('id'), [])
        else:
            episodes = []
        episode_items = []
        for episode in episodes:
            program = url_to_program(episode.get('url', ''))
            if episode.get('url'):
                video_url = add_https_proto(episode.get('url'))
                path = url_for('play_url', video_url=video_url)
                context_menu, favorite_marker, watchlater_marker = self._metadata.get_context_menu(
                    episode, program, cache_file)
                label = self._metadata.get_label(
                    episode) + favorite_marker + watchlater_marker
                is_playable = True
            else:
                label = '[COLOR={greyedout}]%s[/COLOR]' % self._metadata.get_label(
                    episode)
                path = url_for('noop')
                context_menu, _, _ = self._metadata.get_context_menu(
                    episode, program, cache_file)
                is_playable = False

            info_labels = self._metadata.get_info_labels(episode,
                                                         date=date,
                                                         channel=entry)
            # FIXME: Due to a bug in Kodi, ListItem.Title is used when Sort methods are used, not ListItem.Label
            info_labels['title'] = colour(label)

            episode_items.append(
                TitleItem(
                    label=colour(label),
                    path=path,
                    art_dict=self._metadata.get_art(episode),
                    info_dict=info_labels,
                    context_menu=context_menu,
                    is_playable=is_playable,
                ))
        return episode_items
Пример #3
0
 def get_online_categories():
     """Return a list of categories from the VRT NU website"""
     categories = []
     categories_json = get_url_json(
         'https://www.vrt.be/vrtnu/categorieen/jcr:content/par/categories.model.json'
     )
     if categories_json is not None:
         categories = []
         for category in categories_json.get('items'):
             categories.append(
                 dict(
                     id=category.get('name'),
                     thumbnail=add_https_proto(
                         category.get('image').get('src')),
                     name=category.get('title'),
                 ))
     return categories
    def get_asset_id(api_data):
        """Get asset_id from single item json api data"""
        asset_id = None

        # VRT NU Search API
        if api_data.get('type') == 'episode':
            asset_id = assetpath_to_id(api_data.get('assetPath'))

        # VRT NU Schedule API (some are missing vrt.whatson-id)
        elif api_data.get('vrt.whatson-id') or api_data.get('startTime'):
            asset_id = assetpath_to_id(api_data.get('assetPath'))

        # Fallback to VRT NU website scraping
        if not asset_id and api_data.get('url'):
            from webscraper import get_asset_id
            asset_id = get_asset_id(add_https_proto(api_data.get('url')))

        return asset_id
Пример #5
0
def get_category_thumbnail(element):
    """Return a category thumbnail, if available"""
    if get_setting_bool('showfanart', default=True):
        raw_thumbnail = element.find(class_='media').get('data-responsive-image', 'DefaultGenre.png')
        return add_https_proto(raw_thumbnail)
    return 'DefaultGenre.png'
    def get_art(api_data, season=False):
        """Get art dict from single item json api data"""
        art_dict = {}

        # VRT NU Search API
        if api_data.get('type') == 'episode':
            if season is not False:
                if get_setting_bool('showfanart', default=True):
                    art_dict['fanart'] = add_https_proto(
                        api_data.get('programImageUrl', 'DefaultSets.png'))
                    if season != 'allseasons':
                        art_dict['thumb'] = add_https_proto(
                            api_data.get('videoThumbnailUrl',
                                         art_dict.get('fanart')))
                    else:
                        art_dict['thumb'] = art_dict.get('fanart')
                    art_dict['banner'] = art_dict.get('fanart')
                    if api_data.get('programAlternativeImageUrl'):
                        art_dict['cover'] = add_https_proto(
                            api_data.get('programAlternativeImageUrl'))
                        art_dict['poster'] = add_https_proto(
                            api_data.get('programAlternativeImageUrl'))
                else:
                    art_dict['thumb'] = 'DefaultSets.png'
            else:
                if get_setting_bool('showfanart', default=True):
                    art_dict['thumb'] = add_https_proto(
                        api_data.get('videoThumbnailUrl',
                                     'DefaultAddonVideo.png'))
                    art_dict['fanart'] = add_https_proto(
                        api_data.get('programImageUrl', art_dict.get('thumb')))
                    art_dict['banner'] = art_dict.get('fanart')
                    if api_data.get('programAlternativeImageUrl'):
                        art_dict['cover'] = add_https_proto(
                            api_data.get('programAlternativeImageUrl'))
                        art_dict['poster'] = add_https_proto(
                            api_data.get('programAlternativeImageUrl'))
                else:
                    art_dict['thumb'] = 'DefaultAddonVideo.png'

            return art_dict

        # VRT NU Suggest API
        if api_data.get('type') == 'program':
            if get_setting_bool('showfanart', default=True):
                art_dict['thumb'] = add_https_proto(
                    api_data.get('thumbnail', 'DefaultAddonVideo.png'))
                art_dict['fanart'] = art_dict.get('thumb')
                art_dict['banner'] = art_dict.get('fanart')
                if api_data.get('alternativeImage'):
                    art_dict['cover'] = add_https_proto(
                        api_data.get('alternativeImage'))
                    art_dict['poster'] = add_https_proto(
                        api_data.get('alternativeImage'))
            else:
                art_dict['thumb'] = 'DefaultAddonVideo.png'

            return art_dict

        # VRT NU Schedule API (some are missing vrt.whatson-id)
        if api_data.get('vrt.whatson-id') or api_data.get('startTime'):
            if get_setting_bool('showfanart', default=True):
                art_dict['thumb'] = add_https_proto(
                    api_data.get('image', 'DefaultAddonVideo.png'))
                art_dict['fanart'] = art_dict.get('thumb')
                art_dict['banner'] = art_dict.get('fanart')
            else:
                art_dict['thumb'] = 'DefaultAddonVideo.png'

            return art_dict

        # Not Found
        return art_dict