开发者

Running shell commands from bytes objects in python 3.1 (Or writing UTF-8 mp3 tags in python 3.1)

I'm writing a script which uses .CUE files to split monolithic music files into individual tracks, then encodes them in MP3 along with correct tags from the CUE. It's all working, but unfortunately the tags (applied simply through including them with lame's command line arguments) reliably show up as gibberish in iTunes when they include unicode characters (Which they always do, due to the music being Japanese).

I can fix them by running them through this script, but that's another script to run , and occasionally attaches quote marks to the tags (A bug I have been unable to fix), requiring yet one more run of a script to remove.

So my preferred solution is to encode the lame command + arguments string as UTF-8 before running it, but python 3.1 appears to have no support for r开发者_如何学JAVAunning commands from bytes rather than strings. Simply passing a string instead encodes incorrectly.

Alternatively, I'm happy with simply using a tagging library to insert the tags after the encoding is finished, though a solution like that is slower and less elegant. Any suggestions are welcome, though!

Thanks in advance.

EDIT: I invoke lame like this (sorry for long line):

args = "lame --tt \"{0}\" --tn {1:02d}  --ta \"{2}\" --tl \"{3}\"  \"{4}\" \"{5}.mp3\"".format(item.title, item.tracknumber, item.artist, albumObject.title, item.wavFile, "{0:02d} ".format(item.tracknumber) + item.title)
#args = bytearray(args, "utf-8")
retcode = subprocess.check_call(args)


If you choose to use tagging library you may look at eyeD3; then you could set utf-8 encoded tags as follows:

import eyeD3

tag = eyeD3.Tag ('file.mp3')
tag.setVersion (eyeD3.ID3_V2_4)
tag.setTextEncoding (eyeD3.UTF_8_ENCODING)
tag.setArtist ('artist')
tag.setAlbum ('album')
tag.setTitle ('title')
tag.update ()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