Omitting results with id3reader [Beginner]

Ionis lewisnorton90 at googlemail.com
Wed Dec 5 06:43:58 EST 2007


Hey guys, hope you can help me here. I've been playing with python for
about a week or two and I've been reading "A Byte Of Python" to get me
on my feet. I've decided to write a program which will list all ID3
information in a directory of .mp3 files into a .html file.

The python script I'm using for this, along with album art (Example)
are in the same directory as the music. The output I am getting when
it reads these files is "None" so I tried to set up a way to get rid
of these results and move onto the next file.

The omitting I'm attempting is within the If statement half way down
the code, easy to find. Could anyone point me in the right direction
on how to stop these "None" results showing in the result .html file.

Thanks in advance.

==========
import os
import id3reader

songartist = str("")
songtrack = str("")
html_bulkadd = str("")
html_start = str("""
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
>
		<title>Test Document</title>
	</head>
	<body>
""")
html_end = str("""
    </body>
</html>
""")

output = file("output.html", "w")
output.write("")
output.write(html_start)
output.close

path = ""
dirList = os.listdir(path)
for fname in dirList:
    songartist = str("")
    songtrack = str("")
    id3r = id3reader.Reader(fname)
    if id3r.getValue('performer') == "None":
        break
    elif id3r.getValue('title') == "None":
        break
    else:
        songartist = id3r.getValue('performer')
        songtrack = id3r.getValue('title')
        output = file("output.html", "a")
        output.write("<p>" + str(songartist) + " - " + str(songtrack)
+ "</p>\n")
        output.close

output = file("output.html", "a")
output.write("\n"+html_end)
output.close
==========

If anyone is curious on the module you can find it here:
http://nedbatchelder.com/code/modules/id3reader.html



More information about the Python-list mailing list