読者です 読者をやめる 読者になる 読者になる

キリッとガジェット

Android,ガジェット系の記事が多めの個人ブログ.

ブログ移行しました。こちらへどうぞ!

walkman対応のmp3タグを書き込む【eyeD3】

最近、Raspberry Piで超A&Gを録音(AAC-LC)→ffmpegでmp3に変換→dropboxにアップロードしています。非常に便利なのですが、ffmpegでid3タグをつけるとwalkmanで認識されません。
(ちなみにA&Gで録ったAAC-LCはwalkmanでは再生すらできない…)

radikoのflvから取り出したAACはなぜiTunesで読めないのか? - ザリガニが見ていた...。

walkmanで使えるmp3タグ

設定メモ: walkmanのid3tag

結論から言うとid3v2.3、utf16しか使えません。さすがソニー、守備範囲狭すぎですね。

eyeD3で書き込む

  • cliで使える
  • id3のバージョンを指定できる
  • 簡単そう(apt−getで入る)

で探したらeyeD3がありました。
pythonで動いてるらしいですがよく知りません(適当)。

eyeD3でID3タグを編集する - ろくなもの入れ

とりあえず使ってみます。

$ sudo apt-get install eyeD3
$ eyeD3 -a [artist] -A [album] -t [title] example.mp3

上のような引数で使えます。
が、普通に使うとid3v2.4、Latin-1で書き込もうとするので日本語だとエラーになります。

$ eyeD3 -a 今井麻美 example.mp3

example.mp3     [ 12.02 MB ]
-------------------------------------------------------------------------------
Time: 30:00     MPEG2, Layer III        [ 56 kb/s @ 24000 Hz - Joint stereo ]
-------------------------------------------------------------------------------
No ID3 v1.x/v2.x tag found!
Setting artist: 今井麻美
Writing tag...
Uncaught exception: 'latin-1' codec can't encode characters in position 0-3: ordinal not in range(256)
Traceback (most recent call last):
  File "/usr/bin/eyeD3", line 1265, in <module>
    retval = main();
  File "/usr/bin/eyeD3", line 1242, in main
    retval = app.handleFile(f);
  File "/usr/bin/eyeD3", line 559, in handleFile
    if not self.tag.update():
  File "/usr/lib/python2.7/dist-packages/eyeD3/tag.py", line 526, in update
    self.__saveV2Tag(version);
  File "/usr/lib/python2.7/dist-packages/eyeD3/tag.py", line 1251, in __saveV2Tag
    raw_frame = f.render();
  File "/usr/lib/python2.7/dist-packages/eyeD3/frames.py", line 756, in render
    self.text.encode(id3EncodingToString(self.encoding));
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-3: ordinal not in range(256)

id3v2.3とutf16を指定します。

$ eyeD3 --to-v2.3 --set-encoding=utf16-BE -a 今井麻美  example.mp3

example.mp3     [ 12.02 MB ]
-------------------------------------------------------------------------------
Time: 30:00     MPEG2, Layer III        [ 56 kb/s @ 24000 Hz - Joint stereo ]
-------------------------------------------------------------------------------
No ID3 v1.x/v2.x tag found!
Converting tag to ID3 v2.3
Setting artist: 今井麻美
Writing tag...
ID3 v2.3:
title:          artist: 今井麻美
album:          year: None
track:

UserTextFrame: [Description: Tagging time]
2015-04-25T13:01:01

あとで気がついたのですがutf16は5種類ほど存在するようです。穏やかじゃないね。
ちなみにffmpegでm4a(AAC-LC)をmp3に変換すると空のid3v2.4がくっついてくるので消しています。ffmpegで消せるのだろうけどわからないのです。

$ eyeD3 --remove-all example.mp3

example.mp3     [ 12.02 MB ]
-------------------------------------------------------------------------------
Time: 30:00     MPEG2, Layer III        [ 56 kb/s @ 24000 Hz - Joint stereo ]
-------------------------------------------------------------------------------
Removing ID3 v1.x and/or v2.x tag: SUCCESS

参考

他にも色々できます。アルバムアートが入れられるのは便利かも。

$ eyeD3 --h

Usage
  eyeD3 [OPTS] file [file...]

Options
=======
  --version             show program's version number and exit
  -h, --help            show this help message and exit

Tag Versions
------------
    -1, --v1            Only read/write ID3 v1.x tags. By default, v1.x tags
                        are only read if there is not a v2.x tag.
    -2, --v2            Only read/write ID3 v2.x tags.
    --to-v1.1           Convert the file's tag to ID3 v1.1. (Or 1.0 if there is
                        no track number.)
    --to-v2.3           Convert the file's tag to ID3 v2.3
    --to-v2.4           Convert the file's tag to ID3 v2.4

