def show_favorites_menu_items(self):
        ''' The VRT NU addon 'My Programs' menu '''
        self._favorites.get_favorites(ttl=60 * 60)
        favorites_items = [
            TitleItem(
                title=self._kodi.localize(30040),  # My A-Z listing
                path=self._kodi.url_for('favorites_programs'),
                art_dict=dict(thumb='DefaultMovieTitle.png',
                              fanart='DefaultMovieTitle.png'),
                info_dict=dict(plot=self._kodi.localize(30041))),
            TitleItem(
                title=self._kodi.localize(30046),  # My recent items
                path=self._kodi.url_for('favorites_recent'),
                art_dict=dict(thumb='DefaultRecentlyAddedEpisodes.png',
                              fanart='DefaultRecentlyAddedEpisodes.png'),
                info_dict=dict(plot=self._kodi.localize(30047))),
            TitleItem(
                title=self._kodi.localize(30048),  # My soon offline
                path=self._kodi.url_for('favorites_offline'),
                art_dict=dict(thumb='DefaultYear.png',
                              fanart='DefaultYear.png'),
                info_dict=dict(plot=self._kodi.localize(30049))),
        ]

        if self._kodi.get_setting('addmymovies', 'true') == 'true':
            favorites_items.append(
                TitleItem(
                    title=self._kodi.localize(30042),  # My movies
                    path=self._kodi.url_for('categories', category='films'),
                    art_dict=dict(thumb='DefaultAddonVideo.png',
                                  fanart='DefaultAddonVideo.png'),
                    info_dict=dict(plot=self._kodi.localize(30043))), )

        if self._kodi.get_setting('addmydocu', 'true') == 'true':
            favorites_items.append(
                TitleItem(
                    title=self._kodi.localize(30044),  # My documentaries
                    path=self._kodi.url_for('favorites_docu'),
                    art_dict=dict(thumb='DefaultMovies.png',
                                  fanart='DefaultMovies.png'),
                    info_dict=dict(plot=self._kodi.localize(30045))), )

        self._kodi.show_listing(favorites_items)

        # Show dialog when no favorites were found
        if not self._favorites.titles():
            self._kodi.show_ok_dialog(heading=self._kodi.localize(30415),
                                      message=self._kodi.localize(30416))
 def tvshow_to_listitem(self, tvshow, program, cache_file):
     ''' Return a ListItem based on a Suggests API result '''
     metadata = metadatacreator.MetadataCreator()
     metadata.tvshowtitle = tvshow.get('title', '???')
     metadata.plot = statichelper.unescape(tvshow.get('description', '???'))
     metadata.brands.extend(tvshow.get('brands', []))
     metadata.permalink = statichelper.shorten_link(tvshow.get('targetUrl'))
     # NOTE: This adds episode_count to label, would be better as metadata
     # title = '%s  [LIGHT][COLOR yellow]%s[/COLOR][/LIGHT]' % (tvshow.get('title', '???'), tvshow.get('episode_count', '?'))
     label = tvshow.get('title', '???')
     if self._showfanart:
         thumbnail = statichelper.add_https_method(tvshow.get('thumbnail', 'DefaultAddonVideo.png'))
     else:
         thumbnail = 'DefaultAddonVideo.png'
     if self._favorites.is_activated():
         program_title = quote(tvshow.get('title'), '')  # We need to ensure forward slashes are quoted
         if self._favorites.is_favorite(program):
             context_menu = [(self._kodi.localize(30412), 'RunPlugin(%s)' % self._kodi.url_for('unfollow', program=program, title=program_title))]
             label += ' [COLOR yellow]°[/COLOR]'
         else:
             context_menu = [(self._kodi.localize(30411), 'RunPlugin(%s)' % self._kodi.url_for('follow', program=program, title=program_title))]
     else:
         context_menu = []
     context_menu.append((self._kodi.localize(30413), 'RunPlugin(%s)' % self._kodi.url_for('delete_cache', cache_file=cache_file)))
     return TitleItem(
         title=label,
         path=self._kodi.url_for('programs', program=program),
         art_dict=dict(thumb=thumbnail, icon='DefaultAddonVideo.png', fanart=thumbnail),
         info_dict=metadata.get_info_dict(),
         context_menu=context_menu,
     )
    def show_offline(self, page=0, use_favorites=False):
        ''' The VRT NU add-on 'Soon offline' and 'My soon offline' listing menu '''
        # My programs menus may need more up-to-date favorites
        self._favorites.get_favorites(ttl=5 * 60 if use_favorites else 60 * 60)
        page = realpage(page)
        episode_items, sort, ascending, content = self._apihelper.get_episode_items(
            page=page, use_favorites=use_favorites, variety='offline')

        # Add 'More...' entry at the end
        if len(episode_items) == 50:
            if use_favorites:
                offline = 'favorites_offline'
            else:
                offline = 'offline'
            episode_items.append(
                TitleItem(
                    title=self._kodi.localize(30300),
                    path=self._kodi.url_for(offline, page=page + 1),
                    art_dict=dict(thumb='DefaultYear.png',
                                  fanart='DefaultYear.png'),
                    info_dict=dict(),
                ))

        self._kodi.show_listing(episode_items,
                                sort=sort,
                                ascending=ascending,
                                content=content)
