]> git.0d.be Git - django-panik-emissions.git/commitdiff
management: also compute durations of non-podcastable files
authorFrédéric Péters <fpeters@0d.be>
Tue, 24 Mar 2020 15:02:17 +0000 (16:02 +0100)
committerFrédéric Péters <fpeters@0d.be>
Tue, 24 Mar 2020 15:02:17 +0000 (16:02 +0100)
emissions/management/commands/create-sound-files.py

index f08192f64aff9cb7e414764d7f25c01bbb919c0e..4bd0000a74c30c560bedb32c91f2fce9d620dacc 100644 (file)
@@ -56,7 +56,7 @@ class Command(BaseCommand):
         self.copy = copy
         self.link = link
 
-        for soundfile in SoundFile.objects.select_related().exclude(podcastable=False):
+        for soundfile in SoundFile.objects.select_related():
             if emission and soundfile.episode.emission.slug != emission:
                 continue
             if episode and soundfile.episode.slug != episode:
@@ -66,6 +66,17 @@ class Command(BaseCommand):
                     continue
             except ValueError:  # no file associated with it
                 continue
+            if not soundfile.podcastable:
+                # get duration using initial file
+                if not soundfile.duration:
+                    cmd = ['soxi', '-D', soundfile.file.path]
+                    try:
+                        soundfile.duration = int(float(subprocess.check_output(cmd)))
+                    except (ValueError, subprocess.CalledProcessError):
+                        pass
+                    else:
+                        soundfile.save()
+                continue
             for format in formats.split(','):
                 file_path = soundfile.get_format_path(format)
                 created = False