pymp3

Description

pymp3 is a simple python script I wrote to tag my MP3 collection quickly and easily using pyid3lib. While most music is already tagged, subtle differences in spellings in fields such as artist can make listening to a single artist in applications such a Rhythmbox a hassle. For example, having songs tagged with the artist "N-sync", "N'Sync", "Nsync", etc, will all display as a different artist in your jukebox of choice.

By organizing your music into proper folders and then running this script, pymp3 can allievate these problems. You simply must arrange your music a directory layout like: Artist/Album/. All the songs inside Artist/Album/ will have their artist and album tags set to the value of the directory that they are in. Any miscellaneous songs in Artist/ that don't fit in a specific album folder will have their album tag set to "Unknown".

Source

#!/usr/bin/env python

import os
import pyid3lib

for root, dirs, files in os.walk('/home/jonojono/Desktop/Music'):
    for f in files:
        if f.endswith('.MP3') or f.endswith('.mp3'):
            song = os.path.join(root, f)
            dir = os.path.dirname(song)
            dirlist = dir.split('/')

            id3info = pyid3lib.tag(song)
            if dirlist[-2] == "Music":
                id3info.artist = dirlist[-2]
            else:
                id3info.album = dirlist[-1]
                id3info.artist = dirlist[-2]
            id3info.update()