]> git.parisson.com Git - teleforma.git/commitdiff
add Media.duration
authorGuillaume Pellerin <guillaume.pellerin@parisson.com>
Fri, 19 Jun 2026 13:44:45 +0000 (15:44 +0200)
committerGuillaume Pellerin <guillaume.pellerin@parisson.com>
Fri, 19 Jun 2026 13:44:45 +0000 (15:44 +0200)
debian-packages.txt
teleforma/models/core.py

index 7a083b26935d52b162b048edfdc1769533d3abd9..369b52411af65df2745ba480c0dcf68efffaf313 100644 (file)
@@ -1,3 +1,4 @@
+ffmpeg
 git
 less
 locales
@@ -9,4 +10,4 @@ python3-psycopg2
 python3-yaml
 redis-tools
 uwsgi
-vim
+vim
\ No newline at end of file
index c3eec5788a0a2944fa7dc395f594c1b9e288772d..863d9eb12d8ae24b59162a99e9888163983c4b14 100644 (file)
@@ -44,6 +44,7 @@ import asyncio
 import tempfile
 import threading
 import logging
+import subprocess
 
 import django.db.models as models
 from django.conf import settings
@@ -1063,6 +1064,7 @@ class Media(MediaBase):
         )
     poster_file = models.FileField(
         _('poster file'), upload_to='items/%Y/%m/%d', max_length=255, null=True, blank=False)
+    duration = models.DurationField(_("duration"), blank=True, null=True)
 
     def set_mime_type(self):
         path = None
@@ -1107,6 +1109,14 @@ class Media(MediaBase):
         else:
             return None
 
+    def set_duration(filename):
+        result = subprocess.run(["ffprobe", "-v", "error", "-show_entries",
+                             "format=duration", "-of",
+                             "default=noprint_wrappers=1:nokey=1", filename],
+            stdout=subprocess.PIPE,
+            stderr=subprocess.STDOUT)
+        self.duration = float(result.stdout)
+
     class Meta(MetaCore):
         db_table = app_label + '_' + 'media'
         ordering = ['-date_modified', '-conference__session',]