예제 #1
0
 def test_file_md5(self):
     p = os.path.realpath(__file__)
     m1 = mmp.file_md5(p)
     m2 = mmp.file_md5(p, 10)
     self.assertTrue(m1 != m2)
     self.assertRaises(ValueError, lambda: mmp.file_md5('/bull/shit/path'))
     self.assertTrue(m1 == mmp.file_md5(p))
예제 #2
0
 def test_file_md5(self):
     p = os.path.realpath(__file__)
     m1 = mmp.file_md5(p)
     m2 = mmp.file_md5(p,10)
     self.assertTrue( m1 != m2 )
     self.assertRaises( ValueError, lambda : mmp.file_md5('/file/path') )
     self.assertTrue( m1 == mmp.file_md5(p) )
예제 #3
0
    def __init__(self, fpath):
        # Forcing the unicode through
        try    : fpath = fpath.decode("utf-8")
        except : pass

        if not mmp.file_playable(fpath): raise BadSongFile(fpath)

        try              : full_mutagen  = mutagen.File(fpath, easy=True)
        except Exception : raise BadSongFile(fpath)

        self.path = fpath
        if not os.path.exists(self.path):
            self.logger.info("Attempting to read metadata of file \
                    that does not exist. Setting metadata to {}")
            self.__metadata = {}
            return
        # TODO : Simplify the way all of these rules are handled right now it's
        # extremely unclear and needs to be refactored.
        #if full_mutagen is None: raise BadSongFile(fpath)
        if full_mutagen is None: full_mutagen = FakeMutagen(fpath)
        self.__metadata = Metadata.airtime_dict(full_mutagen)
        # Now we extra the special values that are calculated from the mutagen
        # object itself:

        if mmp.extension(fpath) == 'wav':
            full_mutagen.set_length(mmp.read_wave_duration(fpath))

        for special_key,f in airtime_special.iteritems():
            try:
                new_val = f(full_mutagen)
                if new_val is not None:
                    self.__metadata[special_key] = new_val
            except Exception as e:
                self.logger.info("Could not get special key %s for %s" %
                        (special_key, fpath))
                self.logger.info(str(e))
        # Finally, we "normalize" all the metadata here:
        self.__metadata = mmp.normalized_metadata(self.__metadata, fpath)
        # Now we must load the md5:
        # TODO : perhaps we shouldn't hard code how many bytes we're reading
        # from the file?
        self.__metadata['MDATA_KEY_MD5'] = mmp.file_md5(fpath,max_length=100)
