Ejemplo n.º 1
0
    def perform_command(self):
        """
        Perform command and return the appropriate exit code.

        :rtype: int
        """
        if len(self.actual_arguments) < 1:
            return self.print_help()
        audio_file_path = self.actual_arguments[0]

        if not self.check_input_file(audio_file_path):
            return self.ERROR_EXIT_CODE

        try:
            prober = FFPROBEWrapper(rconf=self.rconf, logger=self.logger)
            dictionary = prober.read_properties(audio_file_path)
            for key in sorted(dictionary.keys()):
                self.print_generic(u"%s %s" % (key, dictionary[key]))
            return self.NO_ERROR_EXIT_CODE
        except FFPROBEPathError:
            self.print_error(u"Unable to call the ffprobe executable '%s'" % (self.rconf[RuntimeConfiguration.FFPROBE_PATH]))
            self.print_error(u"Make sure the path to ffprobe is correct")
        except (FFPROBEUnsupportedFormatError, FFPROBEParsingError):
            self.print_error(u"Cannot read properties of file '%s'" % (audio_file_path))
            self.print_error(u"Make sure the input file has a format supported by ffprobe")

        return self.ERROR_EXIT_CODE
Ejemplo n.º 2
0
    def perform_command(self):
        """
        Perform command and return the appropriate exit code.

        :rtype: int
        """
        if len(self.actual_arguments) < 1:
            return self.print_help()
        audio_file_path = self.actual_arguments[0]

        if not self.check_input_file(audio_file_path):
            return self.ERROR_EXIT_CODE

        try:
            prober = FFPROBEWrapper(rconf=self.rconf, logger=self.logger)
            dictionary = prober.read_properties(audio_file_path)
            for key in sorted(dictionary.keys()):
                self.print_generic(u"%s %s" % (key, dictionary[key]))
            return self.NO_ERROR_EXIT_CODE
        except FFPROBEPathError:
            self.print_error(u"Unable to call the ffprobe executable '%s'" %
                             (self.rconf[RuntimeConfiguration.FFPROBE_PATH]))
            self.print_error(u"Make sure the path to ffprobe is correct")
        except (FFPROBEUnsupportedFormatError, FFPROBEParsingError):
            self.print_error(u"Cannot read properties of file '%s'" %
                             (audio_file_path))
            self.print_error(
                u"Make sure the input file has a format supported by ffprobe")

        return self.ERROR_EXIT_CODE
Ejemplo n.º 3
0
def main():
    if len(sys.argv) < 2:
        usage()
        return
    audio_file_path = sys.argv[1]
    prober = FFPROBEWrapper()
    dictionary = prober.read_properties(audio_file_path)
    for key in sorted(dictionary.keys()):
        print "%s %s" % (key, dictionary[key])
Ejemplo n.º 4
0
def main():
    """ Entry point """
    if len(sys.argv) < 2:
        usage()
        return
    audio_file_path = sys.argv[1]
    prober = FFPROBEWrapper()
    dictionary = prober.read_properties(audio_file_path)
    for key in sorted(dictionary.keys()):
        print "%s %s" % (key, dictionary[key])
Ejemplo n.º 5
0
def step2():
    on_info("Test 2/6 (ffprobe)...")
    try:
        on_info("  Trying to call ffprobe...")
        from aeneas.ffprobewrapper import FFPROBEWrapper

        file_path = get_abs_path("aeneas/tests/res/container/job/assets/p001.mp3")
        prober = FFPROBEWrapper()
        properties = prober.read_properties(file_path)
        on_info("  Trying to call ffprobe... succeeded.")
        return True
    except:
        on_error("  Unable to call ffprobe.")
        on_error("  Please make sure you have ffprobe installed correctly and that it is in your $PATH.")
    return False
