]> git.parisson.com Git - teleforma.git/commitdiff
add Media.set_duration, ffmpeg
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Wed, 5 Oct 2022 10:11:55 +0000 (12:11 +0200)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Wed, 5 Oct 2022 10:11:55 +0000 (12:11 +0200)
debian-packages.txt
teleforma/management/commands/teleforma-import-seminar-media-update.py
teleforma/models/core.py

index 8a529a8738bfae05f630e8df04160a91a5033b71..b91c4e217ce1e0c44eed47e580070759747e384b 100644 (file)
@@ -9,3 +9,4 @@ python3-psycopg2
 python3-yaml
 uwsgi
 gettext
+ffmpeg
index 09154fb2a167de65cdc69188c0a3729535c0598b..1274b4bec1a19e47abde2492831b44e16387c9d2 100644 (file)
@@ -185,7 +185,6 @@ class Command(BaseCommand):
                     path = dir + os.sep + filename
 
                     seminar_title = '_'.join([course_code, str(seminar_rank)])
-                    collection_id = '_'.join([department_name, seminar_title])
                     course = Course.objects.get(code=course_code)
                     department, c = Department.objects.get_or_create(name=department_name,
                                                                      organization=organization)
index 684c47c1865521cd15aca4f597dafbee7c5c289d..2de2044f04fda1698edcfdff1af073665c502555 100755 (executable)
@@ -116,6 +116,7 @@ class MetaCore:
     app_label = app_label
 
 
+
 class ClonableMixin(object):
 
     def clone(self):
@@ -652,6 +653,7 @@ class Media(MediaBase):
         elif self.conference:
             self.conference.course.save()
         self.set_mime_type()
+        self.set_duration()
 
     def poster_url(self, geometry='640'):
         url = ''
@@ -672,11 +674,31 @@ class Media(MediaBase):
                 m.save()
             return markers
 
+    def set_duration(self):
+        """
+        set media duration
+        """
+        if self.file:
+            process = subprocess.Popen(["ffmpeg", "-i", self.file.path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+            stdout, stderr = process.communicate()
+            try:
+                pattern = re.compile(r'Duration: ([\w.-]+):([\w.-]+):([\w.-]+),')
+                match = pattern.search(stdout)
+                duration = "%s:%s:%s" % (match.group(1), match.group(2), match.group(3))
+            except:
+                duration = None
+        else:
+            duration = None
+
+        self.approx_duration = duration
+
     class Meta(MetaCore):
         db_table = app_label + '_' + 'media'
         ordering = ['rank']
 
 
+
+
 class SuggestionsMixin(Model):
     suggested_seminars = models.ManyToManyField('teleforma.Seminar', related_name="%(class)ss_related",
                                                 verbose_name=_('suggested seminars'),