mkogg.py: Fix 'self.get_mp4_metadata(self, source)'
[blog.git] / posts / Mutagen.mdwn
1 I just switched to [Mutagen][] as the metadata handler for my
2 [[mkogg]] utility.  I used to use [metaflac][] and [id3v2][], but ran
3 up against limitations discussed on the `mkogg` page.  Here's a quick
4 note on using Mutagen to set some [ID3][] tags:
5
6     >>> from mutagen.mp3 import MP3
7     >>> import mutagen.id3
8     >>> audio = MP3('some_file.mp3')
9     >>> audio['TIT2'] = TIT2(encoding=3, text=["Title"])
10     >>> audio.save(v1=2)  # also include ID3v1 tags, when possible
11
12 ID3v2 encodings are hardcoded to the [following table][encodings]:
13
14 <table>
15   <thead>
16     <tr><td>Value</td><td>Encoding</td></tr>
17   </thead>
18   <tbody>
19     <tr><td>0</td><td>ISO-8859-1 (ASCII)</td></tr>
20     <tr><td>1</td><td>UCS-2 in ID3v2.2 and ID3v2.3, UTF-16 encoded Unicode with BOM.</td></tr>
21     <tr><td>2</td><td>UTF-16BE encoded Unicode without BOM in ID3v2.4 only.</td></tr>
22     <tr><td>3</td><td>UTF-8 encoded Unicode in ID3v2.4 only.</td></tr>
23   </tbody>
24 </table>
25
26 In order to get ID3v1 tags, you'll need to use frames and encodings
27 that ID3v1 understands.  For encodings, that means `0` (ISO-8859-1).
28
29 [Mutagen]: http://code.google.com/p/mutagen/
30 [metaflac]: http://flac.sourceforge.net/documentation_tools_metaflac.html
31 [id3v2]: http://id3v2.sourceforge.net/
32 [ID3]: http://en.wikipedia.org/wiki/ID3
33 [encodings]: http://en.wikipedia.org/wiki/ID3#ID3v2
34
35 [[!tag tags/python]]
36 [[!tag tags/tools]]