]> git.0d.be Git - django-panik-emissions.git/commitdiff
add warning if main sound volume is too low
authorFrédéric Péters <fpeters@0d.be>
Wed, 25 Oct 2023 15:29:47 +0000 (17:29 +0200)
committerFrédéric Péters <fpeters@0d.be>
Wed, 25 Oct 2023 15:30:47 +0000 (17:30 +0200)
emissions/models.py
emissions/templates/emissions/episode_detail.html

index 02fc8c604431cd150403b50e53e8fee7ab4847f1..afd072eaddc27df90f43f27dbf72e49677634231 100644 (file)
@@ -1,5 +1,7 @@
 import datetime
+import json
 import os
+import statistics
 import urllib.parse
 
 from ckeditor.fields import RichTextField
@@ -744,6 +746,14 @@ class SoundFile(models.Model):
             return False
         return bool(self.duration < min(self.get_durations()) * 0.5)
 
+    def has_low_volume(self):
+        waveform_json = self.get_format_path('waveform.json')
+        if os.path.exists(waveform_json):
+            with open(waveform_json) as wavefile_fd:
+                median_volume = statistics.median(json.load(wavefile_fd))
+                return bool(median_volume < 10)
+        return False
+
     def __str__(self):
         return '%s - %s' % (self.title or self.id, self.episode.title)
 
index 95f5ebbdc9e6b88e5d6db6c4fd509222b98bcb44..323755e80dc1186447c5f6fd1bce709f905dee88 100644 (file)
         <div class="errornotice">
           {% trans "An episode should have only one main sound." %}
         </div>
+      {% elif episode.main_sound.has_low_volume %}
+        <div class="errornotice">
+          {% trans "The audio volume of the main soundfile is too low." %}
+          {% if has_future_diffusion %}
+            {% trans "You should replace that file before it is broadcasted." %}
+          {% endif %}
+        </div>
       {% endif %}
 
       <table id="soundfiles"