示例#1
0
    def _update_type(self):
        """Update the type of this Media object.

        If there's a video file, mark this as a video type, else fallback
        to audio, if possible, or unknown (None)
        """
        if any(file.type == VIDEO for file in self.files):
            return VIDEO
        elif any(file.type == AUDIO for file in self.files):
            return AUDIO
        return None
示例#2
0
    def index(self, order=None, offset=0, limit=10, api_key=None, **kwargs):
        """Query for a flat list of categories.

        :param id: An :attr:`id <mediadrop.model.media.Category.id>` for lookup
        :type id: int

        :param name: A :attr:`name <mediadrop.model.media.Category.name>`
            for lookup
        :type name: str

        :param slug: A :attr:`slug <mediadrop.model.media.Category.slug>`
            for lookup
        :type slug: str

        :param order:
            A column name and 'asc' or 'desc', seperated by a space.
            The column name can be any one of the returned columns.
            Defaults to newest category first (id desc).
        :type order: str

        :param offset:
            Where in the complete resultset to start returning results.
            Defaults to 0, the very beginning. This is useful if you've
            already fetched the first 50 results and want to fetch the
            next 50 and so on.
        :type offset: int

        :param limit:
            Number of results to return in each query. Defaults to 10.
            The maximum allowed value defaults to 50 and is set via
            :attr:`request.settings['api_media_max_results']`.
        :type limit: int

        :param api_key:
            The api access key if required in settings
        :type api_key: unicode or None

        :rtype: JSON-ready dict
        :returns: The returned dict has the following fields:

            count (int)
                The total number of results that match this query.
            categories (list of dicts)
                A list of **category_info** dicts, as generated by the
                :meth:`_info <mediadrop.controllers.api.categories.CategoriesController._info>`
                method. The number of dicts in this list will be the lesser
                of the number of matched items and the requested limit.

        """
        if asbool(request.settings['api_secret_key_required']) \
            and api_key != request.settings['api_secret_key']:
            return dict(error='Authentication Error')

        if any(key in kwargs for key in ('id', 'slug', 'name')):
            kwargs['offset'] = offset
            kwargs['limit'] = limit
            kwargs['tree'] = False
            return self._get_query(**kwargs)

        return self._index_query(order, offset, limit, tree=False)
示例#3
0
    def index(self, order=None, offset=0, limit=10, api_key=None, **kwargs):
        """Query for a flat list of categories.

        :param id: An :attr:`id <mediadrop.model.media.Category.id>` for lookup
        :type id: int

        :param name: A :attr:`name <mediadrop.model.media.Category.name>`
            for lookup
        :type name: str

        :param slug: A :attr:`slug <mediadrop.model.media.Category.slug>`
            for lookup
        :type slug: str

        :param order:
            A column name and 'asc' or 'desc', seperated by a space.
            The column name can be any one of the returned columns.
            Defaults to newest category first (id desc).
        :type order: str

        :param offset:
            Where in the complete resultset to start returning results.
            Defaults to 0, the very beginning. This is useful if you've
            already fetched the first 50 results and want to fetch the
            next 50 and so on.
        :type offset: int

        :param limit:
            Number of results to return in each query. Defaults to 10.
            The maximum allowed value defaults to 50 and is set via
            :attr:`request.settings['api_media_max_results']`.
        :type limit: int

        :param api_key:
            The api access key if required in settings
        :type api_key: unicode or None

        :rtype: JSON-ready dict
        :returns: The returned dict has the following fields:

            count (int)
                The total number of results that match this query.
            categories (list of dicts)
                A list of **category_info** dicts, as generated by the
                :meth:`_info <mediadrop.controllers.api.categories.CategoriesController._info>`
                method. The number of dicts in this list will be the lesser
                of the number of matched items and the requested limit.

        """
        if asbool(request.settings['api_secret_key_required']) \
            and api_key != request.settings['api_secret_key']:
            return dict(error='Authentication Error')

        if any(key in kwargs for key in ('id', 'slug', 'name')):
            kwargs['offset'] = offset
            kwargs['limit'] = limit
            kwargs['tree'] = False
            return self._get_query(**kwargs)

        return self._index_query(order, offset, limit, tree=False)
示例#4
0
 def _all_links(self):
     """
     finds all tags with link attributes sequentially. safe against modification
     of said attributes in-place.
     """
     start = self.root
     while True:
         tag = start.findNext(lambda tag: any([(
             tag.get(i) for i in self.settings['attrs_considered_links'])]))
         if tag:
             start = tag
             yield tag
         else:
             break
示例#5
0
def preferred_player_for_media(media, **kwargs):
    uris = media.get_uris()

    from mediadrop.model.players import fetch_enabled_players
    # Find the first player that can play any uris
    for player_cls, player_data in fetch_enabled_players():
        can_play = player_cls.can_play(uris)
        if any(can_play):
            break
    else:
        return None

    # Grab just the uris that the chosen player can play
    playable_uris = [uri for uri, plays in izip(uris, can_play) if plays]
    kwargs['data'] = player_data
    return player_cls(media, playable_uris, **kwargs)
