Fixing wrong charset in Japanese mp3 files

I had some mp3s I downloaded from a publisher’s website, but they were all shift-jis encoded but marked as latin1. A common thing in Japan, unicode is still not at complete saturation. This script I completely whipped up is very single-purpose, one-shot. You’ll likely have to modify it if you’re having a similar problem.

import os
import mutagen.id3

def findMP3s(path):
    for child in os.listdir(path):
        child= os.path.join(path, child)
        if os.path.isdir(child):
            for mp3 in findMP3s(child):
                yield mp3
        elif child.lower().endswith(u'.mp3'):
            yield child

for path in findMP3s('.'):
    id3= mutagen.id3.ID3(path)
    for key, value in id3.items():
        if value.encoding!=3:

            for i in range(len(value.text)):
                value.text[i]= value.text[i].encode('latin1').decode('shift-jis')

            value.encoding= 3
    id3.save()
Code language: Python (python)

Leave a Reply

Your email address will not be published. Required fields are marked *

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)