如何设置:“艺术家"、“专辑艺术家"、“年份"、“专辑"、“歌曲编号"和“标题"标签的字段,带有诱变剂 [英] How to set: "artist", "album artist", "year", "album", "song number" and "title" fields of the tag, with mutagen

查看:87
本文介绍了如何设置:“艺术家"、“专辑艺术家"、“年份"、“专辑"、“歌曲编号"和“标题"标签的字段,带有诱变剂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 mutagen(使用 Python 2.7.5)来创建一个程序,假设歌曲的路径是 ...\Artist\Year Album\Songnumber Title.mp3, 设置歌曲的艺术家、专辑艺术家、年份、专辑、歌曲编号和标题标签,并保留流派标签.我试图用 EasyID3 做到这一点,但它没有专辑艺术家标签.我也尝试过使用常规的 ID3,但我遇到了一些问题.这是我使用的代码:

from mutagen.id3 import ID3, TIT2, TPE2, TALB, TPE1, TYER, TDAT, TRCK, TCON, TORY, TPUBp = "E:\\Musik\\Aeon\\2005 Bleeding the False\\01 Cenobites - Copy.mp3"音频 = ID3(p)audio.add(TIT2(encoding=3, text=u"t")) #TITLEaudio.add(TRCK(encoding=3, text=u"1")) #TRACKaudio.add(TPE1(encoding=3, text=u"a")) #ARTISTaudio.add(TALB(encoding=3, text=u"al")) #ALBUMaudio.add(TYER(encoding=3, text=u"2000")) #YEARaudio.add(TDAT(encoding=3, text=u"2001")) #YEARaudio.add(TORY(encoding=3, text=u"2002")) #ORIGYEARaudio.add(TPE2(encoding=3, text=u"aa")) #ALBUMARTISTaudio.add(TCON(encoding=3, text=u"g")) #GENRE音频.save()

我使用此表来查找每个标签的 4 个字母代码.>

标题、曲目、艺术家和专辑都运行良好.对于 mp3 文件的属性>详细信息下的所有字段,除了这四个和年份"之外,之前的值都被 save() 清除了,当我尝试添加新的时,什么也没有发生.特别是流派"和专辑艺术家"字段不起作用.至于同时具有 TYER 和 TDAT 代码的年份",除非该字段首先为空,然后仅由 TYER 为空,否则它根本不会改变.代码为 TORY 的ORIGYEAR"什么也没做.

流派"字段实际上并未完全损坏 - 如果您使用 python 代码(audio.add(etc))更改它,或者事先手动进入属性>详细信息,save() 将清除非内置流派,例如技术死亡金属"或mt3jr39kf390",同时它适用于经典摇滚"或乡村"等内置流派,而某些整数例如当 1 或 2 变成那些内置流派.(年份字段有时也有类似的行为 - 如果您手动将字段值设置为某些数字,save() 会将其更改为不同的数字.我只观察到低于 800 的值,但不是所有的——448和449保持不变,而500变成320,700变成448,12变成10,10变成8.如果你这样把12变成10然后再次运行程序,什么都不会发生,但如果您手动将其更改为其他值并返回到 10,它将变为 8.)

所以,问题是,如果那里已经有东西,我无法更改年份标签,我无法更改专辑艺术家或流派标签,并且我不知道如何执行get"命令,如果甚至还有一个这样我就可以保留流派标签.

此外,EasyID3 具有相同的问题 - save() 清除某些字段,并且在流派和年份方面表现得很奇怪.唯一的区别似乎是即使该字段不为空,也可以更改年份.这是我使用的代码:

