清空音乐文件的标签以避免播放器显示乱码

有时候我们拿到的音乐文件会包含专辑、歌手、音轨、年份等等标签信息,英文的还好,但是中文的,跨操作系统的时候就容易出现乱码。这时放到播放器里,十分影响观感,那不如把这些信息都清空。

import os
from mutagenx.easyid3 import EasyID3
from mutagenx.easymp4 import EasyMP4
baseurl = "C:/musics"
flist = os.listdir(baseurl)
for f in flist:
    fname = baseurl + "/" + f
    if fname.endswith(".mp3"):
        try:
            m = EasyID3(fname)
        except Exception as e:
            print(e)
    elif fname.endswith(".mp4") or fname.endswith(".m4a"):
        try:
            m = EasyMP4(fname)
        except Exception as e:
            print(e)
    else:
        print(fname) + " is unable to be converted."
    m["title"] = ""
    m["album"] = ""
    m["artist"] = ""
    m["tracknumber"] = "0"
    m["genre"] = ""
    m["date"] = ""
    m.save()