コード例 #1
0
ファイル: tags.py プロジェクト: foxhead128/akane
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
コード例 #2
0
ファイル: id3v1.py プロジェクト: foxhead128/akane
 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)
コード例 #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)
コード例 #4
0
ファイル: tags.py プロジェクト: foxhead128/akane
 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)