Ejemplo n.º 1
0
    def get_metadata(self):
        """returns a MetaData object, or None

        raises IOError if unable to read the file"""

        from audiotools.id3 import ID3CommentPair
        from audiotools.id3 import read_id3v2_comment
        from audiotools.id3v1 import ID3v1Comment

        with open(self.filename, "rb") as f:
            if f.read(3) == b"ID3":
                id3v2 = read_id3v2_comment(self.filename)

                try:
                    # yes IDv2, yes ID3v1
                    return ID3CommentPair(id3v2, ID3v1Comment.parse(f))
                except ValueError:
                    # yes ID3v2, no ID3v1
                    return id3v2
            else:
                try:
                    # no ID3v2, yes ID3v1
                    return ID3v1Comment.parse(f)
                except ValueError:
                    # no ID3v2, no ID3v1
                    return None
Ejemplo n.º 2
0
    def get_metadata(self):
        """returns a MetaData object, or None

        raises IOError if unable to read the file"""

        from audiotools.id3 import ID3CommentPair
        from audiotools.id3 import read_id3v2_comment
        from audiotools.id3v1 import ID3v1Comment

        with open(self.filename, "rb") as f:
            if f.read(3) == b"ID3":
                id3v2 = read_id3v2_comment(self.filename)

                try:
                    # yes IDv2, yes ID3v1
                    return ID3CommentPair(id3v2, ID3v1Comment.parse(f))
                except ValueError:
                    # yes ID3v2, no ID3v1
                    return id3v2
            else:
                try:
                    # no ID3v2, yes ID3v1
                    return ID3v1Comment.parse(f)
                except ValueError:
                    # no ID3v2, no ID3v1
                    return None
Ejemplo n.º 3
0
    def get_metadata(self):
        """returns a MetaData object, or None

        raises IOError if unable to read the file"""

        f = open(self.filename, "rb")

        # first, attempt to find APEv2 comment at end of file
        f.seek(-32, 2)
        if (f.read(10) == "APETAGEX\xd0\x07"):
            from audiotools import ApeTag

            return ApeTag.read(f)
        else:
            # then, look for ID3v2 comment at beginning of file
            f.seek(0, 0)
            if (f.read(3) == "ID3"):
                from audiotools.id3 import read_id3v2_comment
                try:
                    id3v2 = read_id3v2_comment(self.filename)
                except ValueError:
                    id3v2 = None
            else:
                id3v2 = None

            # and look for ID3v1 comment at end of file
            try:
                f.seek(-128, 2)
                if (f.read(3) == "TAG"):
                    from audiotools.id3v1 import ID3v1Comment
                    try:
                        id3v1 = ID3v1Comment.parse(f)
                    except ValueError:
                        id3v1 = None
                else:
                    id3v1 = None
            except IOError:
                id3v1 = None

            # if both ID3v2 and ID3v1 are present, return a pair
            if ((id3v2 is not None) and (id3v1 is not None)):
                from audiotools.id3 import ID3CommentPair
                return ID3CommentPair(id3v2, id3v1)
            elif (id3v2 is not None):
                return id3v2
            else:
                return id3v1
Ejemplo n.º 4
0
    def get_metadata(self):
        """returns a MetaData object, or None

        raises IOError if unable to read the file"""

        f = open(self.filename, "rb")

        # first, attempt to find APEv2 comment at end of file
        f.seek(-32, 2)
        if (f.read(10) == "APETAGEX\xd0\x07"):
            from audiotools import ApeTag

            return ApeTag.read(f)
        else:
            # then, look for ID3v2 comment at beginning of file
            f.seek(0, 0)
            if (f.read(3) == "ID3"):
                from audiotools.id3 import read_id3v2_comment
                try:
                    id3v2 = read_id3v2_comment(self.filename)
                except ValueError:
                    id3v2 = None
            else:
                id3v2 = None

            # and look for ID3v1 comment at end of file
            try:
                f.seek(-128, 2)
                if (f.read(3) == "TAG"):
                    from audiotools.id3v1 import ID3v1Comment
                    try:
                        id3v1 = ID3v1Comment.parse(f)
                    except ValueError:
                        id3v1 = None
                else:
                    id3v1 = None
            except IOError:
                id3v1 = None

            # if both ID3v2 and ID3v1 are present, return a pair
            if ((id3v2 is not None) and (id3v1 is not None)):
                from audiotools.id3 import ID3CommentPair
                return ID3CommentPair(id3v2, id3v1)
            elif (id3v2 is not None):
                return id3v2
            else:
                return id3v1