1 # more info on the M3U file format available here:
2 # http://n4k3d.com/the-m3u-file-format/
9 def __init__(self, length, title, path):
15 # # # song info lines are formatted like:
16 #EXTINF:419,Alice In Chains - Rotten Apple
19 # # # file name - relative or absolute path of file
20 # ..\Minus The Bear - Planet of Ice\Minus The Bear_Planet of Ice_01_Burying Luck.mp3
22 inf = open(infile,'r')
24 # # # all m3u files should start with this line:
26 # this is not a valid M3U and we should stop..
28 line = line.lstrip('\xef\xbb\xbf')
29 line = line.rstrip('\n')
31 if not line.startswith('#EXTM3U'):
34 # initialize playlist variables before reading file
36 song=track(None,None,None)
39 line = line.lstrip('\xef\xbb\xbf')
40 line = line.rstrip('\n')
42 if line.startswith('#EXTINF:'):
43 # pull length and title from #EXTINF line
44 length,title=line.split('#EXTINF:')[1].split(',',1)
45 title=title.decode('string_escape')
46 song=track(length,title,None)
47 elif (len(line) != 0):
48 # pull song path from all other, non-blank lines
52 # reset the song variable so it doesn't use the same EXTINF more than once
53 song=track(None,None,None)
59 # for now, just pull the track info and print it onscreen
60 # get the M3U file path from the first command line argument
63 playlist = parseM3U(m3ufile)
64 for track in playlist:
65 print (track.title, track.length, track.path)
67 if __name__ == '__main__':