def get_metadata(full_path):
    metadata = {
        'filename': os.path.basename(full_path)[:-4],
    }
    
    if full_path.endswith('mp4') or full_path.endswith('m4a'):
        id3_cls = EasyMP4
    elif full_path.endswith('mp3'):
        id3_cls = EasyMP3
    else:
        id3_cls = None
    
    if id3_cls:
        try:
            audio = id3_cls(full_path)
        except Exception, e:
            print e
            audio = None
    
        if audio:
            for key in ('artist', 'title', 'album', 'genre'):
                try:
                    value = unicode(audio[key][0])
                except (IndexError, __HOLE__):
                    continue

                metadata[key] = value

            metadata['length'] = audio.info.length
    
    return metadata
dataset/ETHPy150Open disqus/playa/playa/ext/audio/index.py/get_metadata