Esempio n. 1
0
def _format(self, filename=None, base=None, preadd=(), postadd=()):
    filename, base = from_config('filename', 'base')
    meta = NormMetaData(preadd)
    meta.update(self.meta.flat())
    meta.update(postadd)
    filename = FileFormat(filename)
    base = os.path.abspath(base)
    return os.path.join(base, filename.evaluate(meta))
Esempio n. 2
0
def _get_meta(self):
    metacache = getattr(self, '_meta_cache', (False, False))
    if metacache[0] is not getattr(self, 'filename', None) or metacache[1] \
       is not getattr(self, 'tags', None):
        self._meta_cache = (getattr(self, 'filename', None),
           getattr(self, 'tags', None))
        if getattr(self, 'tags', None) is None:
            meta = NormMetaData()
        else:
            meta = NormMetaData.converted(self)
        path = getattr(self, 'filename', None)
        if isinstance(path, basestring):
            (meta['dir'], meta['name']) = os.path.split(path)
            meta['path'] = path
            meta['basename'] = os.path.splitext(meta['name'])[0]
        relpath = getattr(self, 'relpath', None)
        if isinstance(relpath, basestring):
            meta['relpath'] = relpath.decode(Config['fs_encoding'], Config['fs_encoding_err'] or 'replace')
        reldir = getattr(self, 'reldir', None)
        if isinstance(reldir, basestring):
            meta['reldir'] = reldir.decode(Config['fs_encoding'], Config['fs_encoding_err'] or 'replace')
        ext = getattr(self, 'ext', None)
        if ext is not None:
            meta['ext'] = ext
        type_ = getattr(self, 'type_', None)
        if type_ is not None:
            meta['type'] = type_
        self._meta = meta
    return getattr(self,'_meta')
Esempio n. 3
0
 def add_replaygain(cls, files, metas=()):
     env = {"replaygain": cls.replaygain, "files": tuple(files)}
     if hasattr(cls, "replaygain_cmd") and (not metas or not hasattr(cls, "calc_replaygain")):
         task = CLITask(*cls.replaygain_cmd.evaluate(env))
         yield task
     elif hasattr(cls, "calc_replaygain"):
         task = CLITask(*cls.calc_replaygain_cmd.evaluate(env))
         output = yield task
         tracks, album = cls.calc_replaygain(output)
         if metas:
             for meta, track_gain in zip(metas, tracks):
                 meta.update(track_gain + album)
             yield metas
         else:
             file_objs = [File(f) for f in files]
             for file_obj, trackfile, trackgain in zip(file_objs, tracks):
                 meta = NormMetaData(trackgain + album)
                 meta.apply(file_obj)
                 f.save()
Esempio n. 4
0
def _set_meta(self, value):
    NormMetaData.converted(value).apply(self, True)