예제 #4
0
def load_definitions():
    with md.metadata('MDATA_KEY_DURATION') as t:
        t.default(u'0.0')
        t.depends('length')
        t.translate(lambda k: format_length(k['length']))
        
    with md.metadata('MDATA_KEY_CUE_IN') as t:
        t.default(u'0.0')
        t.depends('cuein')
        t.translate(lambda k: format_length(k['cuein']))

    with md.metadata('MDATA_KEY_CUE_OUT') as t:
        t.default(u'0.0')
        t.depends('cueout')
        t.translate(lambda k: format_length(k['cueout']))

    with md.metadata('MDATA_KEY_MIME') as t:
        t.default(u'')
        t.depends('mime')
        # Is this necessary?
        t.translate(lambda k: k['mime'].replace('audio/vorbis','audio/ogg'))

    with md.metadata('MDATA_KEY_BITRATE') as t:
        t.default(u'')
        t.depends('bitrate')
        t.translate(lambda k: k['bitrate'])
        t.max_value(MAX_SIGNED_INT)

    with md.metadata('MDATA_KEY_SAMPLERATE') as t:
        t.default(u'0')
        t.depends('sample_rate')
        t.translate(lambda k: k['sample_rate'])
        t.max_value(MAX_SIGNED_INT)

    with md.metadata('MDATA_KEY_FTYPE') as t:
        t.depends('ftype') # i don't think this field even exists
        t.default(u'audioclip')
        t.translate(lambda k: k['ftype']) # but just in case

    with md.metadata("MDATA_KEY_CREATOR") as t:
        t.depends("artist")
        # A little kludge to make sure that we have some value for when we parse
        # MDATA_KEY_TITLE
        t.default(u"")
        t.max_length(512)

    with md.metadata("MDATA_KEY_SOURCE") as t:
        t.depends("album")
        t.max_length(512)

    with md.metadata("MDATA_KEY_GENRE") as t:
        t.depends("genre")
        t.max_length(64)

    with md.metadata("MDATA_KEY_MOOD") as t:
        t.depends("mood")
        t.max_length(64)

    with md.metadata("MDATA_KEY_TRACKNUMBER") as t:
        t.depends("tracknumber")
        t.max_value(MAX_SIGNED_INT)

    with md.metadata("MDATA_KEY_BPM") as t:
        t.depends("bpm")
        t.max_value(MAX_SIGNED_INT)

    with md.metadata("MDATA_KEY_LABEL") as t:
        t.depends("organization")
        t.max_length(512)

    with md.metadata("MDATA_KEY_COMPOSER") as t:
        t.depends("composer")
        t.max_length(512)

    with md.metadata("MDATA_KEY_ENCODER") as t:
        t.depends("encodedby")
        t.max_length(512)

    with md.metadata("MDATA_KEY_CONDUCTOR") as t:
        t.depends("conductor")
        t.max_length(512)

    with md.metadata("MDATA_KEY_YEAR") as t:
        t.depends("date")
        t.max_length(16)

    with md.metadata("MDATA_KEY_URL") as t:
        t.depends("website")

    with md.metadata("MDATA_KEY_ISRC") as t:
        t.depends("isrc")
        t.max_length(512)

    with md.metadata("MDATA_KEY_COPYRIGHT") as t:
        t.depends("copyright")
        t.max_length(512)

    with md.metadata("MDATA_KEY_ORIGINAL_PATH") as t:
        t.depends('path')
        t.translate(lambda k: unicode(normpath(k['path'])))

    with md.metadata("MDATA_KEY_MD5") as t:
        t.depends('path')
        t.optional(False)
        t.translate(lambda k: file_md5(k['path'], max_length=100))

    # owner is handled differently by (by events.py)

    # MDATA_KEY_TITLE is the annoying special case b/c we sometimes read it
    # from file name


    # must handle 3 cases:
    # 1. regular case (not recorded + title is present)
    # 2. title is absent (read from file)
    # 3. recorded file
    def tr_title(k):
        #unicode_unknown = u"unknown"
        new_title = u""
        if is_airtime_recorded(k) or k['title'] != u"":
            new_title = k['title']
        else:
            default_title = no_extension_basename(k['path'])
            default_title = re.sub(r'__\d+\.',u'.', default_title)

            # format is: track_number-title-123kbps.mp3
            m = re.match(".+?-(?P<title>.+)-(\d+kbps|unknown)$", default_title)
            if m: new_title = m.group('title')
            else: new_title = re.sub(r'-\d+kbps$', u'', default_title)

        return new_title

    with md.metadata('MDATA_KEY_TITLE') as t:
        # Need to know MDATA_KEY_CREATOR to know if show was recorded. Value is
        # defaulted to "" from definitions above
        t.depends('title','MDATA_KEY_CREATOR','path')
        t.optional(False)
        t.translate(tr_title)
        t.max_length(512)

    with md.metadata('MDATA_KEY_LABEL') as t:
        t.depends('label')
        t.max_length(512)
예제 #5
0
with md.metadata("MDATA_KEY_ISRC") as t:
    t.depends("isrc")
    t.max_length(512)

with md.metadata("MDATA_KEY_COPYRIGHT") as t:
    t.depends("copyright")
    t.max_length(512)

with md.metadata("MDATA_KEY_FILEPATH") as t:
    t.depends('path')
    t.translate(lambda k: normpath(k['path']))

with md.metadata("MDATA_KEY_MD5") as t:
    t.depends('path')
    t.optional(False)
    t.translate(lambda k: file_md5(k['path'], max_length=100))

# owner is handled differently by (by events.py)

with md.metadata('MDATA_KEY_ORIGINAL_PATH') as t:
    t.depends('original_path')

# MDATA_KEY_TITLE is the annoying special case
with md.metadata('MDATA_KEY_TITLE') as t:
    # Need to know MDATA_KEY_CREATOR to know if show was recorded. Value is
    # defaulted to "" from definitions above
    t.depends('title','MDATA_KEY_CREATOR')
    t.max_length(512)

with md.metadata('MDATA_KEY_LABEL') as t:
    t.depends('label')
