cc-4105: refactored metadata into it's own file

This commit is contained in:
Rudi Grinberg 2012-07-19 15:41:09 -04:00
parent 09303a96d3
commit 1c09907fd5
5 changed files with 149 additions and 22 deletions

View file

@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
import os
import mutagen
import abc
from media.monitor.exceptions import BadSongFile
from media.monitor.pure import LazyProperty
from media.monitor.monitor import Metadata
class PathChannel(object):
"""a dumb struct; python has no record types"""
@ -13,27 +12,12 @@ class PathChannel(object):
# It would be good if we could parameterize this class by the attribute
# that would contain the path to obtain the meta data. But it would be too much
# work for little reward
# work
class HasMetaData(object):
# TODO : add documentation for HasMetaData
__metaclass__ = abc.ABCMeta
# doing weird bullshit here because python constructors only
# call the constructor of the leftmost superclass.
@LazyProperty
def metadata(self):
# Normally this would go in init but we don't like
# relying on consumers of this behaviour to have to call
# the constructor
try: f = mutagen.File(self.path, easy=True)
except Exception: raise BadSongFile(self.path)
metadata = {}
for k,v in f:
# Special handling of attributes here
if isinstance(v, list):
if len(v) == 1: metadata[k] = v[0]
else: raise Exception("Weird mutagen %s:%s" % (k,str(v)))
else: metadata[k] = v
return metadata
return Metadata(self.path)
class BaseEvent(object):
__metaclass__ = abc.ABCMeta