Esempio n. 1
0
def delete_tag(filename):
    with fileutil.opened(filename, "rb+") as file:
        try:
            (cls, offset, length) = detect_tag(file)
            fileutil.replace_chunk(file, offset, length, bytes())
        except NoTagError:
            pass
Esempio n. 2
0
 def delete(cls, filename, offset=None):
     """Delete ID3v1 tag from a file (if present)."""
     with fileutil.opened(filename, "rb+") as file:
         if offset is None:
             file.seek(-128, 2)
         else:
             file.seek(offset)
         offset = file.tell()
         data = file.read(128)
         if data[:3] == b"TAG":
             fileutil.replace_chunk(file, offset, 128, b"", in_place=True)
Esempio n. 3
0
 def delete(cls, filename, offset=None):
     """Delete ID3v1 tag from a file (if present)."""
     with fileutil.opened(filename, "rb+") as file:
         if offset is None:
             file.seek(-128, 2)
         else:
             file.seek(offset)
         offset = file.tell()
         data = file.read(128)
         if data[:3] == b"TAG":
             fileutil.replace_chunk(file, offset, 128, b"", in_place=True)
Esempio n. 4
0
 def write(self, filename=None):
     if not filename:
         filename = self._filename
     if not filename:
         raise TypeError("invalid file: {0}".format(filename))
     with fileutil.opened(filename, "rb+") as file:
         try:
             (offset, length) = detect_tag(file)[1:3]
         except NoTagError:
             (offset, length) = (0, 0)
         if offset > 0:
             delete_tag(file)
             (offset, length) = (0, 0)
         tag_data = self.encode(size_hint=length)
         fileutil.replace_chunk(file, offset, length, tag_data)