コード例 #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))
コード例 #5
0
ファイル: id3_frames_gen.py プロジェクト: quodlibet/mutagen
"""
./id3_frames_gen.py > api/id3_frames.rst
"""

import sys
import os

sys.path.insert(0, os.path.abspath('../'))

import mutagen.id3
from mutagen.id3 import Frames, Frames_2_2, Frame


BaseFrames = dict([(k, v) for (k, v) in vars(mutagen.id3).items()
                   if v not in Frames.values() and v not in Frames_2_2.values()
                   and isinstance(v, type) and
                   (issubclass(v, Frame) or v is Frame)])


def print_header(header, type_="-"):
    print(header)
    print(type_ * len(header))
    print("")


def print_frames(frames, sort_mro=False):
    if sort_mro:
        # less bases first, then by name
        sort_func = lambda x: (len(x[1].__mro__), x[0])
    else:
コード例 #6
0
ファイル: test__id3frames.py プロジェクト: gdelfresno/mutagen
 def test_all_tested(self):
     check = dict.fromkeys(list(Frames.keys()) + list(Frames_2_2.keys()))
     tested = [l[0] for l in self.DATA]
     for t in tested:
         check.pop(t, None)
     self.assertEqual(list(check.keys()), [])
コード例 #7
0
ファイル: test__id3frames.py プロジェクト: gdelfresno/mutagen
 def create_frame_tests(cls):
     for kind in (list(Frames.values()) + list(Frames_2_2.values())):
         new_type = type(cls.__name__ + kind.__name__,
                         (cls, TestCase), {"FRAME": kind})
         assert new_type.__name__ not in globals()
         globals()[new_type.__name__] = new_type