예제 #6
0
def load_definitions():
    with md.metadata('MDATA_KEY_DURATION') as t:
        t.default(u'0.0')
        t.depends('length')
        t.translate(lambda k: format_length(k['length']))

    with md.metadata('MDATA_KEY_CUE_IN') as t:
        t.default(u'0.0')
        t.depends('cuein')
        t.translate(lambda k: format_length(k['cuein']))

    with md.metadata('MDATA_KEY_CUE_OUT') as t:
        t.default(u'0.0')
        t.depends('cueout')
        t.translate(lambda k: format_length(k['cueout']))

    with md.metadata('MDATA_KEY_MIME') as t:
        t.default(u'')
        t.depends('mime')
        # Is this necessary?
        t.translate(lambda k: k['mime'].replace('audio/vorbis', 'audio/ogg'))

    with md.metadata('MDATA_KEY_BITRATE') as t:
        t.default(u'')
        t.depends('bitrate')
        t.translate(lambda k: k['bitrate'])
        t.max_value(MAX_SIGNED_INT)

    with md.metadata('MDATA_KEY_SAMPLERATE') as t:
        t.default(u'0')
        t.depends('sample_rate')
        t.translate(lambda k: k['sample_rate'])
        t.max_value(MAX_SIGNED_INT)

    with md.metadata('MDATA_KEY_FTYPE') as t:
        t.depends('ftype')  # i don't think this field even exists
        t.default(u'audioclip')
        t.translate(lambda k: k['ftype'])  # but just in case

    with md.metadata("MDATA_KEY_CREATOR") as t:
        t.depends("artist")
        # A little kludge to make sure that we have some value for when we parse
        # MDATA_KEY_TITLE
        t.default(u"")
        t.max_length(512)

    with md.metadata("MDATA_KEY_SOURCE") as t:
        t.depends("album")
        t.max_length(512)

    with md.metadata("MDATA_KEY_GENRE") as t:
        t.depends("genre")
        t.max_length(64)

    with md.metadata("MDATA_KEY_MOOD") as t:
        t.depends("mood")
        t.max_length(64)

    with md.metadata("MDATA_KEY_TRACKNUMBER") as t:
        t.depends("tracknumber")
        t.max_value(MAX_SIGNED_INT)

    with md.metadata("MDATA_KEY_BPM") as t:
        t.depends("bpm")
        t.max_value(MAX_SIGNED_INT)

    with md.metadata("MDATA_KEY_LABEL") as t:
        t.depends("organization")
        t.max_length(512)

    with md.metadata("MDATA_KEY_COMPOSER") as t:
        t.depends("composer")
        t.max_length(512)

    with md.metadata("MDATA_KEY_ENCODER") as t:
        t.depends("encodedby")
        t.max_length(512)

    with md.metadata("MDATA_KEY_CONDUCTOR") as t:
        t.depends("conductor")
        t.max_length(512)

    with md.metadata("MDATA_KEY_YEAR") as t:
        t.depends("date")
        t.max_length(16)

    with md.metadata("MDATA_KEY_URL") as t:
        t.depends("website")

    with md.metadata("MDATA_KEY_ISRC") as t:
        t.depends("isrc")
        t.max_length(512)

    with md.metadata("MDATA_KEY_COPYRIGHT") as t:
        t.depends("copyright")
        t.max_length(512)

    with md.metadata("MDATA_KEY_ORIGINAL_PATH") as t:
        t.depends('path')
        t.translate(lambda k: unicode(normpath(k['path'])))

    with md.metadata("MDATA_KEY_MD5") as t:
        t.depends('path')
        t.optional(False)
        t.translate(lambda k: file_md5(k['path'], max_length=100))

    # owner is handled differently by (by events.py)

    # MDATA_KEY_TITLE is the annoying special case b/c we sometimes read it
    # from file name

    # must handle 3 cases:
    # 1. regular case (not recorded + title is present)
    # 2. title is absent (read from file)
    # 3. recorded file
    def tr_title(k):
        #unicode_unknown = u"unknown"
        new_title = u""
        if is_airtime_recorded(k) or k['title'] != u"":
            new_title = k['title']
        else:
            default_title = no_extension_basename(k['path'])
            default_title = re.sub(r'__\d+\.', u'.', default_title)

            # format is: track_number-title-123kbps.mp3
            m = re.match(".+?-(?P<title>.+)-(\d+kbps|unknown)$", default_title)
            if m: new_title = m.group('title')
            else: new_title = re.sub(r'-\d+kbps$', u'', default_title)

        return new_title

    with md.metadata('MDATA_KEY_TITLE') as t:
        # Need to know MDATA_KEY_CREATOR to know if show was recorded. Value is
        # defaulted to "" from definitions above
        t.depends('title', 'MDATA_KEY_CREATOR', 'path')
        t.optional(False)
        t.translate(tr_title)
        t.max_length(512)

    with md.metadata('MDATA_KEY_LABEL') as t:
        t.depends('label')
        t.max_length(512)