From 2f06a508bd0e0ca7b9a5bb124b007cdb51ebd3e0 Mon Sep 17 00:00:00 2001 From: Dave Hayes Date: Mon, 28 Jan 2013 14:05:34 -0600 Subject: [PATCH] Implements support for WMA/ASF * Adds support for importing/managing .wma and .asf files * Adds support for all available ASF tag equivalents * Adds two utility methods for (un)packing embedded ASF pictures * Modifies scrub plugin to work around the lack of a delete method on ASFTags object. --- beets/mediafile.py | 161 +++++++++++++++++++++++++++++++++++++-------- beetsplug/scrub.py | 6 +- 2 files changed, 140 insertions(+), 27 deletions(-) diff --git a/beets/mediafile.py b/beets/mediafile.py index 611876280..ef2d53c58 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' } @@ -139,6 +142,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("