예제 #1
0
파일: mp3md.py 프로젝트: funkwit/mp3md
  def try_fix(self, directory, valid_files, to_fix, errors):
    for file, tag in to_fix:
      try:
        source = Check.get_value(tag, self.from_frame)
        match = re.search(self.regex, source)
        if not match:
          errors.record(file, "FIXERROR", "Cannot move value from frame %s as does not match regex %s" % (self.from_frame, self.regex))
          break

        replace_value = match.group(self.match_group)
        existing_value = Check.get_value(tag, self.to_frame)
        if existing_value:
          if not self.overwrite:
            errors.record(file, "FIXERROR", "Could not copy value '%s' from frame %s; destination frame %s already has value '%s' and overwrite=False" % (replace_value, self.from_frame, self.to_frame, existing_value))
            break

        tag.delall(self.to_frame)
        tag.delall(self.from_frame)
        replace_from = re.sub(self.regex, "", source)

        frame = Frames.get(self.to_frame)(encoding=3, text=replace_value)
        tag.add(frame)
        frame = Frames.get(self.from_frame)(encoding=3, text=replace_from)
        tag.add(frame)
        tag.save()
        errors.record(file, "FIXED", "Value '%s' moved from frame %s to %s" % (replace_value, self.from_frame, self.to_frame))
      except object, e:
        errors.record(file, "FIXERROR", "Could not move regex %s from frame %s to frame %s: %s" % (self.refex, self.from_frame, self.to_frame, e))
예제 #2
0
파일: mp3md.py 프로젝트: funkwit/mp3md
  def try_fix(self, directory, valid_files, to_fix, errors):
    values = []
    for (file, tag) in valid_files:
      values.append(Check.get_value(tag, self.source))
    if len(values) == 0:
      for (file, tag) in to_fix:
        errors.record(file, "FIXERROR", "No valid source values for tag %s" % self.source)
      
    counter = {}
    for value in values: counter[value] = counter.get(value, 0) + 1    
    top = sorted([ (freq,word) for word, freq in counter.items() ], reverse=True)[0]
    top_value = top[1]
    top_freq = top[0]
    outliers = len(valid_files) - top_freq
    permitted_outliers = 0 if self.outliers == 0 else self.outliers if self.outliers >= 1 else max(int(self.outliers * len(valid_files)), 1)

    for (file, tag) in to_fix:
      if outliers > permitted_outliers:
        errors.record(file, "FIXERROR", "Too many outliers from %s: %s (max %s)" % (top_value, outliers, permitted_outliers))
      else:
        try:
          frame = Frames.get(self.target)(encoding=3, text=top_value)
          tag.add(frame)
          tag.save() 
          errors.record(file, "FIX", "Fixed: set field %s to \"%s\"" % (self.target, top_value))
        except object, e:
          errors.record(file, "FIXERROR", "Could not save %s" % e)
예제 #3
0
파일: mp3md.py 프로젝트: funkwit/mp3md
 def try_fix(self, directory, valid_files, to_fix, errors):
   for file, tag in to_fix:
     try:
       tag.delall(self.frametype)
       frame = Frames.get(self.frametype)(encoding=3, text=self.value)
       tag.add(frame)
       tag.save() 
       errors.record(file, "FIXED", "Frame %s set to '%s'" % (self.frametype, self.value))
     except object, e:
       errors.record(file, "FIXERROR", "Could not set frame %s to '%s': %s" % (self.frametype, self.value, e))
예제 #4
0
파일: mp3md.py 프로젝트: funkwit/mp3md
 def try_fix(self, directory, valid_files, to_fix, errors):
   for file, tag in to_fix:
     try:
       artist = Check.get_value(tag, 'TPE1') 
       title = Check.get_value(tag, 'TIT2')
       search_string = " - " + artist
       newtitle = title.replace(search_string, "")
       tag.delall('TIT2')
       frame = Frames.get('TIT2')(encoding=3, text=newtitle)
       tag.add(frame)
       tag.save() 
       errors.record(file, "FIXED", "Title set to '%s'" % (newtitle))
     except object, e:
       errors.record(file, "FIXERROR", "Could not set title to '%s': %s" % (newtitle, e))