示例#6
0
def preferred_player_for_media(media, **kwargs):
    uris = media.get_uris()

    from mediadrop.model.players import fetch_enabled_players
    # Find the first player that can play any uris
    for player_cls, player_data in fetch_enabled_players():
        can_play = player_cls.can_play(uris)
        if any(can_play):
            break
    else:
        return None

    # Grab just the uris that the chosen player can play
    playable_uris = [uri for uri, plays in izip(uris, can_play) if plays]
    kwargs['data'] = player_data
    return player_cls(media, playable_uris, **kwargs)
示例#7
0
 def _all_links(self):
     """
     finds all tags with link attributes sequentially. safe against modification
     of said attributes in-place.
     """
     start = self.root
     while True:
         tag = start.findNext(
           lambda tag : any(
             [(tag.get(i) for i in self.settings['attrs_considered_links'])]
           ))
         if tag:
             start = tag
             yield tag
         else :
             break
示例#8
0
    def tree(self, depth=10, api_key=None, **kwargs):
        """Query for an expanded tree of categories.

        :param id: A :attr:`mediadrop.model.media.Category.id` to lookup the parent node
        :type id: int
        :param name: A :attr:`mediadrop.model.media.Category.name` to lookup the parent node
        :type name: str
        :param slug: A :attr:`mediadrop.model.media.Category.slug` to lookup the parent node
        :type slug: str

        :param depth:
            Number of level deep in children to expand. Defaults to 10.
            The maximum allowed value defaults to 10 and is set via
            :attr:`request.settings['api_tree_max_depth']`.
        :type limit: int
        :param api_key:
            The api access key if required in settings
        :type api_key: unicode or None
        :rtype: JSON-ready dict
        :returns: The returned dict has the following fields:

            count (int)
                The total number of results that match this query.
            categories (list of dicts)
                A list of **category_info** dicts, as generated by the
                :meth:`_info <mediadrop.controllers.api.categories.CategoriesController._info>`
                method. Each of these dicts represents a category at the top
                level of the hierarchy. Each dict has also been modified to
                have an extra 'children' field, which is a list of
                **category_info** dicts representing that category's children
                within the hierarchy.

        """
        if asbool(request.settings['api_secret_key_required']) \
            and api_key != request.settings['api_secret_key']:
            return dict(error='Authentication Error')
        if any(key in kwargs for key in ('id', 'slug', 'name')):
            kwargs['depth'] = depth
            kwargs['tree'] = True
            return self._get_query(**kwargs)

        return self._index_query(depth=depth, tree=True)
示例#9
0
    def tree(self, depth=10, api_key=None, **kwargs):
        """Query for an expanded tree of categories.

        :param id: A :attr:`mediadrop.model.media.Category.id` to lookup the parent node
        :type id: int
        :param name: A :attr:`mediadrop.model.media.Category.name` to lookup the parent node
        :type name: str
        :param slug: A :attr:`mediadrop.model.media.Category.slug` to lookup the parent node
        :type slug: str

        :param depth:
            Number of level deep in children to expand. Defaults to 10.
            The maximum allowed value defaults to 10 and is set via
            :attr:`request.settings['api_tree_max_depth']`.
        :type limit: int
        :param api_key:
            The api access key if required in settings
        :type api_key: unicode or None
        :rtype: JSON-ready dict
        :returns: The returned dict has the following fields:

            count (int)
                The total number of results that match this query.
            categories (list of dicts)
                A list of **category_info** dicts, as generated by the
                :meth:`_info <mediadrop.controllers.api.categories.CategoriesController._info>`
                method. Each of these dicts represents a category at the top
                level of the hierarchy. Each dict has also been modified to
                have an extra 'children' field, which is a list of
                **category_info** dicts representing that category's children
                within the hierarchy.

        """
        if asbool(request.settings['api_secret_key_required']) \
            and api_key != request.settings['api_secret_key']:
            return dict(error='Authentication Error')
        if any(key in kwargs for key in ('id', 'slug', 'name')):
            kwargs['depth'] = depth
            kwargs['tree'] = True
            return self._get_query(**kwargs)

        return self._index_query(depth=depth, tree=True)
示例#10
0
 def has_permission(self, permission_name):
     return any(perm.permission_name == permission_name
                for perm in self.permissions)
示例#11
0
文件: auth.py 项目: z0x010/mediadrop
 def has_permission(self, permission_name):
     return any(perm.permission_name == permission_name
                for perm in self.permissions)
示例#12
0
 def contains_only_whitespace(node):
     if is_tag(node):
         if not any([not is_text(s) for s in node.contents]):
             if not any([unicode(s).strip() for s in node.contents]):
                 return True
     return False
示例#13
0
 def contains_only_whitespace(node):
     if is_tag(node):
         if not any([not is_text(s) for s in node.contents]):
             if not any([unicode(s).strip() for s in node.contents]):
                 return True
     return False