Exemple #1
0
def use_lastupdated_cache(func, *args, **kwargs):
    """
    Not a decorator. Function to check sync_info last_updated_at to decide if cache or refresh
    sync_info=self.get_sync('watched', 'show', 'slug').get(slug)
    cache_name='TraktAPI.get_show_progress.response.{}'.format(slug)
    """
    sync_info = kwargs.pop('sync_info', None) or {}
    cache_name = kwargs.pop('cache_name', None) or ''

    # Get last modified timestamp from Trakt sync
    last_updated_at = sync_info.get('last_updated_at')

    # Get cached object
    cached_obj = cache.get_cache(cache_name) if last_updated_at else None

    # Return the cached response if show hasn't been modified on Trakt or watched since caching
    if cached_obj and cached_obj.get('response') and cached_obj.get(
            'last_updated_at'):
        if cached_obj['last_updated_at'] == last_updated_at:
            return cached_obj['response']

    # Otherwise get a new response from Trakt and cache it with the timestamp
    # Cache is long (14 days) because we refresh earlier if last_updated_at timestamps change
    response = func(*args, **kwargs)
    if response and last_updated_at:
        cache.set_cache(
            {
                'response': response,
                'last_updated_at': last_updated_at
            }, cache_name)
    return response
Exemple #2
0
    def select_artwork(self,
                       ftv_id,
                       ftv_type,
                       container_refresh=True,
                       blacklist=[]):
        if ftv_type not in ['movies', 'tv']:
            return
        with busy_dialog():
            artwork = self.get_artwork_request(ftv_id, ftv_type)
        if not artwork:
            return xbmcgui.Dialog().notification(
                'FanartTV',
                ADDON.getLocalizedString(32217).format(ftv_type, ftv_id))

        # Choose Type
        _artwork_types = [
            'poster', 'fanart', 'clearart', 'clearlogo', 'landscape', 'banner'
        ]
        _artwork_types.append('discart' if ftv_type ==
                              'movies' else 'characterart')
        artwork_types = [i for i in _artwork_types if i not in blacklist
                         ]  # Remove types that we previously looked for
        choice = xbmcgui.Dialog().select(xbmc.getLocalizedString(13511),
                                         artwork_types)
        if choice == -1:
            return

        # Get artwork of user's choosing
        artwork_type = artwork_types[choice]
        artwork_items = self.get_artwork(ftv_id,
                                         ftv_type,
                                         artwork_type,
                                         get_list=True)

        # If there was not artwork of that type found then blacklist it before re-prompting
        if not artwork_items:
            xbmcgui.Dialog().notification(
                'FanartTV',
                ADDON.getLocalizedString(32217).format(ftv_type, ftv_id))
            blacklist.append(artwork_types[choice])
            return self.select_artwork(ftv_id, ftv_type, container_refresh,
                                       blacklist)

        # Choose artwork from options
        items = [
            ListItem(label=i.get('url'),
                     label2=ADDON.getLocalizedString(32219).format(
                         i.get('lang', ''), i.get('likes', 0), i.get('id',
                                                                     '')),
                     art={
                         'thumb': i.get('url')
                     }).get_listitem() for i in artwork_items if i.get('url')
        ]
        choice = xbmcgui.Dialog().select(xbmc.getLocalizedString(13511),
                                         items,
                                         useDetails=True)
        if choice == -1:  # If user hits back go back to main menu rather than exit completely
            return self.select_artwork(ftv_id, ftv_type, container_refresh,
                                       blacklist)

        # Cache our choice as the best artwork forever since it was selected manually
        # Some types have have HD and SD variants so set cache for both
        for i in ARTWORK_TYPES.get(ftv_type, {}).get(artwork_type, []):
            success = cache.set_cache(
                artwork_items[choice].get('url'),
                cache_name='fanart_tv.best.{}.{}.{}.{}'.format(
                    self.language, ftv_id, ftv_type, i),
                cache_days=10000)
        if success and container_refresh:
            xbmc.executebuiltin('Container.Refresh')
            xbmc.executebuiltin(
                'UpdateLibrary(video,/fake/path/to/force/refresh/on/home)')
 def set_cache(self, cache_days=120):
     cache.set_cache(self.my_history,
                     self.cache_name,
                     cache_days=cache_days)