lewashby

building a string from mp3 meta data

Discussion created by lewashby on Jun 4, 2014
Latest reply on Jun 6, 2014 by Caleb1987
'm trying to write a program to get the artist and album from mp3 meta data. To do a test run I had my python program to build a simple 30 character string one byte at a time starting 125 bytes in from the end of the file, that's where the mp3 meta data starts. I did this on the Alice in Chains song 'Rooster'. After my program ran I got a string that looked like this b'Rooster\x00\x00\x00\x00\x00, It was Rooster with 23 sets of '\x00' attached. I want to stop building the string when I hit the first '\x00', but I'm not sure how I should go about doing that. I tried while file.read() is not '\x00': but that didn't work. Any ideas on how I can represent '\x00' as a byte to stop on? I'm consued because '\x00' is four bytes, not one.

#!/usr/bin/env python3

import sys

file = sys.argv[1]
f = open(file, 'rb')

f.seek(-125, 2)
artist = f.read()
char = f.read()
while char is not '\x00':
    char = f.read(1)
    artist = artist + f.read()
print(artist)

f.close()

Outcomes