I'm trying to read the ID3 tags from my vast karaoke collection, so that I can store them in a CSV file, for easy formatting and printing, but I'm having issues actually getting the values! I manage to get them in a format like this, if I print the method items()
:
[('artist', [u'Steve Miller Band']), ('title', [u'Space Cowboy [Karaoke]'])]
[('artist', [u'Stevie Wonder']), ('title', [u"Livin' For The City [Karaoke]"])]
The code I'm using is below:
#! /usr/bin/env python2.7
import os
import glob
import os.path
import csv
from mutagen.easyid3 import EasyID3
from mutagen.mp3 import MP3
#form stagger.id3 import *
directory = os.path.normpath("C:/Users/Adrian/Music/Karaoke/Kar/*/*.cdg")
files = glob.glob(directory)
csvw = open('C:\\python\\karaoke.csv', 'wb')
info = []
for f in files:
split = os.path.splitext(f)
newpath = split[0] + ".mp3"
if(os.path.isfile(newpath)):
audio = MP3(newpath, ID3=EasyID3)
stuff = audio.items()
print stuff
try:
print>>csvw, (stuff[0] + ", " + stuff[1] + "\r\n")
except:
print>>csvw, (os.path.basename(newpath) + "\r\n")
info.append(audio.items())
I have tried using integers to access them as if they were a list, and also strings as if it were a dictionary, but I get an error each time. I've read somewhere on SE that the function items()
returns a "dictionary-like-object", but searching on google hasn't helped me either!