For my media server, I am looking for ways to transfer tags from my FLAC files to MP3.

In a bash script, I can extract tags using metaflac to local vars, but when tagging mp3 with id3v2, I seem to lose national characters (guess it must be unicode?)

Also I need to be able to set replay gain tags, and album art (all present in the FLAC's).

I am looking for a scripted solution to run unattended.

有帮助吗?

解决方案

Try this tool eyed3. It supports album art embedding, text encoding in latin1, utf8, utf16-BE and utf16-LE. However the replay gain is not supported. As far as I understand it is not widely supported.

其他提示

If you are interested in a Python solution, the mutagen library looks really good.

It could be as easy as:

from mutagen.flac import FLAC
from mutagen.easyid3 import EasyID3

flacfile = FLAC("flacfile.flac")
mp3file = EasyID3("mp3file.mp3")

for tag in flacfile:
    if tag in EasyID3.valid_keys.keys():
        mp3file[tag] = flacfile[tag]

mp3file.save()

I found this solution for copying mp3 id3 tags into FLAC files.

Victor's solution showed me the way. It may fail, however, if copying tags to a file you've just converted, for example, from flac to mp3. That is, it will fail if the file you are copying tags to doesn't already have any tags.

So you may need to prime the destination file first, giving it the means to have tags.

from mutagen import File
from mutagen.flac import FLAC
from mutagen.easyid3 import EasyID3
from mutagen.id3 import ID3, ID3NoHeaderError

def convert_tags(f1,f2):
    # f1: full path to file copying tags from
    # f2: full path to file copying tags to
    # http://stackoverflow.com/questions/8873364/linux-script-to-transfer-id3-tags-from-flac-to-mp3
    # http://stackoverflow.com/a/18369606/2455413
    try:
        meta = EasyID3(f2)
    except ID3NoHeaderError:
        meta = File(f2, easy=True)
        meta.add_tags()
        meta.save()
    from_f = FLAC(f1)
    to_f = EasyID3(f2)
    for tag in from_f:
        if tag in EasyID3.valid_keys.keys(): to_f[tag] = from_f[tag]
    to_f.save()
    return
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top