pátek 19. dubna 2013

Simple iTunes Cleaner

This script cleans track names, album names etc. in an iTunes library using regular expressions. Select all song you want to check and fix and run the script. Uncomment the last line if you like what you se in your console. Caution: there is no "Undo" in iTunes. Changes are irreversible. Make a backup. Please, send me your regular expressions or your other suggestions.

import re
import win32com.client
cleaner = [
  ["Name Album Artist AlbumArtist Composer Genre", r"^\s+", r""],
  ["Name Album Artist AlbumArtist Composer Genre", r"\s+$", r""],
  ["Name Album Artist AlbumArtist Composer Genre", r"\s+", r" "],
  ["Name Album", r",([^ ])", r", \1"],
  ["Artist AlbumArtist Composer", u"^[vV][aA][rR][iI][oO][uU][sS]$", u"Various Artists"],
]
iTunes = win32com.client.Dispatch("iTunes.Application")
tracks = iTunes.SelectedTracks
for track in tracks:
  for [whereRaw, reA, reB] in cleaner:
    for where in whereRaw.split():
      old = eval("track." + where)
      new = re.sub(reA, reB, old)
      if not old == new:
        print "%s: \"%s\" -> \"%s\"" % (where, old, new)
        #track.__setattr__(where, new)

Žádné komentáře: