diff --git a/beets/mediafile.py b/beets/mediafile.py index 611876280..dfc6a3dd5 100644 --- a/beets/mediafile.py +++ b/beets/mediafile.py @@ -34,9 +34,11 @@ import mutagen.oggvorbis import mutagen.mp4 import mutagen.flac import mutagen.monkeysaudio +import mutagen.asf import datetime import re import base64 +import struct import imghdr import os import logging @@ -72,6 +74,7 @@ TYPES = { 'ape': 'APE', 'wv': 'WavPack', 'mpc': 'Musepack', + 'asf': 'Windows Media' } @@ -105,8 +108,11 @@ def _safe_cast(out_type, val): return False else: try: - # Should work for strings, bools, ints: - return bool(int(val)) + if isinstance(val, mutagen.asf.ASFBoolAttribute): + return bool(val) + else: + # Should work for strings, bools, ints: + return bool(int(val)) except ValueError: return False @@ -139,6 +145,44 @@ def _safe_cast(out_type, val): return val +def unpack_image(data): + """ + Helper function to unpack image data from a WM/Picture tag. + + The data has the following format: + 1 byte: Picture type (0-20), see ID3 APIC frame specification at http://www.id3.org/id3v2.4.0-frames + 4 bytes: Picture data length in LE format + MIME type, null terminated UTF-16-LE string + Description, null terminated UTF-16-LE string + The image data in the given length + """ + (type, size) = struct.unpack_from("