Example #1
0
def addmetadata(folder, tracklist, metadata, num, discno):
   files = os.listdir(folder)
   
   trackcount = len(tracklist)
   
   for f in files:
      pre, suf = f.rsplit('.', 1)
      numeric = numre.match(pre)
      if suf in endings:
         fullname = os.path.join(folder, f)
         audio = MP3(fullname, ID3=EasyID3)
         if numeric:
            tn = int(numeric.group(1))
            audio['tracknumber'] = str(tn)
         else:
            tn = int(audio["tracknumber"][0].split('/')[0])
         title = tracklist[tn-1][0]
         audio['title'] = unicode(title, 'utf-8')
         audio['artist'] = unicode(metadata[0], 'utf-8')
         audio['album'] = unicode(metadata[1], 'utf-8')
         audio['date'] = unicode(str(metadata[2]), 'utf-8')
         audio['tracknumber'] = unicode("%d/%d" % (tn, trackcount), 'utf-8')
         if len(metadata) == 4:
            audio['genre'] = metadata[3]
         newf = title + os.extsep + suf
         newf = Util.filterchars(newf)
         if num:
            if discno:
               newf = "%d-%s %s" % (discno, str(tn).zfill(2), newf)
            else:
               newf = "%s %s" % (str(tn).zfill(2), newf)
         newpath = os.path.join(folder, newf)
         if len(newpath) > 255:
            title = title[:len(title) - (len(newpath) - 255)]
            newf = title + os.extsep + suf
            newf = Util.filterchars(newf)
            if num:
               newf = "%s %s" % (str(tn).zfill(2), newf)
         audio.save()
         logger.info(newf)
         os.rename(os.path.join(folder, f), os.path.join(folder, newf))
Example #2
0
   album = tracklist[0][1]
if not year:
   year = tracklist[0][2]
tracklist = tracklist[1:]
outputdir = os.path.join(os.environ['MUSIC'], 'iTunes', 'iTunes Music', artist, album)

print artist, album, year

tracks = glob.glob(os.path.join(directory, '*.wav'))
trackcount = len(tracks)
contents = os.listdir(outputdir)
for i, track in enumerate(tracks):
   d, fname = os.path.split(track)
   tn = int(trackre.match(fname).group(1))
   title = tracklist[tn-1][0]
   safetitle = Util.filterchars(title)
   encodename = os.path.join(outputdir, "%s.mp3" % safetitle)
   if number:
      t = str(tn).zfill(2)
      newname = os.path.join(outputdir, "%s %s.mp3" % (t, safetitle))
   else:
      newname = encodename
   #Match filenames that differ only by case
   for c in contents:
      if c.lower() == os.path.split(newname)[1].lower():
         newname = os.path.join(outputdir, c)
         break
   print tn, '\t', title, '\t', newname
   
   if dryrun:
      continue