예제 #1
0
    def verify(self, progress=None):
        """verifies the current file for correctness

        returns True if the file is okay
        raises an InvalidFile with an error message if there is
        some problem with the file"""

        # Checking for a truncated Ogg stream typically involves
        # verifying that the "end of stream" flag is set on the last
        # Ogg page in the stream in the event that one or more whole
        # pages is lost.  But since the OpusFile decoder doesn't perform
        # this check and doesn't provide any access to its internal
        # Ogg decoder (unlike Vorbis), we'll perform that check externally.
        #
        # And since it's a fast check, we won't bother to update progress.

        from audiotools.ogg import PageReader
        import os.path

        try:
            reader = PageReader(open(self.filename, "rb"))
        except IOError as err:
            raise InvalidOpus(str(err))

        try:
            page = reader.read()
            while (not page.stream_end):
                page = reader.read()
            reader.close()
        except (IOError, ValueError) as err:
            raise InvalidOpus(str(err))

        return AudioFile.verify(self, progress)
예제 #2
0
    def verify(self, progress=None):
        """verifies the current file for correctness

        returns True if the file is okay
        raises an InvalidFile with an error message if there is
        some problem with the file"""

        # Checking for a truncated Ogg stream typically involves
        # verifying that the "end of stream" flag is set on the last
        # Ogg page in the stream in the event that one or more whole
        # pages is lost.  But since the OpusFile decoder doesn't perform
        # this check and doesn't provide any access to its internal
        # Ogg decoder (unlike Vorbis), we'll perform that check externally.
        #
        # And since it's a fast check, we won't bother to update progress.

        from audiotools.ogg import PageReader
        import os.path

        try:
            reader = PageReader(open(self.filename, "rb"))
        except IOError as err:
            raise InvalidOpus(str(err))

        try:
            page = reader.read()
            while (not page.stream_end):
                page = reader.read()
            reader.close()
        except (IOError, ValueError) as err:
            raise InvalidOpus(str(err))

        return AudioFile.verify(self, progress)
예제 #3
0
    def total_frames(self):
        """returns the total PCM frames of the track as an integer"""

        from audiotools._ogg import PageReader

        try:
            reader = PageReader(file(self.filename, "rb"))
            page = reader.read()
            pcm_samples = page.granule_position

            while (not page.stream_end):
                page = reader.read()
                pcm_samples = max(pcm_samples, page.granule_position)

            reader.close()
            return pcm_samples
        except (IOError, ValueError):
            return 0