Commits

Cliff Dyer committed bd82cdc

Added playlist class

Comments (0)

Files changed (2)

             return self.encoder
 
     def get_tags(self, source):
-        raise NotImplemented
+	return {}
 
     def set_tags(self, target, tags):
-        raise NotImplemented
+	pass
 
     def update_tags(self, target, tags):
-        raise NotImplemented
+	pass
     
 
 class MP3Format(AudioFormat):
     extension = 'flac'
 
     def set_tags(self, source, tags):
+	if not tags:
+	    return
         field_arguments = []
         for field in tags:
             field_arguments.append(
                             continue
         return metadata
 
+
+class Playlist(object):
+    def __init__(self, filepath):
+        self.filepath = filepath
+
+    def __enter__(self):
+        self.file = open(self.filepath)
+        return self
+
+    def __exit__(self, *args, **kwargs):
+        self.file.close()
+
+    def __next__(self):
+        line = '#'
+        while line.startswith('#') or not line:
+            line = self.file.__next__().strip()
+        return AudioFile(line.strip())
+
+    def __iter__(self):
+        return self
 
 import os
 
-class TestConversion(unittest.TestCase):
+class ConversionTestCase(object): #unittest.TestCase):
 
     def tearDown(self):
         pass
         askulls.convert(audio_out)
         self.assertTrue(os.path.exists(outpath))
 
+
+class PlaylistTestCase(unittest.TestCase):
+
+    def test_playlist_is_context_manager(self):
+        with audiotools.Playlist('test/foo.m3u') as pl:
+            self.assertEqual(pl.filepath, 'test/foo.m3u')
+
+    def test_playlist_contains_audiofiles(self):
+        with audiotools.Playlist('test/foo.m3u') as pl:
+            audio = pl.next()
+            self.assertIsInstance(audio, audiotools.AudioFile)
+
+    def test_playlist_ignores_metadata_and_blank_lines(self):
+        with audiotools.Playlist('test/foo.m3u') as pl:
+            self.assertEqual(len(list(pl)), 1)
+
 if __name__ == '__main__':
     unittest.main()