Commits

Cliff Dyer committed f136ae6

Added basic test for audiotools utilities.

Comments (0)

Files changed (3)

         self.format = self.get_format()
 
     def delete(self):
-        if os.exists(self.filename):
+        if os.path.exists(self.filename):
             os.unlink(self.filename)
 
     def get_format(self):
                 if all(c in 'abcdefghijklmnopqrstuvwxyz' for c in key):
                     if key in key_conversions:
                         key = key_conversions[key]
-                    if key != 'cover':
+                    if key == 'cover':
+                        continue
+                    if key == 'BPM':
+                        value = value.decode('utf-8')
+                        value = int(''.join(c for c in value if c in set('0123456789')))
+                    else:
                         try:
                             metadata[key.upper()] = value.decode('utf-8')
                         except UnicodeDecodeError:
                             continue
         return metadata
 
-def faad_to_flac(source, target):
-    """Decode to WAV format using faad.  This loses metadata.
-    faad -i will recover it."""
-    outdir = os.path.dirname(target)
-    basename = source.split('/')[-1].rsplit('.', 1)[0]
-    wav_target = os.path.join(outdir, '{}.wav'.format(basename))
-    print(source, basename)
-    metadata = get_m4a_tags(source)
-    for key in metadata:
-        print(key, metadata[key])
-    subprocess.call(['faad', '-o', wav_target, source])
-
-def get_music_files(rootdir):
-    for dirpath, dirs, files in os.walk(rootdir):
-        for filename in files:
-            extension = filename.lower().rsplit('.', 1)[-1]
-            if extension in music_file_extensions:
-                yield dirpath, filename

test/01 Anonymous Skulls.m4a

Binary file added.
+import os
+import unittest
+
+import audiotools
+
+import os
+
+class TestConversion(unittest.TestCase):
+
+    def tearDown(self):
+        pass
+        #os.unlink('test/01 Anonymous Skulls.m4a.flac')
+
+    def test_conversion_from_m4a_to_flac(self):
+        askulls = audiotools.AudioFile('test/01 Anonymous Skulls.m4a')
+        self.assertTrue(os.path.exists(askulls.filename))
+        outpath = os.path.join(os.path.dirname(askulls.filename), os.path.basename(askulls.filename)) + '.flac'
+        audio_out = audiotools.AudioFile(outpath)
+        self.assertFalse(os.path.exists(outpath))
+        self.assertEqual(audio_out.filename, 'test/01 Anonymous Skulls.m4a.flac')
+        askulls.convert(audio_out)
+        self.assertTrue(os.path.exists(outpath))
+
+if __name__ == '__main__':
+    unittest.main()