1 # more info on the M3U file format available here:
2 # http://n4k3d.com/the-m3u-file-format/
7 def __init__(self, length, title, path):
13 # # # song info lines are formatted like:
14 #EXTINF:419,Alice In Chains - Rotten Apple
17 # # # file name - relative or absolute path of file
18 # ..\Minus The Bear - Planet of Ice\Minus The Bear_Planet of Ice_01_Burying Luck.mp3
20 inf = open(infile,'r')
22 # # # all m3u files should start with this line:
24 # this is not a valid M3U and we should stop..
26 if not line.startswith('#EXTM3U'):
29 # initialize playlist variables before reading file
31 song=track(None,None,None)
35 if line.startswith('#EXTINF:'):
36 # pull length and title from #EXTINF line
37 length,title=line.split('#EXTINF:')[1].split(',',1)
38 song=track(length,title,None)
39 elif (len(line) != 0):
40 # pull song path from all other, non-blank lines
44 # reset the song variable so it doesn't use the same EXTINF more than once
45 song=track(None,None,None)
51 # for now, just pull the track info and print it onscreen
52 # get the M3U file path from the first command line argument
55 playlist = parseM3U(m3ufile)
56 for track in playlist:
57 print (track.title, track.length, track.path)
59 if __name__ == '__main__':