from mutagen.easyid3 import EasyID3p = "E:\\Musik\\Aeon\\2005 Bleeding the False\\01 Cenobites - Copy.mp3"音频 = EasyID3(p)音频[标题"] = ut"音频[艺术家"] = ua"音频["专辑"] = "al"音频[日期"] = u2000"音频["tracknumber"] = u"1"音频[流派"] = ug"音频.save()打印 '\n'.join(EasyID3.valid_keys.keys())

解决方案

尝试如下保存

audio.save(v2_version=3)

它解决了我的问题.

这是因为 TYER TDAT TORY 是 v2.3 标签,并在 v2.4 中进行了更改来源:https://en.wikipedia.org/wiki/ID3#ID3v2_frame_specification

I'm trying to use mutagen (with Python 2.7.5) to create a program that, given that the path to songs is ...\Artist\Year Album\Songnumber Title.mp3, sets the artist, album artist, year, album, song number and title tags of the song, and preserves the genre tag. I tried to do this with EasyID3, but it doesn't have the album artist tag. I also tried to do it with regular ID3, but I ran into a couple of problems with it. Here's the code I used:

from mutagen.id3 import ID3, TIT2, TPE2, TALB, TPE1, TYER, TDAT, TRCK, TCON, TORY, TPUB
p = "E:\\Musik\\Aeon\\2005 Bleeding the False\\01 Cenobites - Copy.mp3"
audio = ID3(p)
audio.add(TIT2(encoding=3, text=u"t"))    #TITLE
audio.add(TRCK(encoding=3, text=u"1"))    #TRACK
audio.add(TPE1(encoding=3, text=u"a"))    #ARTIST
audio.add(TALB(encoding=3, text=u"al"))   #ALBUM
audio.add(TYER(encoding=3, text=u"2000")) #YEAR
audio.add(TDAT(encoding=3, text=u"2001")) #YEAR
audio.add(TORY(encoding=3, text=u"2002")) #ORIGYEAR
audio.add(TPE2(encoding=3, text=u"aa"))   #ALBUMARTIST
audio.add(TCON(encoding=3, text=u"g"))    #GENRE
audio.save()

I used this table to find the 4-letter codes for each tag.

Title, track, artist and album all worked fine. For all fields under the mp3 file's properties>details except these four and "year", previous values were cleared by save(), and when I tried to add new ones, nothing happened. In particular the "genre" and "album artist" fields didn't work. As for "year" which has both the codes TYER and TDAT, it wouldn't change at all unless the field was empty first, and then only by TYER. "ORIGYEAR" with the code TORY did nothing.

The "genre" field isn't actually completely broken - if you change it with python code (audio.add(etc)), or manually go into properties>details beforehand, save() will clear non-built-in genres such as "Technical Death Metal" or "mt3jr39kf390", while it works with built-in genres such as "Classic Rock" or "Country", while certain integers such as 1 or 2 turn into those built-in genres. (The year field occasionally behaves similarly as well - if you manually set the field value to certain numbers, save() will change it into a different number. I've only observed this for values below 800, but not for all - 448 and 449 remain unchanged, while 500 turns into 320, 700 turns into 448, 12 turns into 10, and 10 turns into 8. If you change 12 to 10 this way and then run the program again, nothing will happen, but if you manually change it to some other value and back to 10, it will turn into 8.)

So, the problem is that I can't change the year tag if there's already something there, I can't change the album artist or genre tag, and I don't know how to do the "get" command if there even is one so I can preserve the genre tag.

Also, EasyID3 has the same issues — save() clears certain fields and behaves weirdly with genre and year. The only difference seems to be that it's possible to change the year even if the field isn't empty. Here's the code I used:

from mutagen.easyid3 import EasyID3
p = "E:\\Musik\\Aeon\\2005 Bleeding the False\\01 Cenobites - Copy.mp3"
audio = EasyID3(p)
audio["title"] = u"t"
audio["artist"] = u"a"
audio["album"] = "al"
audio["date"] = u"2000"
audio["tracknumber"] = u"1"
audio["genre"] = u"g"
audio.save()
print '\n'.join(EasyID3.valid_keys.keys())

解决方案

Try saving as follows

audio.save(v2_version=3)

it fixed the issue in my case.

Edit: it's because TYER TDAT TORY are v2.3 tags and got changed in v2.4 Source: https://en.wikipedia.org/wiki/ID3#ID3v2_frame_specification

这篇关于如何设置:“艺术家"、“专辑艺术家"、“年份"、“专辑"、“歌曲编号"和“标题"标签的字段,带有诱变剂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