예제 #1
0
 def get_tvshow_items(self, path=None):
     if path:
         api_url = self._VRTNU_SUGGEST_URL + '?facets[categories]=' + path
     else:
         # If no path is provided, we return the A-Z listing
         api_url = self._VRTNU_SUGGEST_URL + '?facets[transcodingStatus]=AVAILABLE'
     tvshows = requests.get(api_url, proxies=self._proxies).json()
     tvshow_items = []
     for tvshow in tvshows:
         metadata = metadatacreator.MetadataCreator()
         metadata.mediatype = 'tvshow'
         metadata.tvshowtitle = tvshow.get('title', '???')
         metadata.plot = statichelper.unescape(tvshow.get('description', '???'))
         metadata.brands = tvshow.get('brands')
         metadata.permalink = statichelper.shorten_link(tvshow.get('targetUrl'))
         # NOTE: This adds episode_count to title, would be better as metadata
         # title = '%s  [LIGHT][COLOR yellow]%s[/COLOR][/LIGHT]' % (tvshow.get('title', '???'), tvshow.get('episode_count', '?'))
         title = tvshow.get('title', '???')
         thumbnail = statichelper.add_https_method(tvshow.get('thumbnail', 'DefaultAddonVideo.png'))
         # Cut vrtbase url off since it will be added again when searching for episodes
         # (with a-z we dont have the full url)
         video_url = statichelper.add_https_method(tvshow.get('targetUrl')).replace(self._VRT_BASE, '')
         tvshow_items.append(helperobjects.TitleItem(title=title,
                                                     url_dict=dict(action=actions.LISTING_EPISODES, video_url=video_url),
                                                     is_playable=False,
                                                     art_dict=dict(thumb=thumbnail, icon='DefaultAddonVideo.png', fanart=thumbnail),
                                                     video_dict=metadata.get_video_dict()))
     return tvshow_items
예제 #2
0
    def show_video_category_episodes(self, path):
        category = path.split('/')[-2]
        joined_url = self._VRTNU_SEARCH_URL + category
        response = requests.get(joined_url)
        programs = response.json()
        menu_items = []
        for program in programs:
            title = program['title']
            plot = BeautifulSoup(program['description'], 'html.parser').text
            thumbnail = statichelper.replace_double_slashes_with_https(
                program['thumbnail'])

            metadata_creator = metadatacreator.MetadataCreator()
            metadata_creator.plot = plot
            video_dictionary = metadata_creator.get_video_dictionary()
            #cut vrtbase url off since it will be added again when searching for episodes (with a-z we dont have the
            #  full url)
            link_to_video = statichelper.replace_double_slashes_with_https(
                program['targetUrl']).replace(self._VRT_BASE, '')
            item = helperobjects.TitleItem(title, {
                'action': actions.LISTING_VIDEOS,
                'video': link_to_video
            }, False, thumbnail, video_dictionary)
            menu_items.append(item)
        self._kodi_wrapper.show_listing(menu_items, sortmethod.ALPHABET)
예제 #3
0
    def _map_to_season_items(self, api_url, seasons, episode):
        season_items = []
        sort = 'label'
        ascending = True

        fanart = statichelper.add_https_method(episode.get('programImageUrl', 'DefaultSets.png'))
        program_type = episode.get('programType')
        metadata = metadatacreator.MetadataCreator()
        metadata.mediatype = 'season'
        metadata.brands = episode.get('programBrands') or episode.get('brands')

        # Reverse sort seasons if program_type is 'reeksaflopend' or 'daily'
        if program_type in ('daily', 'reeksaflopend'):
            ascending = False

        # NOTE: Sort the episodes ourselves, because Kodi does not allow to set to 'ascending'
        seasons = sorted(seasons, key=lambda k: k['key'], reverse=not ascending)

        for season in seasons:
            season_key = season.get('key')
            title = '%s %s' % (self._kodi_wrapper.get_localized_string(32094), season_key)
            season_facet = '&facets[seasonTitle]='
            path = api_url + season_facet + season_key
            season_items.append(helperobjects.TitleItem(
                title=title,
                url_dict=dict(action=actions.LISTING_EPISODES, video_url=path),
                is_playable=False,
                art_dict=dict(thumb=fanart, icon='DefaultSets.png', fanart=fanart),
                video_dict=metadata.get_video_dict(),
            ))
        return season_items, sort, ascending
 def get_az_metadata(tile):
     metadata_creator = metadatacreator.MetadataCreator()
     description = ""
     description_item = tile.find(class_="tile__description")
     if description_item is not None:
         p_item = description_item.find("p")
         if p_item is not None:
             description = p_item.text.strip()
     metadata_creator.plot = description
     return metadata_creator.get_video_dictionary()
 def get_az_metadata(tile):
     metadata_creator = metadatacreator.MetadataCreator()
     description = ''
     description_item = tile.find(class_='nui-tile--content')
     if description_item is not None:
         p_item = description_item.find('p')
         if p_item is not None:
             description = p_item.text.strip()
     metadata_creator.plot = description
     return metadata_creator.get_video_dictionary()
