def parseM3U(infile): if '#EXT' not in infile: text = read_url(infile).lstrip() else: text = infile inf = open(m3uTemp,'w') inf.write(text) inf.close() inf = open(m3uTemp,'r') # # # all m3u files should start with this line: #EXTM3U # this is not a valid M3U and we should stop.. line = inf.readline() if not line.startswith('#EXTM3U'): return # initialize playlist variables before reading file playlist=[] song=track(None,None,None) for line in inf: banana='y' line=line.strip() if line.startswith('#EXTINF:'): # pull length and title from #EXTINF line try: length,title=line.split('#EXTINF:')[1].split(',',1) song=track(length,title,None) except: banana = 'x' elif (len(line) != 0): if banana!='x': # pull song path from all other, non-blank lines song.path=line playlist.append(song) # reset the song variable so it doesn't use the same EXTINF more than once song=track(None,None,None) else: banana='x' inf.close() return playlist
def parseM3U(infile): text = read_url(infile).lstrip() inf = open(m3uTemp,'w') inf.write(text) inf.close() inf = open(m3uTemp,'r') # # # all m3u files should start with this line: #EXTM3U # this is not a valid M3U and we should stop.. line = inf.readline() if not line.startswith('#EXTM3U'): return # initialize playlist variables before reading file playlist=[] song=track(None,None,None) for line in inf: banana='y' line=line.strip() if line.startswith('#EXTINF:'): # pull length and title from #EXTINF line try: length,title=line.split('#EXTINF:')[1].split(',',1) song=track(length,title,None) except: banana = 'x' elif (len(line) != 0): if banana!='x': # pull song path from all other, non-blank lines song.path=line playlist.append(song) # reset the song variable so it doesn't use the same EXTINF more than once song=track(None,None,None) else: banana='x' inf.close() return playlist
def test_read_file_url(self): page_html = wu.read_url(cm.BASE_TEST_URL + 'crawler/barebones.html') self.assertIn('<html', page_html, "Cannot find html tag")
def test_read_url(self): page_html = wu.read_url('http://www.google.com') self.assertIn('<html', page_html, "Cannot find html tag")