From: Guillaume Pellerin Date: Fri, 19 Jun 2026 13:44:45 +0000 (+0200) Subject: add Media.duration X-Git-Tag: 3.0.0~3 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=289c0da5c9005cbdde36744e999dc241a1df106c;p=teleforma.git add Media.duration --- diff --git a/debian-packages.txt b/debian-packages.txt index 7a083b26..369b5241 100644 --- a/debian-packages.txt +++ b/debian-packages.txt @@ -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 diff --git a/teleforma/models/core.py b/teleforma/models/core.py index c3eec578..863d9eb1 100644 --- a/teleforma/models/core.py +++ b/teleforma/models/core.py @@ -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',]