예제 #6
0
    def show_tvguide(self, params):
        date = params.get('date')
        channel = params.get('channel')

        if not date:
            today = datetime.today()
            date_items = []
            for i in range(7, -31, -1):
                day = today + timedelta(days=i)
                title = day.strftime(
                    self._kodi_wrapper.get_localized_datelong())
                if str(i) in DATE_STRINGS:
                    if i == 0:
                        title = '[COLOR yellow][B]%s[/B], %s[/COLOR]' % (
                            self._kodi_wrapper.get_localized_string(
                                DATE_STRINGS[str(i)]), title)
                    else:
                        title = '[B]%s[/B], %s' % (
                            self._kodi_wrapper.get_localized_string(
                                DATE_STRINGS[str(i)]), title)
                date_items.append(
                    helperobjects.TitleItem(
                        title=title,
                        url_dict=dict(action=actions.LISTING_TVGUIDE,
                                      date=day.strftime('%Y-%m-%d')),
                        is_playable=False,
                        art_dict=dict(thumb='DefaultYear.png',
                                      icon='DefaultYear.png',
                                      fanart='DefaultYear.png'),
                        video_dict=dict(plot=day.strftime(
                            self._kodi_wrapper.get_localized_datelong()))), )
            self._kodi_wrapper.show_listing(date_items,
                                            sort='unsorted',
                                            content_type='files')

        elif not channel:
            dateobj = statichelper.strptime(date, '%Y-%m-%d')
            datelong = dateobj.strftime(
                self._kodi_wrapper.get_localized_datelong())
            channel_items = []
            for channel in ('een', 'canvas', 'ketnet'):
                plot = self._kodi_wrapper.get_localized_string(
                    32301) % CHANNELS[channel]['name'] + '\n' + datelong
                channel_items.append(
                    helperobjects.TitleItem(
                        title=CHANNELS[channel]['name'],
                        url_dict=dict(action=actions.LISTING_TVGUIDE,
                                      date=date,
                                      channel=channel),
                        is_playable=False,
                        art_dict=dict(thumb=self.__get_media(channel + '.png'),
                                      icon='DefaultAddonPVRClient.png',
                                      fanart='DefaultAddonPVRClient.png'),
                        video_dict=dict(plot=plot),
                    ), )
            self._kodi_wrapper.show_listing(channel_items,
                                            content_type='files')

        else:
            dateobj = statichelper.strptime(date, '%Y-%m-%d')
            datelong = dateobj.strftime(
                self._kodi_wrapper.get_localized_datelong())
            api_url = dateobj.strftime(self.VRT_TVGUIDE)
            schedule = requests.get(api_url, proxies=self._proxies).json()
            episodes = schedule[CHANNELS[channel]['id']]
            episode_items = []
            for episode in episodes:
                metadata = metadatacreator.MetadataCreator()
                title = episode.get('title')
                start = episode.get('start')
                end = episode.get('end')
                url = episode.get('url')
                metadata.title = '%s - %s' % (start, title)
                metadata.tvshowtitle = title
                metadata.datetime = dateobj
                metadata.duration = (
                    statichelper.strptime(end, '%H:%M') -
                    statichelper.strptime(start, '%H:%M')).total_seconds()
                metadata.plot = '[B]%s[/B]\n%s\n%s - %s\n[I]%s[/I]' % (
                    title, datelong, start, end, CHANNELS[channel]['name'])
                metadata.brands = [channel]
                metadata.mediatype = 'episode'
                thumb = episode.get('image', 'DefaultAddonVideo.png')
                metadata.icon = thumb
                if url:
                    video_url = statichelper.add_https_method(url)
                    url_dict = dict(action=actions.PLAY, video_url=video_url)
                else:
                    # FIXME: Find a better solution for non-actionable items
                    url_dict = dict(action=actions.LISTING_TVGUIDE,
                                    date=date,
                                    channel=channel)
                    metadata.title = '[COLOR gray]%s[/COLOR]' % metadata.title
                    title = '[COLOR gray]%s[/COLOR]' % metadata.title
                episode_items.append(
                    helperobjects.TitleItem(
                        title=title,
                        url_dict=url_dict,
                        is_playable=bool(url),
                        art_dict=dict(thumb=thumb,
                                      icon='DefaultAddonVideo.png',
                                      fanart=thumb),
                        video_dict=metadata.get_video_dict(),
                    ))
            self._kodi_wrapper.show_listing(episode_items,
                                            sort='unsorted',
                                            content_type='episodes')
 def get_multiple_layout_episode_metadata(self, soup):
     metadata_creator = metadatacreator.MetadataCreator()
     metadata_creator.duration = self.__get_multiple_layout_episode_duration(
         soup)
     return metadata_creator.get_video_dictionary()
 def get_single_layout_episode_metadata(self, soup):
     metadata_creator = metadatacreator.MetadataCreator()
     metadata_creator.duration = self.__get_episode_duration(soup)
     metadata_creator.plot = self.get_plot(soup)
     metadata_creator.datetime = self.get_broadcast_datetime(soup)
     return metadata_creator.get_video_dictionary()