Exemplo n.º 4
0
    def show_channel_menu(self, date):
        ''' Offer a menu to select the channel '''
        now = datetime.now(dateutil.tz.tzlocal())
        epg = self.parse(date, now)
        datelong = self._kodi.localize_datelong(epg)

        channel_items = []
        for channel in CHANNELS:
            if channel.get('name') not in ('een', 'canvas', 'ketnet'):
                continue

            fanart = 'resource://resource.images.studios.coloured/%(studio)s.png' % channel
            thumb = 'resource://resource.images.studios.white/%(studio)s.png' % channel
            plot = '%s\n%s' % (self._kodi.localize(30301).format(**channel),
                               datelong)
            channel_items.append(
                TitleItem(
                    title=channel.get('label'),
                    path=self._kodi.url_for('tvguide',
                                            date=date,
                                            channel=channel.get('name')),
                    art_dict=dict(thumb=thumb, fanart=fanart),
                    info_dict=dict(plot=plot, studio=channel.get('studio')),
                ))
        return channel_items
Exemplo n.º 5
0
    def search_menu(self):
        ''' Main search menu '''
        menu_items = [
            TitleItem(
                title=self._kodi.localize(30424),  # New search...
                path=self._kodi.url_for('search_query'),
                art_dict=dict(thumb='DefaultAddonsSearch.png',
                              fanart='DefaultAddonsSearch.png'),
                info_dict=dict(plot=self._kodi.localize(30425)),
                is_playable=False,
            )
        ]

        try:
            with self._kodi.open_file(self._search_history, 'r') as f:
                history = json.load(f)
        except Exception:
            history = []

        for keywords in history:
            menu_items.append(
                TitleItem(
                    title=keywords,
                    path=self._kodi.url_for('search_query', keywords=keywords),
                    art_dict=dict(thumb='DefaultAddonsSearch.png',
                                  fanart='DefaultAddonsSearch.png'),
                    is_playable=False,
                ))

        if history:
            menu_items.append(
                TitleItem(
                    title=self._kodi.localize(30426),  # Clear search history
                    path=self._kodi.url_for('clear_search'),
                    info_dict=dict(plot=self._kodi.localize(30427)),
                    art_dict=dict(thumb='icons/infodialogs/uninstall.png',
                                  fanart='icons/infodialogs/uninstall.png'),
                    is_playable=False,
                ))

        self._kodi.show_listing(menu_items)
    def get_channel_items(self, channels=None, live=True):
        ''' Construct a list of channel ListItems, either for Live TV or the TV Guide listing '''
        from resources.lib import tvguide
        _tvguide = tvguide.TVGuide(self._kodi)

        channel_items = []
        for channel in CHANNELS:
            if channels and channel.get('name') not in channels:
                continue

            fanart = 'resource://resource.images.studios.coloured/%(studio)s.png' % channel
            thumb = 'resource://resource.images.studios.white/%(studio)s.png' % channel

            if not live:
                path = self._kodi.url_for('channels', channel=channel.get('name'))
                label = channel.get('label')
                plot = '[B]%s[/B]' % channel.get('label')
                is_playable = False
                info_dict = dict(title=label, plot=plot, studio=channel.get('studio'), mediatype='video')
                context_menu = []
            elif channel.get('live_stream') or channel.get('live_stream_id'):
                if channel.get('live_stream_id'):
                    path = self._kodi.url_for('play_id', video_id=channel.get('live_stream_id'))
                elif channel.get('live_stream'):
                    path = self._kodi.url_for('play_url', video_url=channel.get('live_stream'))
                label = self._kodi.localize(30101).format(**channel)
                # A single Live channel means it is the entry for channel's TV Show listing, so make it stand out
                if channels and len(channels) == 1:
                    label = '[B]%s[/B]' % label
                is_playable = True
                if channel.get('name') in ['een', 'canvas', 'ketnet']:
                    if self._showfanart:
                        fanart = self.get_live_screenshot(channel.get('name', fanart))
                    plot = '%s\n\n%s' % (self._kodi.localize(30102).format(**channel), _tvguide.live_description(channel.get('name')))
                else:
                    plot = self._kodi.localize(30102).format(**channel)
                # NOTE: Playcount is required to not have live streams as "Watched"
                info_dict = dict(title=label, plot=plot, studio=channel.get('studio'), mediatype='video', playcount=0)
                context_menu = [(self._kodi.localize(30413), 'RunPlugin(%s)' % self._kodi.url_for('delete_cache', cache_file='channel.%s.json' % channel))]
            else:
                # Not a playable channel
                continue

            channel_items.append(TitleItem(
                title=label,
                path=path,
                art_dict=dict(thumb=thumb, fanart=fanart),
                info_dict=info_dict,
                context_menu=context_menu,
                is_playable=is_playable,
            ))

        return channel_items
    def get_featured_items(self):
        ''' Construct a list of featured Listitems '''
        from resources.lib import FEATURED

        featured_items = []
        for feature in FEATURED:
            featured_name = self._kodi.localize_from_data(feature.get('name'), FEATURED)
            featured_items.append(TitleItem(
                title=featured_name,
                path=self._kodi.url_for('featured', feature=feature.get('id')),
                art_dict=dict(thumb='DefaultCountry.png', fanart='DefaultCountry.png'),
                info_dict=dict(plot='[B]%s[/B]' % featured_name, studio='VRT'),
            ))
        return featured_items
