-2

I'm using python 2.7 for this here. I've got a bit of code to extract certain mp3 tags, like this here

mp3info = EasyID3(fileName)
print mp3info
print mp3info['genre']
print mp3info.get('genre', default=None)
print str(mp3info['genre'])
print repr(mp3info['genre'])
genre = unicode(mp3info['genre'])
print genre

I have to use the name ['genre'] instead of [2] as the order can vary between tracks. It produces output like this

{'artist': [u'Really Cool Band'], 'title': [u'Really Cool Song'], 'genre': [u'Rock'], 'date': [u'2005']}
[u'Rock']
[u'Rock']
[u'Rock']
[u'Rock']
[u'Rock']

At first I was like, "Why thank you, I do rock" but then I got on with trying to debug the code. As you can see, I've tried a few different approaches, but none of them work. All I want is for it to output

Rock

I reckon I could possibly use split, but that could get very messy very quickly as there's a distinct possibility that artist or title could contain '

Any suggestions?

vmos
  • 109
  • 1
  • 2
  • 10

2 Answers2

1

It's not a string that you can use split on,, it's a list; that list usually (always?) contains one item. So you can get that first item:

genre = mp3info['genre'][0]
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
1
[u'Rock']

Is a list of length 1, its single element is a Unicode string.

Try

 print genre[0]

To only print the first element of the list.

RemcoGerlich
  • 30,470
  • 6
  • 61
  • 79