Beispiel #1
0
    def get_storefront_category(self, storefront, category):
        """ Returns a storefront.

         :param str storefront:         The ID of the storefront.
         :param str category:           The ID of the category.
         :rtype: Category
         """
        response = util.http_get(
            API_ENDPOINT + '/%s/storefronts/%s/detail/%s' %
            (self._mode(), storefront, category),
            token=self._tokens.jwt_token if self._tokens else None,
            profile=self._tokens.profile if self._tokens else None)
        result = json.loads(response.text)

        items = []
        for item in result.get('row', {}).get('teasers'):
            if item.get('target', {}).get('type') == CONTENT_TYPE_MOVIE:
                items.append(self._parse_movie_teaser(item))

            elif item.get('target', {}).get('type') == CONTENT_TYPE_PROGRAM:
                items.append(self._parse_program_teaser(item))

        return Category(category_id=category,
                        title=result.get('row', {}).get('title'),
                        content=items)
Beispiel #2
0
    def get_storefront(self, storefront):
        """ Returns a storefront.

         :param str storefront:         The ID of the storefront.
         :rtype: list[Category|Program|Movie]
         """
        response = util.http_get(
            API_ENDPOINT + '/%s/storefronts/%s' % (self._mode(), storefront),
            token=self._tokens.jwt_token if self._tokens else None,
            profile=self._tokens.profile if self._tokens else None)
        result = json.loads(response.text)

        items = []
        for row in result.get('rows', []):
            if row.get('rowType') in [
                    'SWIMLANE_DEFAULT', 'SWIMLANE_PORTRAIT',
                    'SWIMLANE_LANDSCAPE'
            ]:
                items.append(
                    Category(
                        category_id=row.get('id'),
                        title=row.get('title'),
                    ))
                continue

            if row.get('rowType') == 'CAROUSEL':
                for item in row.get('teasers'):
                    if item.get('target',
                                {}).get('type') == CONTENT_TYPE_MOVIE:
                        items.append(self._parse_movie_teaser(item))

                    elif item.get('target',
                                  {}).get('type') == CONTENT_TYPE_PROGRAM:
                        items.append(self._parse_program_teaser(item))
                continue

            if row.get('rowType') in ['TOP_BANNER', 'MARKETING_BLOCK']:
                item = row.get('teaser')
                if item.get('target', {}).get('type') == CONTENT_TYPE_MOVIE:
                    items.append(self._parse_movie_teaser(item))

                elif item.get('target',
                              {}).get('type') == CONTENT_TYPE_PROGRAM:
                    items.append(self._parse_program_teaser(item))
                continue

            _LOGGER.debug('Skipping recommendation %s with type %s',
                          row.get('title'), row.get('rowType'))

        return items
Beispiel #3
0
    def get_categories(self):
        """ Get a list of all the categories.
        :rtype list[Category]
        """
        response = util.http_get(API_ENDPOINT + '/%s/catalog/filters' % self._mode(),
                                 token=self._tokens.jwt_token,
                                 profile=self._tokens.profile)
        info = json.loads(response.text)

        categories = []
        for item in info.get('catalogFilters', []):
            categories.append(Category(
                category_id=item.get('id'),
                title=item.get('title'),
            ))

        return categories
Beispiel #4
0
    def get_recommendations(self, storefront):
        """ Returns the config for the dashboard.

         :param str storefront:         The ID of the listing.
         :rtype: list[Category]
         """
        response = util.http_get(API_ENDPOINT + '/%s/storefronts/%s' %
                                 (self._mode(), storefront),
                                 token=self._tokens.jwt_token,
                                 profile=self._tokens.profile)
        recommendations = json.loads(response.text)

        categories = []
        for cat in recommendations.get('rows', []):
            if cat.get('rowType') not in ['SWIMLANE_DEFAULT']:
                _LOGGER.debug('Skipping recommendation %s with type %s',
                              cat.get('title'), cat.get('rowType'))
                continue

            items = []
            for item in cat.get('teasers'):
                if item.get('target', {}).get('type') == CONTENT_TYPE_MOVIE:
                    items.append(self._parse_movie_teaser(item))

                elif item.get('target',
                              {}).get('type') == CONTENT_TYPE_PROGRAM:
                    items.append(self._parse_program_teaser(item))

            categories.append(
                Category(
                    category_id=cat.get('id'),
                    title=cat.get('title'),
                    content=items,
                ))

        return categories