Ejemplo n.º 6
0
def step2():
    on_info("Test 2/6 (ffprobe)...")
    try:
        on_info("  Trying to call ffprobe...")
        from aeneas.ffprobewrapper import FFPROBEWrapper
        file_path = get_abs_path(
            "aeneas/tests/res/container/job/assets/p001.mp3")
        prober = FFPROBEWrapper()
        properties = prober.read_properties(file_path)
        on_info("  Trying to call ffprobe... succeeded.")
        return True
    except:
        on_error("  Unable to call ffprobe.")
        on_error(
            "  Please make sure you have ffprobe installed correctly and that it is in your $PATH."
        )
    return False
Ejemplo n.º 7
0
    def read_properties(self):
        """
        Populate this object by reading
        the audio properties of the file at the given path.

        Currently this function uses
        :class:`aeneas.ffprobewrapper.FFPROBEWrapper`
        to get the audio file properties.
        """

        self._log("Reading properties")

        # check the file can be read
        if self.file_path is None:
            raise AttributeError("File path is None")
        if not os.path.isfile(self.file_path):
            self._log(["File '%s' cannot be read", self.file_path],
                      Logger.CRITICAL)
            raise OSError("File cannot be read")

        # get the file size
        self._log(["Getting file size for '%s'", self.file_path])
        self.file_size = os.path.getsize(self.file_path)
        self._log(
            ["File size for '%s' is '%d'", self.file_path, self.file_size])

        # get the audio properties
        self._log("Reading properties with FFPROBEWrapper...")
        prober = FFPROBEWrapper(logger=self.logger)
        properties = prober.read_properties(self.file_path)
        self._log("Reading properties with FFPROBEWrapper... done")

        # save relevant properties in results inside the audiofile object
        self.audio_length = gf.safe_float(
            properties[FFPROBEWrapper.STDOUT_DURATION])
        self._log(["Stored audio_length: '%s'", self.audio_length])
        self.audio_format = properties[FFPROBEWrapper.STDOUT_CODEC_NAME]
        self._log(["Stored audio_format: '%s'", self.audio_format])
        self.audio_sample_rate = gf.safe_int(
            properties[FFPROBEWrapper.STDOUT_SAMPLE_RATE])
        self._log(["Stored audio_sample_rate: '%s'", self.audio_sample_rate])
        self.audio_channels = gf.safe_int(
            properties[FFPROBEWrapper.STDOUT_CHANNELS])
        self._log(["Stored audio_channels: '%s'", self.audio_channels])
Ejemplo n.º 8
0
    def read_properties(self):
        """
        Populate this object by reading
        the audio properties of the file at the given path.

        Currently this function uses
        :class:`~aeneas.ffprobewrapper.FFPROBEWrapper`
        to get the audio file properties.

        :raises: :class:`~aeneas.audiofile.AudioFileProbeError`: if the path to the ``ffprobe`` executable cannot be called
        :raises: :class:`~aeneas.audiofile.AudioFileUnsupportedFormatError`: if the audio file has a format not supported
        :raises: OSError: if the audio file cannot be read
        """
        self.log(u"Reading properties...")

        # check the file can be read
        if not gf.file_can_be_read(self.file_path):
            self.log_exc(u"File '%s' cannot be read" % (self.file_path), None,
                         True, OSError)

        # get the file size
        self.log([u"Getting file size for '%s'", self.file_path])
        self.file_size = gf.file_size(self.file_path)
        self.log(
            [u"File size for '%s' is '%d'", self.file_path, self.file_size])

        # get the audio properties using FFPROBEWrapper
        try:
            self.log(u"Reading properties with FFPROBEWrapper...")
            properties = FFPROBEWrapper(rconf=self.rconf,
                                        logger=self.logger).read_properties(
                                            self.file_path)
            self.log(u"Reading properties with FFPROBEWrapper... done")
        except FFPROBEPathError:
            self.log_exc(u"Unable to call ffprobe executable", None, True,
                         AudioFileProbeError)
        except (FFPROBEUnsupportedFormatError, FFPROBEParsingError):
            self.log_exc(u"Audio file format not supported by ffprobe", None,
                         True, AudioFileUnsupportedFormatError)

        # save relevant properties in results inside the audiofile object
        self.audio_length = TimeValue(
            properties[FFPROBEWrapper.STDOUT_DURATION])
        self.audio_format = properties[FFPROBEWrapper.STDOUT_CODEC_NAME]
        self.audio_sample_rate = gf.safe_int(
            properties[FFPROBEWrapper.STDOUT_SAMPLE_RATE])
        self.audio_channels = gf.safe_int(
            properties[FFPROBEWrapper.STDOUT_CHANNELS])
        self.log([u"Stored audio_length: '%s'", self.audio_length])
        self.log([u"Stored audio_format: '%s'", self.audio_format])
        self.log([u"Stored audio_sample_rate: '%s'", self.audio_sample_rate])
        self.log([u"Stored audio_channels: '%s'", self.audio_channels])
        self.log(u"Reading properties... done")
