]> git.0d.be Git - django-panik-emissions.git/commitdiff
create-sound-files: compute duration from mp3 if it's the only format
authorFrédéric Péters <fpeters@0d.be>
Sat, 28 Dec 2019 16:59:24 +0000 (17:59 +0100)
committerFrédéric Péters <fpeters@0d.be>
Sat, 28 Dec 2019 16:59:24 +0000 (17:59 +0100)
emissions/management/commands/create-sound-files.py

index 55f1fae46ef3c9a46920688abd3ae3f96836f4d5..f08192f64aff9cb7e414764d7f25c01bbb919c0e 100644 (file)
@@ -73,10 +73,14 @@ class Command(BaseCommand):
                     created = self.create(soundfile, format)
                 if created or reset_metadata:
                     self.set_metadata(soundfile, format)
-            if (force or not soundfile.duration) and os.path.exists(soundfile.get_format_path('ogg')):
-                cmd = ['soxi', '-D', soundfile.get_format_path('ogg')]
-                soundfile.duration = int(float(subprocess.check_output(cmd)))
-                soundfile.save()
+            if (force or not soundfile.duration):
+                for extension in ('ogg', 'mp3'):
+                    soundfile_name = soundfile.get_format_path(extension)
+                    if os.path.exists(soundfile_name):
+                        cmd = ['soxi', '-D', soundfile_name]
+                        soundfile.duration = int(float(subprocess.check_output(cmd)))
+                        soundfile.save()
+                        break
 
 
     def create(self, soundfile, format):