Editing ID3 Tags in Python Part 2: NPR Presents The Austin 100

2018, Mar 14    

I was excited to get the chance to re-use the code from the previous post to solve a problem I recently had with a compilation of songs taken from different albums. NPR Music has put together a compilation of 100 songs from bands playing at this year’s South by Southwest (SXSW) festival. It’s available to download for free for a limited time.

The issue, when putting the folder containing the 100 mp3s on my Android phone, is that the ID3 tags for album and album artist are specific to the album from which each song originated. Each song is listed under a different album, resulting in 100 additional albums to scroll through in the Google Play mp3 player - a complete mess!

I used the Python code below to harmonize the album and album artist ID3 tags for the Austin 100 compilation. All the songs are now classified under a single album in Google Play - making it easy to listen to the collection of songs without navigating through 100 different folders.

The code:

    
# load the libraries that we'll use  
from mutagen.mp3 import MP3  
from mutagen.easyid3 import EasyID3  
import mutagen.id3  
from mutagen.id3 import ID3, TIT2, TIT3, TALB, TPE1, TRCK, TYER  
import glob  
import numpy as np  
  
# extract the file names (with file paths)  
filez = glob.glob("/media/ID3/NPR Music Presents The Austin 100 (2018)/*.mp3")  
# loop through the mp3 files, setting the album and   
# albumartist   
# to the appropriate values   
for i in np.arange(0, len(filez)):  
	# mp3 name (with directory) from filez  
	song = filez[i]  
	# turn it into an mp3 object using the mutagen library  
	mp3file = MP3(song, ID3=EasyID3)  
	# set the album name  
	mp3file['album'] = ['NPR Presents the Austin 100']  
	# set the albumartist name  
	mp3file['albumartist'] = ['Austin 100']  
	# save the changes that we've made  
	mp3file.save()  

Always exciting to re-use code written for a different purpose!