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, attrs=None):
16 # # # song info lines are formatted like:
17 #EXTINF:419,Alice In Chains - Rotten Apple
20 # # # file name - relative or absolute path of file
21 # ..\Minus The Bear - Planet of Ice\Minus The Bear_Planet of Ice_01_Burying Luck.mp3
23 inf = open(infile,'r')
25 # # # all m3u files should start with this line:
27 # this is not a valid M3U and we should stop..
29 line = line.lstrip('\xef\xbb\xbf')
30 line = line.rstrip('\n')
32 if not line.startswith('#EXTM3U'):
35 # initialize playlist variables before reading file
37 song=track(None,None,None)
40 line = line.lstrip('\xef\xbb\xbf')
41 line = line.rstrip('\n')
43 if line.startswith('#EXTINF:'):
44 # pull length and title from #EXTINF line
45 prefix,title=line.split('#EXTINF:')[1].split(',',1)
47 length,attrstr=prefix.split(' ',1)
52 attrstr=attrstr.strip()
53 key,tail=attrstr.split('=',1)
55 value,attrstr=tail.split('"',1)
56 attrstr=attrstr.strip()
59 title=title.decode('string_escape')
60 song=track(length,title,None,attrs)
61 elif (len(line) != 0):
62 # pull song path from all other, non-blank lines
66 # reset the song variable so it doesn't use the same EXTINF more than once
67 song=track(None,None,None)
73 # for now, just pull the track info and print it onscreen
74 # get the M3U file path from the first command line argument
77 playlist = parseM3U(m3ufile)
78 for track in playlist:
79 print (track.title, track.length, track.path)
81 if __name__ == '__main__':