Exemplo n.º 1
0
def get_uri(source):
    """
    Check a media source as a valid file or uri and return the proper uri
    """

    import gst
    # Is this an valid URI source
    if gst.uri_is_valid(source):
        uri_protocol = gst.uri_get_protocol(source)
        if gst.uri_protocol_is_supported(gst.URI_SRC, uri_protocol):
            return source
        else:
            raise IOError('Invalid URI source for Gstreamer')

    # is this a file?
    import os.path
    if os.path.exists(source):
        # get the absolute path
        pathname = os.path.abspath(source)
        # and make a uri of it
        uri = path2uri(pathname)

        return get_uri(uri)
    else:
        raise IOError('Failed getting uri for path %s: not such file or directoy' % source)

    return uri
Exemplo n.º 2
0
    def _analyze(self):
        """
        Sets up a pipeline to analyze the given uri
        """
        self.current_uri = self.queue[0]
        self.info("Analyzing %s", self.current_uri)

        # check if file exists and is readable
        if gst.uri_get_protocol(self.current_uri) == "file":
            filename = gst.uri_get_location(self.current_uri)
            error = None
            if not os.access(filename, os.F_OK):
                error = _("File does not exist")
            elif not os.access(filename, os.R_OK):
                error = _("File not readable by current user")
            if error:
                self.info("Error: %s", self.error)
                self.error = error
                self._finishAnalysis(
                    "File does not exist or is not readable by the current user"
                )
                return False

        # setup graph and start analyzing
        self.pipeline = gst.Pipeline("Discoverer-%s" % self.current_uri)

        # create the source element
        source = self._createSource()
        if source is None:
            self._finishAnalysis("no source")
            return False

        # create decodebin(2)
        dbin = self._createDecodeBin()

        self.pipeline.add(source, dbin)
        source.link(dbin)
        self.info("analysis pipeline created")

        # connect to bus messages
        self._connectToBus()

        self.info("setting pipeline to PAUSED")

        # go to PAUSED
        if self.pipeline.set_state(
                gst.STATE_PAUSED) == gst.STATE_CHANGE_FAILURE:
            if not self.error:
                self.error = _("Pipeline didn't want to go to PAUSED.")
            self.info("Pipeline didn't want to go to PAUSED")
            self._finishAnalysis("failure going to PAUSED")

            return False

        self._scheduleTimeout()

        # return False so we don't get called again
        return False
Exemplo n.º 3
0
def uri_is_valid(uri):
    """Checks if the given uri is a valid uri (of type file://)

    Will also check if the size is valid (> 0).

    @param uri: The location to check
    @type uri: C{URI}
    """
    return (gst.uri_is_valid(uri) and gst.uri_get_protocol(uri) == "file"
            and len(os.path.basename(gst.uri_get_location(uri))) > 0)
Exemplo n.º 4
0
    def _analyze(self):
        """
        Sets up a pipeline to analyze the given uri
        """
        self.current_uri = self.queue[0]
        self.info("Analyzing %s", self.current_uri)

        # check if file exists and is readable
        if gst.uri_get_protocol(self.current_uri) == "file":
            filename = gst.uri_get_location(self.current_uri)
            error = None
            if not os.access(filename, os.F_OK):
                error = _("File does not exist")
            elif not os.access(filename, os.R_OK):
                error = _("File not readable by current user")
            if error:
                self.info("Error: %s", self.error)
                self.error = error
                self._finishAnalysis("File does not exist or is not readable by the current user")
                return False

        # setup graph and start analyzing
        self.pipeline = gst.Pipeline("Discoverer-%s" % self.current_uri)

        # create the source element
        source = self._createSource()
        if source is None:
            self._finishAnalysis("no source")
            return False

        # create decodebin(2)
        dbin = self._createDecodeBin()

        self.pipeline.add(source, dbin)
        source.link(dbin)
        self.info("analysis pipeline created")

        # connect to bus messages
        self._connectToBus()

        self.info("setting pipeline to PAUSED")

        # go to PAUSED
        if self.pipeline.set_state(gst.STATE_PAUSED) == gst.STATE_CHANGE_FAILURE:
            if not self.error:
                self.error = _("Pipeline didn't want to go to PAUSED.")
            self.info("Pipeline didn't want to go to PAUSED")
            self._finishAnalysis("failure going to PAUSED")

            return False

        self._scheduleTimeout()

        # return False so we don't get called again
        return False
Exemplo n.º 5
0
def uri_is_valid(uri):
    """Checks if the given uri is a valid uri (of type file://)

    Will also check if the size is valid (> 0).

    @param uri: The location to check
    @type uri: C{URI}
    """
    return (gst.uri_is_valid(uri) and
            gst.uri_get_protocol(uri) == "file" and
            len(os.path.basename(gst.uri_get_location(uri))) > 0)
Exemplo n.º 6
0
    def _createSource(self):
        source = gst.element_make_from_uri(gst.URI_SRC, self.current_uri, "src-%s" % self.current_uri)
        if not source:
            self.warning("This is not a media file: %s", self.current_uri)
            self.error = _("No available source handler.")
            self.error_detail = _(
                'You do not have a GStreamer source element to handle the "%s" protocol'
            ) % gst.uri_get_protocol(self.current_uri)

            return None

        # increment source blocksize to 128kbytes, this should speed up
        # push-mode scenarios (like pictures).
        if hasattr(source.props, "blocksize"):
            source.props.blocksize = 131072
        return source
Exemplo n.º 7
0
    def _createSource(self):
        source = gst.element_make_from_uri(gst.URI_SRC, self.current_uri,
                                           "src-%s" % self.current_uri)
        if not source:
            self.warning("This is not a media file: %s", self.current_uri)
            self.error = _("No available source handler.")
            self.error_detail = _(
                "You do not have a GStreamer source element to handle protocol '%s'"
            ) % gst.uri_get_protocol(self.current_uri)

            return None

        # increment source blocksize to 128kbytes, this should speed up
        # push-mode scenarios (like pictures).
        if hasattr(source.props, 'blocksize'):
            source.props.blocksize = 131072
        return source
Exemplo n.º 8
0
def get_uri(source):
    """
    Check a media source as a valid file or uri and return the proper uri
    """

    import gst

    src_info = source_info(source)

    if src_info['is_file']:  # Is this a file?
        return get_uri(src_info['uri'])

    elif gst.uri_is_valid(source):  # Is this a valid URI source for Gstreamer
        uri_protocol = gst.uri_get_protocol(source)
        if gst.uri_protocol_is_supported(gst.URI_SRC, uri_protocol):
            return source
        else:
            raise IOError('Invalid URI source for Gstreamer')
    else:
        raise IOError('Failed getting uri for path %s: no such file' % source)
Exemplo n.º 9
0
def get_uri(source):
    """
    Check a media source as a valid file or uri and return the proper uri
    """

    import gst

    src_info = source_info(source)

    if src_info['is_file']:  # Is this a file?
        return get_uri(src_info['uri'])

    elif gst.uri_is_valid(source):  # Is this a valid URI source for Gstreamer
        uri_protocol = gst.uri_get_protocol(source)
        if gst.uri_protocol_is_supported(gst.URI_SRC, uri_protocol):
            return source
        else:
            raise IOError('Invalid URI source for Gstreamer')
    else:
        raise IOError('Failed getting uri for path %s: no such file' % source)