特斯拉车载MP3乱码的问题

修复特斯拉MP3的乱码问题
linux

由于最近车载娱乐包过期了,导致了开车无法听歌,于是就U盘听歌,但是听歌过程中,歌曲名乱码,于是我就开启了折腾之路

尝试修改歌曲中名字特殊符号(不行)

修改特殊符号,比如空格和&,.等等,不好使

修改MP3的TAG(好使)

下面是修复代码

import mutagen
import mutagen.mp3
import mutagen.id3

import os

""" filename 文件路径 source_charset 字符编码 dry_run 是否只是查看 """

def fix_file(filename, source_charset, dry_run): print("Opening file: {}".format(filename)) try: m = mutagen.mp3.Open(filename) except mutagen.mp3.HeaderNotFoundError as e: print("Error opening file {}: {}".format(filename, e)) return

t = m.tags
if t is None:
    print("File {} does not contain ID3 tags.".format(filename))
    return

t.update_to_v24()
for k, v in t.items():
    #        print(k)
    if isinstance(v, mutagen.id3.TextFrame) and not isinstance(v, mutagen.id3.TimeStampTextFrame):
        print(v)
        enc = v.encoding
        old_ts = "".join(v.text)
        print(v.encoding)
        if v.encoding == mutagen.id3.Encoding.LATIN1:
            bs = old_ts.encode("latin1")
            ts = bs.decode('GBK', errors="ignore")
            v.encoding = mutagen.id3.Encoding.UTF16
            v.text = [ts]
            fixed = True
        else:
            ts = old_ts
            fixed = False
        print("  {} Was {}: {} {}".format("*" if fixed else " ", enc, k, ts))
if dry_run:
    print("Dry run. File not saved!")
else:
    t.save(filename)
    print("File {} saved".format(filename))

if name == 'main':

歌曲文件路径

music_path = '/Volumes/新加卷'
for a in os.listdir(music_path):
    p = music_path + "/" + a
    print("---------" + p + "------------")

    if os.path.isdir(p):
        continue
    else:
        sp = os.path.splitext(a)[1]
        if sp == '.mp3':
            fix_file(p, 'GBK', False)

原理分析

特斯拉的音乐播放器的显示的歌曲名字读取的是MP3的文件的TAG信息,下面主要标签信息

TAG备注示例
title歌曲名暗号
artist歌手周杰伦
album专辑八度空间
year年份2007
artwork歌曲图片

效果

bigcong