Ejemplo n.º 9
0
    def check_ffprobe(cls):
        """
        Check whether ``ffprobe`` can be called.

        Return ``True`` on failure and ``False`` on success.

        :rtype: bool
        """
        try:
            from aeneas.ffprobewrapper import FFPROBEWrapper
            file_path = gf.absolute_path(u"tools/res/audio.mp3", __file__)
            prober = FFPROBEWrapper()
            properties = prober.read_properties(file_path)
            gf.print_success(u"ffprobe        OK")
            return False
        except:
            pass
        gf.print_error(u"ffprobe        ERROR")
        gf.print_info(u"  Please make sure you have ffprobe installed correctly")
        gf.print_info(u"  (usually it is provided by the ffmpeg installer)")
        gf.print_info(u"  and that its path is in your PATH environment variable")
        return True
Ejemplo n.º 10
0
    def read_properties(self):
        """
        Populate this object by reading
        the audio properties of the file at the given path.

        Currently this function uses
        :class:`aeneas.ffprobewrapper.FFPROBEWrapper`
        to get the audio file properties.
        """

        self._log("Reading properties")

        # check the file can be read
        if self.file_path is None:
            raise AttributeError("File path is None")
        if not os.path.isfile(self.file_path):
            self._log(["File '%s' cannot be read", self.file_path], Logger.CRITICAL)
            raise OSError("File cannot be read")

        # get the file size
        self._log(["Getting file size for '%s'", self.file_path])
        self.file_size = os.path.getsize(self.file_path)
        self._log(["File size for '%s' is '%d'", self.file_path, self.file_size])

        # get the audio properties
        self._log("Reading properties with FFPROBEWrapper...")
        prober = FFPROBEWrapper(logger=self.logger)
        properties = prober.read_properties(self.file_path)
        self._log("Reading properties with FFPROBEWrapper... done")

        # save relevant properties in results inside the audiofile object
        self.audio_length = gf.safe_float(properties[FFPROBEWrapper.STDOUT_DURATION])
        self._log(["Stored audio_length: '%s'", self.audio_length])
        self.audio_format = properties[FFPROBEWrapper.STDOUT_CODEC_NAME]
        self._log(["Stored audio_format: '%s'", self.audio_format])
        self.audio_sample_rate = gf.safe_int(properties[FFPROBEWrapper.STDOUT_SAMPLE_RATE])
        self._log(["Stored audio_sample_rate: '%s'", self.audio_sample_rate])
        self.audio_channels = gf.safe_int(properties[FFPROBEWrapper.STDOUT_CHANNELS])
        self._log(["Stored audio_channels: '%s'", self.audio_channels])
