X-Git-Url: https://git.rvb.name/vpproxy.git/blobdiff_plain/1074f7e8729c2ff065d73960c5450c9356c2fd11..1aebc74d991c35b7eb82395434d543d44f536089:/plugins/modules/M3uParser.py?ds=sidebyside diff --git a/plugins/modules/M3uParser.py b/plugins/modules/M3uParser.py index 9e2fce6..5bee611 100644 --- a/plugins/modules/M3uParser.py +++ b/plugins/modules/M3uParser.py @@ -6,10 +6,11 @@ import hexdump import codecs class track(): - def __init__(self, length, title, path): + def __init__(self, length, title, path, attrs=None): self.length = length self.title = title self.path = path + self.attrs = attrs # # # song info lines are formatted like: @@ -41,9 +42,29 @@ def parseM3U(infile): line = line.strip() if line.startswith('#EXTINF:'): # pull length and title from #EXTINF line - length,title=line.split('#EXTINF:')[1].split(',',1) + prefix,title=line.split('#EXTINF:')[1].split(',',1) + title=title.strip() + length,attrstr=prefix.split(' ',1) + attrs={} + + while attrstr: + + attrstr=attrstr.strip() + key,tail=attrstr.split('=',1) + if tail[0]=='\"': + tail=tail[1:] + value,attrstr=tail.split('"',1) + else: + try: + value,attrstr=tail.split(' ',1) + except ValueError: + value=tail + attrstr='' + attrstr=attrstr.strip() + attrs[key]=value + title=title.decode('string_escape') - song=track(length,title,None) + song=track(length,title,None,attrs) elif (len(line) != 0): # pull song path from all other, non-blank lines song.path=line