Python - 如何添加初始 MP3 属性

标签 python python-2.7 mp3

我曾经在文件名中获取带有艺术家和歌曲名称的歌曲(例如 - “布兰妮斯 PIL 斯 - 哎呀我又做了一次”。 我的脚本有两个目的: 1.将艺术家姓名和歌曲添加到他的 MP3 属性中(使用 eyed3)。 2.在我的主音乐文件夹中为艺术家创建一个新文件夹(如果我还没有)。

我的问题是,如果 MP3 文件没有属性,我就不能添加新的..

这是我的代码(这是我的第一个 :-))..谢谢!

#That's the 0.2 ver of my code
import os
import shutil
import eyed3.id3

songs_path = raw_input("Please insert the path of your Songs: ")
music_path = raw_input("Please insert the path of your music folders location: ")

#That's function supposed to present the files in a path
def files_in_folder(m):
    Files = os.listdir(m)
    return Files

mp3_files_list = files_in_folder(downloads_path)
artist_list = files_in_folder(music_path)

for i in mp3_files_list:
    song_artist, song_title = i.split(' - ')
    if not os.path.exists(music_path + '\\' + song_artist):
        os.mkdir(music_path + '\\' + song_artist, 0777 )
    src_file = os.path.join(downloads_path, i)
    dst_file = os.path.join(music_path + '\\' + song_artist + '\\' + song_title)
    print src_file
    print dst_file
    shutil.move(src_file, dst_file)
    track_mp3_file = eyed3.load(dst_file)
    if track_mp3_file.tag is None:
        track_mp3_file.tag = eyed3.id3.Tag()
        track_mp3_file.tag.file_info = eyed3.id3.FileInfo(dst_file)
    track_mp3_file.tag.artist = unicode(song_artist, "UTF-8")
    print track_mp3_file.tag.artist
    track_mp3_file.tag.title = unicode(song_title, "UTF-8")
    track_mp3_file.tag.save()

最佳答案

尝试用另一个 id3 版本保存标签:

track_mp3_file.tag.save(version=(2, 3, 0))

来自维基百科:

Windows Explorer and Windows Media Player cannot handle ID3v2.4 tags in any version, up to and including Windows 8 / Windows Media Player 12. Windows can understand ID3v2 up to and including version 2.3

关于Python - 如何添加初始 MP3 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29542819/

相关文章:

python - 如果项目位于表中,则返回该项目在表中的位置。 [Py 3.4]

python - Django选择最大ID

python - 将关键字(字符串)与 Pandas 数据框匹配

iphone - 从哪里开始制作将 MP3 文件转换为 iphone 有声读物 (M4B) 格式的程序?

c# - 用于编辑音频的 .NET 库

python - 如何根据 Google Sheets API 正确打印对象列表属性?

python - for循环被用作while循环(python)

python - 如何在 Ubuntu docker 镜像中安装 Python2.7.5?

python - 函数参数类型设置返回 SyntaxError

c# - 获取mp3文件长度