Ejemplo n.º 11
0
    def check_ffprobe(cls):
        """
        Check whether ``ffprobe`` can be called.

        Return ``True`` on failure and ``False`` on success.

        :rtype: bool
        """
        try:
            from aeneas.ffprobewrapper import FFPROBEWrapper
            file_path = gf.absolute_path(u"tools/res/audio.mp3", __file__)
            prober = FFPROBEWrapper()
            properties = prober.read_properties(file_path)
            gf.print_success(u"ffprobe        OK")
            return False
        except:
            pass
        gf.print_error(u"ffprobe        ERROR")
        gf.print_info(u"  Please make sure you have ffprobe installed correctly")
        gf.print_info(u"  (usually it is provided by the ffmpeg installer)")
        gf.print_info(u"  and that its path is in your PATH environment variable")
        return True
Ejemplo n.º 12
0
 def load(self, input_file_path):
     prober = FFPROBEWrapper()
     return prober.read_properties(
         gf.absolute_path(input_file_path, __file__)
     )
Ejemplo n.º 13
0
def main():

    on_info("Test 1/4...")
    try:
        on_info("Trying to import package aeneas...")
        import aeneas
        on_info("Trying to import package aeneas... succeeded.")
    except ImportError:
        on_error("Unable to import package aeneas.")
        on_error("Check that you have installed the following Python (2.7.x) packages:")
        on_error("1. BeautifulSoup")
        on_error("2. numpy")
        on_error("3. scikits")
        return

    on_info("Test 2/4...")
    try:
        on_info("Trying to call ffprobe...")
        from aeneas.ffprobewrapper import FFPROBEWrapper
        file_path = get_abs_path("aeneas/tests/res/container/job/assets/p001.mp3")
        prober = FFPROBEWrapper()
        properties = prober.read_properties(file_path)
        on_info("Trying to call ffprobe... succeeded.")
    except:
        on_error("Unable to call ffprobe.")
        on_error("Please make sure you have ffprobe installed correctly and that it is in your $PATH.")
        return

    on_info("Test 3/4...")
    try:
        on_info("Trying to call ffmpeg...")
        from aeneas.ffmpegwrapper import FFMPEGWrapper
        input_file_path = get_abs_path("aeneas/tests/res/container/job/assets/p001.mp3")
        handler, output_file_path = tempfile.mkstemp(suffix=".wav")
        converter = FFMPEGWrapper()
        result = converter.convert(input_file_path, output_file_path)
        os.close(handler)
        os.remove(output_file_path)
        if not result:
            on_error("Unable to call ffmpeg.")
            on_error("Please make sure you have ffmpeg installed correctly and that it is in your $PATH.")
            return
        on_info("Trying to call ffmpeg... succeeded.")
    except:
        on_error("Unable to call ffmpeg.")
        on_error("Please make sure you have ffmpeg installed correctly and that it is in your $PATH.")
        return

    on_info("Test 4/4...")
    try:
        on_info("Trying to call espeak...")
        from aeneas.espeakwrapper import ESPEAKWrapper
        from aeneas.language import Language
        text = u"From fairest creatures we desire increase,"
        language = Language.EN
        handler, output_file_path = tempfile.mkstemp(suffix=".wav")
        espeak = ESPEAKWrapper()
        result = espeak.synthesize(text, language, output_file_path)
        os.close(handler)
        os.remove(output_file_path)
        if not result:
            on_error("Unable to call espeak.")
            on_error("Please make sure you have espeak installed correctly and that it is in your $PATH.")
            return
        on_info("Trying to call espeak... succeeded.")
    except:
        on_error("Unable to call espeak.")
        on_error("Please make sure you have espeak installed correctly and that it is in your $PATH.")
        return

    on_info("Congratulations, all dependencies are met.")
    on_info("Enjoy running aeneas!")
Ejemplo n.º 14
0
 def load(self, input_file_path):
     prober = FFPROBEWrapper()
     return prober.read_properties(get_abs_path(input_file_path))
Ejemplo n.º 15
0
 def load(self, input_file_path):
     prober = FFPROBEWrapper()
     return prober.read_properties(get_abs_path(input_file_path))
Ejemplo n.º 16
0
 def load(self, input_file_path):
     prober = FFPROBEWrapper()
     return prober.read_properties(
         gf.absolute_path(input_file_path, __file__))