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)
56 value,attrstr=tail.split('"',1)
59 value,attrstr=tail.split(' ',1)
63 attrstr=attrstr.strip()
66 title=title.decode('string_escape')
67 song=track(length,title,None,attrs)
68 elif (len(line) != 0):
69 # pull song path from all other, non-blank lines
73 # reset the song variable so it doesn't use the same EXTINF more than once
74 song=track(None,None,None)
80 # for now, just pull the track info and print it onscreen
81 # get the M3U file path from the first command line argument
84 playlist = parseM3U(m3ufile)
85 for track in playlist:
86 print (track.title, track.length, track.path)
88 if __name__ == '__main__':