Exemplo n.º 8
0
    def search(self, keywords=None, page=None):
        ''' The VRT NU add-on Search functionality and results '''
        if keywords is None:
            keywords = self._kodi.get_search_string()

        if not keywords:
            self._kodi.end_of_directory()
            return

        page = realpage(page)

        self.add(keywords)
        search_items, sort, ascending, content = self._apihelper.get_search_items(
            keywords, page=page)
        if not search_items:
            self._kodi.show_ok_dialog(
                heading=self._kodi.localize(30098),
                message=self._kodi.localize(30099).format(keywords=keywords))
            self._kodi.end_of_directory()
            return

        # Add 'More...' entry at the end
        if len(search_items) == 50:
            search_items.append(
                TitleItem(
                    title=self._kodi.localize(30300),
                    path=self._kodi.url_for('search',
                                            keywords=keywords,
                                            page=page + 1),
                    art_dict=dict(thumb='DefaultAddonSearch.png',
                                  fanart='DefaultAddonSearch.png'),
                    info_dict=dict(),
                ))

        self._kodi.container_update(replace=True)

        self._favorites.get_favorites(ttl=60 * 60)
        self._kodi.show_listing(search_items,
                                sort=sort,
                                ascending=ascending,
                                content=content,
                                cache=False)
Exemplo n.º 9
0
    def show_date_menu(self):
        ''' Offer a menu to select the TV-guide date '''
        epg = datetime.now(dateutil.tz.tzlocal())
        # Daily EPG information shows information from 6AM until 6AM
        if epg.hour < 6:
            epg += timedelta(days=-1)
        date_items = []
        for i in range(7, -30, -1):
            day = epg + timedelta(days=i)
            title = self._kodi.localize_datelong(day)

            # Highlight today with context of 2 days
            if str(i) in DATE_STRINGS:
                if i == 0:
                    title = '[COLOR yellow][B]%s[/B], %s[/COLOR]' % (
                        self._kodi.localize(DATE_STRINGS[str(i)]), title)
                else:
                    title = '[B]%s[/B], %s' % (self._kodi.localize(
                        DATE_STRINGS[str(i)]), title)

            # Make permalinks for today, yesterday and tomorrow
            if str(i) in DATES:
                date = DATES[str(i)]
            else:
                date = day.strftime('%Y-%m-%d')
            cache_file = 'schedule.%s.json' % date
            date_items.append(
                TitleItem(
                    title=title,
                    path=self._kodi.url_for('tvguide', date=date),
                    art_dict=dict(thumb='DefaultYear.png',
                                  fanart='DefaultYear.png'),
                    info_dict=dict(plot=self._kodi.localize_datelong(day)),
                    context_menu=[(self._kodi.localize(30413),
                                   'RunPlugin(%s)' % self._kodi.url_for(
                                       'delete_cache', cache_file=cache_file))
                                  ],
                ))
        return date_items
    def get_category_items(self):
        ''' Construct a list of category ListItems '''
        categories = []

        # Try the cache if it is fresh
        categories = self._kodi.get_cache('categories.json', ttl=7 * 24 * 60 * 60)

        # Try to scrape from the web
        if not categories:
            try:
                categories = self.get_categories(self._proxies)
            except Exception:
                categories = []
            else:
                self._kodi.update_cache('categories.json', categories)

        # Use the cache anyway (better than hard-coded)
        if not categories:
            categories = self._kodi.get_cache('categories.json', ttl=None)

        # Fall back to internal hard-coded categories if all else fails
        if not categories:
            categories = CATEGORIES

        category_items = []
        for category in categories:
            if self._showfanart:
                thumbnail = category.get('thumbnail', 'DefaultGenre.png')
            else:
                thumbnail = 'DefaultGenre.png'
            category_name = self._kodi.localize_from_data(category.get('name'), CATEGORIES)
            category_items.append(TitleItem(
                title=category_name,
                path=self._kodi.url_for('categories', category=category.get('id')),
                art_dict=dict(thumb=thumbnail, icon='DefaultGenre.png', fanart=thumbnail),
                info_dict=dict(plot='[B]%s[/B]' % category_name, studio='VRT'),
            ))
        return category_items
    def _map_to_season_items(self, program, seasons, episodes):
        ''' Construct a list of TV show season TitleItems based on Search API query and filtered by favorites '''
        import random

        season_items = []
        sort = 'label'
        ascending = True

        episode = random.choice(episodes)
        program_type = episode.get('programType')
        if self._showfanart:
            fanart = statichelper.add_https_method(episode.get('programImageUrl', 'DefaultSets.png'))
        else:
            fanart = 'DefaultSets.png'

        metadata = metadatacreator.MetadataCreator()
        metadata.tvshowtitle = episode.get('program')
        metadata.plot = statichelper.convert_html_to_kodilabel(episode.get('programDescription'))
        metadata.plotoutline = statichelper.convert_html_to_kodilabel(episode.get('programDescription'))
        metadata.brands.extend(episode.get('programBrands', []) or episode.get('brands', []))
        metadata.geolocked = episode.get('allowedRegion') == 'BE'
        metadata.season = episode.get('seasonTitle')

        # Add additional metadata to plot
        plot_meta = ''
        if metadata.geolocked:
            # Show Geo-locked
            plot_meta += self._kodi.localize(30201) + '\n'
        metadata.plot = '%s[B]%s[/B]\n%s' % (plot_meta, episode.get('program'), metadata.plot)

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

        # Add an "* All seasons" list item
        if self._kodi.get_global_setting('videolibrary.showallitems') is True:
            season_items.append(TitleItem(
                title=self._kodi.localize(30096),
                path=self._kodi.url_for('programs', program=program, season='allseasons'),
                art_dict=dict(thumb=fanart, icon='DefaultSets.png', fanart=fanart),
                info_dict=metadata.get_info_dict(),
            ))

        # 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', '')
            try:
                # If more than 300 episodes exist, we may end up with an empty season (Winteruur)
                episode = random.choice([e for e in episodes if e.get('seasonName') == season_key])
            except IndexError:
                episode = episodes[0]
            if self._showfanart:
                fanart = statichelper.add_https_method(episode.get('programImageUrl', 'DefaultSets.png'))
                thumbnail = statichelper.add_https_method(episode.get('videoThumbnailUrl', fanart))
            else:
                fanart = 'DefaultSets.png'
                thumbnail = 'DefaultSets.png'
            label = '%s %s' % (self._kodi.localize(30094), season_key)
            season_items.append(TitleItem(
                title=label,
                path=self._kodi.url_for('programs', program=program, season=season_key),
                art_dict=dict(thumb=thumbnail, icon='DefaultSets.png', fanart=fanart),
                info_dict=metadata.get_info_dict(),
            ))
        return season_items, sort, ascending, 'seasons'
    def episode_to_listitem(self, episode, program, cache_file, titletype):
        ''' Return a ListItem based on a Search API result '''
        from datetime import datetime
        import dateutil.parser
        import dateutil.tz
        now = datetime.now(dateutil.tz.tzlocal())

        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, dateutil.tz.UTC)

        metadata.duration = (episode.get('duration', 0) * 60)  # Minutes to seconds
        metadata.plot = statichelper.convert_html_to_kodilabel(episode.get('description'))
        metadata.brands.extend(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('seasonTitle')
        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 = dateutil.parser.parse(episode.get('assetOnTime'))
        if episode.get('assetOffTime'):
            metadata.offtime = dateutil.parser.parse(episode.get('assetOffTime'))

        # Add additional metadata to plot
        plot_meta = ''
        if metadata.geolocked:
            # Show Geo-locked
            plot_meta += self._kodi.localize(30201)

        # Only display when a video disappears if it is within the next 3 months
        if metadata.offtime is not None and (metadata.offtime - now).days < 93:
            # Show date when episode is removed
            plot_meta += self._kodi.localize(30202).format(date=self._kodi.localize_dateshort(metadata.offtime))
            # Show the remaining days/hours the episode is still available
            if (metadata.offtime - now).days > 0:
                plot_meta += self._kodi.localize(30203).format(days=(metadata.offtime - now).days)
            else:
                plot_meta += self._kodi.localize(30204).format(hours=int((metadata.offtime - now).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)

        label, sort, ascending = self._make_label(episode, titletype, options=display_options)
        if self._favorites.is_activated():
            program_title = quote(episode.get('program'), '')  # We need to ensure forward slashes are quoted
            if self._favorites.is_favorite(program):
                context_menu = [(self._kodi.localize(30412), 'RunPlugin(%s)' % self._kodi.url_for('unfollow', program=program, title=program_title))]
                label += ' [COLOR yellow]°[/COLOR]'
            else:
                context_menu = [(self._kodi.localize(30411), 'RunPlugin(%s)' % self._kodi.url_for('follow', program=program, title=program_title))]
        else:
            context_menu = []
        context_menu.append((self._kodi.localize(30413), 'RunPlugin(%s)' % self._kodi.url_for('delete_cache', cache_file=cache_file)))

        if self._showfanart:
            thumb = statichelper.add_https_method(episode.get('videoThumbnailUrl', 'DefaultAddonVideo.png'))
            fanart = statichelper.add_https_method(episode.get('programImageUrl', thumb))
        else:
            thumb = 'DefaultAddonVideo.png'
            fanart = 'DefaultAddonVideo.png'
        metadata.title = label

        return TitleItem(
            title=label,
            path=self._kodi.url_for('play_id', video_id=episode.get('videoId'), publication_id=episode.get('publicationId')),
            art_dict=dict(thumb=thumb, icon='DefaultAddonVideo.png', fanart=fanart),
            info_dict=metadata.get_info_dict(),
            context_menu=context_menu,
            is_playable=True,
        ), sort, ascending
Exemplo n.º 13
0
    def show_main_menu_items(self):
        ''' The VRT NU add-on main menu '''
        self._favorites.get_favorites(ttl=60 * 60)
        main_items = []

        # Only add 'My programs' when it has been activated
        if self._favorites.is_activated():
            main_items.append(
                TitleItem(
                    title=self._kodi.localize(30010),  # My programs
                    path=self._kodi.url_for('favorites_menu'),
                    art_dict=dict(thumb='icons/settings/profiles.png',
                                  fanart='icons/settings/profiles.png'),
                    info_dict=dict(plot=self._kodi.localize(30011))))

        main_items.extend([
            TitleItem(
                title=self._kodi.localize(30012),  # A-Z listing
                path=self._kodi.url_for('programs'),
                art_dict=dict(thumb='DefaultMovieTitle.png',
                              fanart='DefaultMovieTitle.png'),
                info_dict=dict(plot=self._kodi.localize(30013))),
            TitleItem(
                title=self._kodi.localize(30014),  # Categories
                path=self._kodi.url_for('categories'),
                art_dict=dict(thumb='DefaultGenre.png',
                              fanart='DefaultGenre.png'),
                info_dict=dict(plot=self._kodi.localize(30015))),
            TitleItem(
                title=self._kodi.localize(30016),  # Channels
                path=self._kodi.url_for('channels'),
                art_dict=dict(thumb='DefaultTags.png',
                              fanart='DefaultTags.png'),
                info_dict=dict(plot=self._kodi.localize(30017))),
            TitleItem(
                title=self._kodi.localize(30018),  # Live TV
                path=self._kodi.url_for('livetv'),
                # art_dict=dict(thumb='DefaultAddonPVRClient.png', fanart='DefaultAddonPVRClient.png'),
                art_dict=dict(thumb='DefaultTVShows.png',
                              fanart='DefaultTVShows.png'),
                info_dict=dict(plot=self._kodi.localize(30019))),
            TitleItem(
                title=self._kodi.localize(30020),  # Recent items
                path=self._kodi.url_for('recent'),
                art_dict=dict(thumb='DefaultRecentlyAddedEpisodes.png',
                              fanart='DefaultRecentlyAddedEpisodes.png'),
                info_dict=dict(plot=self._kodi.localize(30021))),
            TitleItem(
                title=self._kodi.localize(30022),  # Soon offline
                path=self._kodi.url_for('offline'),
                art_dict=dict(thumb='DefaultYear.png',
                              fanart='DefaultYear.png'),
                info_dict=dict(plot=self._kodi.localize(30023))),
            TitleItem(
                title=self._kodi.localize(30024),  # Featured content
                path=self._kodi.url_for('featured'),
                art_dict=dict(thumb='DefaultCountry.png',
                              fanart='DefaultCountry.png'),
                info_dict=dict(plot=self._kodi.localize(30025))),
            TitleItem(
                title=self._kodi.localize(30026),  # TV guide
                path=self._kodi.url_for('tvguide'),
                art_dict=dict(thumb='DefaultAddonTvInfo.png',
                              fanart='DefaultAddonTvInfo.png'),
                info_dict=dict(plot=self._kodi.localize(30027))),
            TitleItem(
                title=self._kodi.localize(30028),  # Search
                path=self._kodi.url_for('search'),
                art_dict=dict(thumb='DefaultAddonsSearch.png',
                              fanart='DefaultAddonsSearch.png'),
                info_dict=dict(plot=self._kodi.localize(30029))),
        ])
        self._kodi.show_listing(main_items)

        # NOTE: In the future we can implement a LooseVersion check, now we can simply check if version is empty (pre-2.0.0)
        # from distutils.version import LooseVersion
        settings_version = self._kodi.get_setting('version', '')
        if settings_version == '' and self._kodi.has_credentials(
        ):  # New major version, favourites and what-was-watched will break
            self._kodi.show_ok_dialog(self._kodi.localize(30978),
                                      self._kodi.localize(30979))
        addon_version = self._kodi.get_addon_info('version')
        if settings_version != addon_version:
            self._kodi.set_setting('version', addon_version)
Exemplo n.º 14
0
    def show_episodes(self, date, channel):
        ''' Show episodes for a given date and channel '''
        now = datetime.now(dateutil.tz.tzlocal())
        epg = self.parse(date, now)
        datelong = self._kodi.localize_datelong(epg)
        epg_url = epg.strftime(self.VRT_TVGUIDE)

        self._favorites.get_favorites(ttl=60 * 60)

        cache_file = 'schedule.%s.json' % date
        if date in ('today', 'yesterday', 'tomorrow'):
            # Try the cache if it is fresh
            schedule = self._kodi.get_cache(cache_file, ttl=60 * 60)
            if not schedule:
                self._kodi.log_notice('URL get: ' + epg_url, 'Verbose')
                schedule = json.load(urlopen(epg_url))
                self._kodi.update_cache(cache_file, schedule)
        else:
            self._kodi.log_notice('URL get: ' + epg_url, 'Verbose')
            schedule = json.load(urlopen(epg_url))

        name = channel
        try:
            channel = next(c for c in CHANNELS if c.get('name') == name)
            episodes = schedule.get(channel.get('id'), [])
        except StopIteration:
            episodes = []
        episode_items = []
        for episode in episodes:
            metadata = metadatacreator.MetadataCreator()
            title = episode.get('title', 'Untitled')
            start = episode.get('start')
            end = episode.get('end')
            start_date = dateutil.parser.parse(episode.get('startTime'))
            end_date = dateutil.parser.parse(episode.get('endTime'))
            metadata.datetime = start_date
            url = episode.get('url')
            metadata.tvshowtitle = title
            label = '%s - %s' % (start, title)
            # NOTE: Do not use startTime and endTime as we don't want duration with seconds granularity
            start_time = dateutil.parser.parse(start)
            end_time = dateutil.parser.parse(end)
            if end_time < start_time:
                end_time = end_time + timedelta(days=1)
            metadata.duration = (end_time - start_time).total_seconds()
            metadata.plot = '[B]%s[/B]\n%s\n%s - %s\n[I]%s[/I]' % (
                title, datelong, start, end, channel.get('label'))
            metadata.brands.append(channel.get('studio'))
            metadata.mediatype = 'episode'
            if self._showfanart:
                thumb = episode.get('image', 'DefaultAddonVideo.png')
            else:
                thumb = 'DefaultAddonVideo.png'
            metadata.icon = thumb
            context_menu = []
            if url:
                video_url = statichelper.add_https_method(url)
                path = self._kodi.url_for('play_url', video_url=video_url)
                if start_date <= now <= end_date:  # Now playing
                    label = '[COLOR yellow]%s[/COLOR] %s' % (
                        label, self._kodi.localize(30302))
                program = statichelper.url_to_program(episode.get('url'))
                if self._favorites.is_activated():
                    program_title = quote(title.encode('utf-8'), '')
                    if self._favorites.is_favorite(program):
                        context_menu = [
                            (self._kodi.localize(30412), 'RunPlugin(%s)' %
                             self._kodi.url_for('unfollow',
                                                program=program,
                                                title=program_title))
                        ]
                        label += ' [COLOR yellow]°[/COLOR]'
                    else:
                        context_menu = [
                            (self._kodi.localize(30411), 'RunPlugin(%s)' %
                             self._kodi.url_for('follow',
                                                program=program,
                                                title=program_title))
                        ]
            else:
                # This is a non-actionable item
                path = None
                if start_date < now <= end_date:  # Now playing
                    label = '[COLOR gray]%s[/COLOR] %s' % (
                        label, self._kodi.localize(30302))
                else:
                    label = '[COLOR gray]%s[/COLOR]' % label
            context_menu.append(
                (self._kodi.localize(30413), 'RunPlugin(%s)' %
                 self._kodi.url_for('delete_cache', cache_file=cache_file)))
            metadata.title = label
            episode_items.append(
                TitleItem(
                    title=label,
                    path=path,
                    art_dict=dict(thumb=thumb,
                                  icon='DefaultAddonVideo.png',
                                  fanart=thumb),
                    info_dict=metadata.get_info_dict(),
                    is_playable=True,
                    context_menu=context_menu,
                ))
        return episode_items