artcom-net / mp3-tagger

ID3 data editor
MIT License
35 stars 16 forks source link

After tagging, seeing first charter missing and in year only last digits stays #3

Closed manojshankar closed 5 years ago

manojshankar commented 6 years ago

/home/manu/saavan/Balma.mp3 {'ID3TagV1': {'album': u'nthu Tagaru', 'comment': u'hony Daasan, Charanraj2', 'artist': u'Shiva RajkumarBa', 'track': 49, 'genre': 'Dream', 'song': u'Tagaru', 'year': u'ant'}, 'ID3TagV2': {}} {'album': u'Tagaru', 'comment': u'Shiva Rajkumar', 'track': 49, 'song': u'Banthu Tagaru', 'genre': 'Dream', 'artist': u'anthony Daasan, Charanraj', 'year': u'2017'} manu@manu-RV409-RV509:~/saavan$ python mp3tag.py /home/manu/saavan/Balma.mp3 {'ID3TagV1': {'album': u'nthu Tagaru1', 'comment': u'hony Daasan, Charanraj2', 'artist': u'Shiva RajkumarBa', 'track': 49, 'genre': 'Dream', 'song': u'Tagaru', 'year': u'7ant'}, 'ID3TagV2': {}} {'album': u'Tagaru', 'comment': u'Shiva Rajkumar', 'track': 49, 'song': u'Banthu Tagaru', 'genre': 'Dream', 'artist': u'anthony Daasan, Charanraj', 'year': u'2017'}

mp3tag.txt

huapage commented 5 years ago

In current version (SHA-1 hash: 698f233f3defdea985d0e1d9a334f3912f17caba) ID3TagV1.update has problem See update function in id3.py For ID3TagV1, the values was fixed as 128 bytes. so better use a byte array to handle.

Original code:

     def update(self, *args):
        """Updates byte string from tags."""
       bytes_ = b'TAG'
        for tag in self.tags:
            if tag.title == 'track':
                bytes_ += b'\x00'
            if tag.replace_bytes:
                bytes_ += tag.replace_bytes
                tag.update_attr()
            else:
                bytes_ += tag.bytes_
        super(ID3FrameV1, self).update(bytes_)

Modified code:

     def update(self, *args):
        """Updates byte string from tags."""
        result_bytes_list = list(b'TAG' + b'\0'*125) # ID3 v1 is fixed as 128 bytes
        has_update = False
        for tag in self.tags:
            offset, length = self.OFFSET[tag.title]
            if tag.replace_bytes: # replace
                has_update = True
                result_bytes_list[offset: offset+length] = list(tag.replace_bytes)
            else: # not changed value
                if tag.bytes_:
                    result_bytes_list[offset: offset+len(tag.bytes_)] = list(tag.bytes_)
        result_bytes = bytes(result_bytes_list)
        if has_update:
            self.replace_bytes = result_bytes
            tag.update_attr() # self.bytes_ = self.replace_bytes
        super(ID3FrameV1, self).update(result_bytes)
artcom-net commented 5 years ago

This is a problem only in Python 2, which is not supported. It is added in the README.rst here: 453ef8c22f688f8a28e95cd7298ea6ead60a0a4b