]> git.parisson.com Git - teleforma.git/commitdiff
exception for setting media duration
authorGuillaume Pellerin <guillaume.pellerin@parisson.com>
Thu, 6 Aug 2026 08:38:53 +0000 (10:38 +0200)
committerGuillaume Pellerin <guillaume.pellerin@parisson.com>
Thu, 6 Aug 2026 08:38:53 +0000 (10:38 +0200)
teleforma/models/core.py

index b6398a6c68533171079ccb2ad533a43273bc181f..03767df6ebc16b5269d4a40098dd557baa48594d 100644 (file)
@@ -1157,12 +1157,18 @@ class Media(MediaBase):
             return None
 
     def set_duration(self):
-        result = subprocess.run(["ffprobe", "-v", "error", "-show_entries",
-                             "format=duration", "-of",
-                             "default=noprint_wrappers=1:nokey=1", self.file.path],
-            stdout=subprocess.PIPE,
-            stderr=subprocess.STDOUT)
-        self.duration = datetime.timedelta(days=0, seconds=float(result.stdout))
+        if self.file:
+            if os.path.exists(self.file.path):
+                try:
+                    result = subprocess.run(["ffprobe", "-v", "error", "-show_entries",
+                                         "format=duration", "-of",
+                                         "default=noprint_wrappers=1:nokey=1", self.file.path],
+                        stdout=subprocess.PIPE,
+                        stderr=subprocess.STDOUT)
+                    self.duration = datetime.timedelta(days=0, seconds=float(result.stdout))
+                except:
+                    logger.info("failed to set duration of media.id: " + str(self.id))
+                    continue
 
     class Meta(MetaCore):
         db_table = app_label + '_' + 'media'