Tag Data
--------
    -a STRING, --artist=STRING
                        Set artist
    -A STRING, --album=STRING
                        Set album
    -t STRING, --title=STRING
                        Set title
    -n NUM, --track=NUM
                        Set track number
    -N NUM, --track-total=NUM
                        Set total number of tracks
    -G GENRE, --genre=GENRE
                        Set genre. The argument is a valid genre string or
                        number.  See --list-genres
    -d NUM, --disc=NUM  Set disc number
    -D NUM, --disc-total=NUM
                        Set total number of discs
    -Y STRING, --year=STRING
                        Set a four digit year.
    -c [LANGUAGE]:[DESCRIPTION]:COMMENT, --comment=[LANGUAGE]:[DESCRIPTION]:COMMENT
                        Set comment
    -L [LANGUAGE]:[DESCRIPTION]:LYRICS, --lyrics=[LANGUAGE]:[DESCRIPTION]:LYRICS
                        Set lyrics
    -p STRING, --publisher=STRING
                        Set the publisher/label text
    --remove-comments   Remove all comment frames.
    --remove-lyrics     Remove all lyrics frames.
    --add-image=IMG_PATH:TYPE[:DESCRIPTION]
                        Add an image to the tag.  The description and type
                        optional, but when used, both ':' delimiters must be
                        present.  The type MUST be an string that corresponds
                        to one given with --list-image-types. If the IMG_PATH
                        value is empty the APIC frame with TYPE is removed.
    --remove-images     Remove all image (APIC) frames.
    --add-object=OBJ_PATH[:DESCRIPTION[:MIME-TYPE[:FILENAME]]
                        Add an encapsulated object to the tag.  The description
                        and filename are optional, but when used, the ':'
                        delimiters must be present.  If the OBJ_PATH value is
                        empty the GEOB frame with DESCRIPTION is removed.
    -i DIR, --write-images=DIR
                        Causes all attached images (APIC frames) to be written
                        to the specified directory.
    -o DIR, --write-objects=DIR
                        Causes all attached objects (GEOB frames) to be written
                        to the specified directory.
    --set-text-frame=FID:TEXT
                        Set the value of a text frame.  To remove the frame,
                        specify an empty value.  e.g., --set-text-frame="TDRC:"
    --set-user-text-frame=DESC:TEXT
                        Set the value of a user text frame (i.e., TXXX). To
                        remove the frame, specify an empty value.  e.g., --set-
                        user-text-frame="SomeDesc:"
    --set-url-frame=FID:URL
                        Set the value of a URL frame.  To remove the frame,
                        specify an empty value.  e.g., --set-url-frame="WCOM:"
    --set-user-url-frame=DESC:URL
                        Set the value of a user URL frame (i.e., WXXX). To
                        remove the frame, specify an empty value.  e.g., --set-
                        user-url-frame="SomeDesc:"
    --play-count=[+]N   If this argument value begins with '+' the tag's play
                        count (PCNT) is incremented by N, otherwise the value
                        is set to exactly N.
    --bpm=N             Set the beats per minute value.
    --unique-file-id=OWNER_ID:ID
                        Add a UFID frame.  If the ID arg is empty the UFID
                        frame with OWNER_ID is removed.  An OWNER_ID MUST be
                        specified.
    --set-encoding=latin1|utf8|utf16-BE|utf16-LE
                        Set the encoding that is used for _all_ text frames.
                        This only takes affect when the tag is updated as the
                        result of a frame value being set with another option
                        (e.g., --artist=) or --force-update is present.
    --remove-v1         Remove ID3 v1.x tag.
    --remove-v2         Remove ID3 v2.x tag.
    --remove-all        Remove both ID3 v1.x and v2.x tags.

Misc. Options
-------------
    --rename=NAME       Rename file (the extension is not affected) based on
                        data in the tag using substitution variables: %A
                        (artist), %a (album), %t (title), %n (track number),
                        and %N (total number of tracks)
    --fs-encoding=ENCODING
                        Use the specified character encoding for the filename
                        when renaming files
    -l, --list-genres   Display the table of ID3 genres and exit
    --list-image-types  List all possible image types
    --strict            Fail for tags that violate the ID3 specification.
    --itunes            Store tags in an iTunes compatible way.
    --jep-118           Output the tag per the format described in JEP-0118.
                        See http://www.xmpp.org/extensions/xep-0118.html
    --rfc822            Output the tag in RFC822-like format
    --nfo               Output NFO information.
    --lametag           Prints the LAME Tag.
    --force-update      Update the tag regardless of whether any frames are set
                        with new values.
    --no-color          Disable color output
    --no-zero-padding   Don't pad track or disc numbers with 0's
    --no-tagging-time-frame
                        When saving tags do not add a TDTG (tagging time) frame
    -F DELIM            Specify a new delimiter for option values that contain
                        multiple fields (default delimiter is ':')
    -v, --verbose       Show all available information
    --debug             Trace program execution.
    --run-profiler      Run using python profiler.