예제 #9
0
    def _map_to_episode_items(self, episodes, titletype=None, season_key=None):
        episode_items = []
        sort = 'episode'
        ascending = True
        for episode in episodes:
            # VRT API workaround: seasonTitle facet behaves as a partial match regex,
            # so we have to filter out the episodes from seasons that don't exactly match.
            if season_key and episode.get('seasonTitle') != season_key:
                continue

            display_options = episode.get('displayOptions', dict())

            # NOTE: Hard-code showing seasons because it is unreliable (i.e; Thuis or Down the Road have it disabled)
            display_options['showSeason'] = True

            if titletype is None:
                titletype = episode.get('programType')

            metadata = metadatacreator.MetadataCreator()
            metadata.tvshowtitle = episode.get('program')
            if episode.get('broadcastDate') != -1:
                metadata.datetime = datetime.fromtimestamp(episode.get('broadcastDate', 0) / 1000)

            metadata.duration = (episode.get('duration', 0) * 60)  # Minutes to seconds
            metadata.plot = statichelper.convert_html_to_kodilabel(episode.get('description'))
            metadata.brands = episode.get('programBrands') or episode.get('brands')
            metadata.geolocked = episode.get('allowedRegion') == 'BE'
            if display_options.get('showShortDescription'):
                short_description = statichelper.convert_html_to_kodilabel(episode.get('shortDescription'))
                metadata.plotoutline = short_description
                metadata.subtitle = short_description
            else:
                metadata.plotoutline = episode.get('subtitle')
                metadata.subtitle = episode.get('subtitle')
            metadata.season = episode.get('seasonName')
            metadata.episode = episode.get('episodeNumber')
            metadata.mediatype = episode.get('type', 'episode')
            metadata.permalink = statichelper.shorten_link(episode.get('permalink')) or episode.get('externalPermalink')
            if episode.get('assetOnTime'):
                metadata.ontime = statichelper.strptime(episode.get('assetOnTime'), '%Y-%m-%dT%H:%M:%S+0000')
            if episode.get('assetOffTime'):
                metadata.offtime = statichelper.strptime(episode.get('assetOffTime'), '%Y-%m-%dT%H:%M:%S+0000')

            # Add additional metadata to plot
            plot_meta = ''
            if metadata.geolocked:
                # Show Geo-locked
                plot_meta += self._kodi_wrapper.get_localized_string(32201)
            # Only display when a video disappears if it is within the next 3 months
            if metadata.offtime is not None and (metadata.offtime - datetime.utcnow()).days < 93:
                # Show date when episode is removed
                plot_meta += self._kodi_wrapper.get_localized_string(32202) % metadata.offtime.strftime(self._kodi_wrapper.get_localized_dateshort())
                # Show the remaining days/hours the episode is still available
                if (metadata.offtime - datetime.utcnow()).days > 0:
                    plot_meta += self._kodi_wrapper.get_localized_string(32203) % (metadata.offtime - datetime.utcnow()).days
                else:
                    plot_meta += self._kodi_wrapper.get_localized_string(32204) % int((metadata.offtime - datetime.utcnow()).seconds / 3600)
            if plot_meta:
                metadata.plot = '%s\n%s' % (plot_meta, metadata.plot)

            if self._showpermalink and metadata.permalink:
                metadata.plot = '%s\n\n[COLOR yellow]%s[/COLOR]' % (metadata.plot, metadata.permalink)

            thumb = statichelper.add_https_method(episode.get('videoThumbnailUrl', 'DefaultAddonVideo.png'))
            fanart = statichelper.add_https_method(episode.get('programImageUrl', thumb))
            video_url = statichelper.add_https_method(episode.get('url'))
            title, sort, ascending = self._make_title(episode, titletype, options=display_options)
            metadata.title = title
            episode_items.append(helperobjects.TitleItem(
                title=title,
                url_dict=dict(action=actions.PLAY, video_url=video_url, video_id=episode.get('videoId'), publication_id=episode.get('publicationId')),
                is_playable=True,
                art_dict=dict(thumb=thumb, icon='DefaultAddonVideo.png', fanart=fanart),
                video_dict=metadata.get_video_dict(),
            ))
        return episode_items, sort, ascending