Пример #1
0
    def get_list_of_lists(self, path, page=1, limit=250, authorize=False, next_page=True):
        response = self.get_response(path, page=page, limit=limit)
        like_list = True if path.startswith('lists/') else False
        delete_like = True if path.startswith('users/likes') else False
        if not response:
            return
        items = []
        for i in response.json():
            if i.get('list', {}).get('name'):
                i = i.get('list', {})
            elif not i.get('name'):
                continue

            item = {}
            item['label'] = i.get('name')
            item['infolabels'] = {'plot': i.get('description')}
            item['infoproperties'] = {k: v for k, v in i.items() if v and type(v) not in [list, dict]}
            item['art'] = {}
            item['params'] = {
                'info': 'trakt_userlist',
                'list_slug': i.get('ids', {}).get('slug'),
                'user_slug': i.get('user', {}).get('ids', {}).get('slug')}
            item['unique_ids'] = {
                'trakt': i.get('ids', {}).get('trakt'),
                'slug': i.get('ids', {}).get('slug'),
                'user': i.get('user', {}).get('ids', {}).get('slug')}
            item['infoproperties']['tmdbhelper.context.sorting'] = dumps(item['params'])

            # Add library context menu
            item['context_menu'] = [(
                xbmc.getLocalizedString(20444), u'Runscript(plugin.video.themoviedb.helper,{})'.format(
                    u'user_list={list_slug},user_slug={user_slug}'.format(**item['params'])))]

            # Unlike list context menu
            if path.startswith('users/likes'):
                item['context_menu'] += [(
                    ADDON.getLocalizedString(32319), u'Runscript(plugin.video.themoviedb.helper,{},delete)'.format(
                        u'like_list={list_slug},user_slug={user_slug}'.format(**item['params'])))]

            # Like list context menu
            elif path.startswith('lists/'):
                item['context_menu'] += [(
                    ADDON.getLocalizedString(32315), u'Runscript(plugin.video.themoviedb.helper,{})'.format(
                        u'like_list={list_slug},user_slug={user_slug}'.format(**item['params'])))]

            # Owner of list so set param to allow deleting later
            else:
                item['params']['owner'] = 'true'
                item['context_menu'] += [(
                    xbmc.getLocalizedString(118), u'Runscript(plugin.video.themoviedb.helper,{})'.format(
                        u'rename_list={list_slug}'.format(**item['params'])))]
                item['context_menu'] += [(
                    xbmc.getLocalizedString(117), u'Runscript(plugin.video.themoviedb.helper,{})'.format(
                        u'delete_list={list_slug}'.format(**item['params'])))]

            items.append(item)
        if not next_page:
            return items
        return items + pages.get_next_page(response.headers)
Пример #2
0
 def get_basic_list(self, path, trakt_type, page=1, limit=20, params=None, sort_by=None, sort_how=None, extended=None, authorize=False, randomise=False):
     # TODO: Add argument to check whether to refresh on first page (e.g. for user lists)
     # Also: Think about whether need to do it for standard respons
     cache_refresh = True if try_int(page, fallback=1) == 1 else False
     if randomise:
         response = self.get_simple_list(
             path, extended=extended, page=1, limit=50, trakt_type=trakt_type)
     elif sort_by is not None:  # Sorted list manually paginated because need to sort first
         response = self.get_sorted_list(path, sort_by, sort_how, extended, cache_refresh=cache_refresh)
         response = PaginatedItems(items=response['items'], page=page, limit=limit).get_dict()
     else:  # Unsorted lists can be paginated by the API
         response = self.get_simple_list(
             path, extended=extended, page=page, limit=limit, trakt_type=trakt_type)
     if response:
         if randomise and len(response['items']) > limit:
             items = random.sample(response['items'], limit)
             return items
         return response['items'] + pages.get_next_page(response['headers'])