Browse Source

podcast: more resilient to invalid audio

boyska 3 years ago
parent
commit
d9123555ce
1 changed files with 9 additions and 4 deletions
  1. 9 4
      larigira/audiogen_podcast.py

+ 9 - 4
larigira/audiogen_podcast.py

@@ -35,9 +35,8 @@ def get_duration(url):
                 url,
             ]
         ).split(b"\n")
-    except CalledProcessError:
-        logging.exception("error probing `%s`", url)
-        return 0
+    except CalledProcessError as exc:
+        raise ValueError("error probing `%s`" % url) from exc
     duration = next(l for l in lineout if l.startswith(b"duration="))
     value = duration.split(b"=")[1]
     return int(float(value))
@@ -64,7 +63,13 @@ class Audio(object):
     def duration(self):
         """lazy-calculation"""
         if self._duration is None:
-            self._duration = get_duration(self.url.encode("utf-8"))
+            try:
+                self._duration = get_duration(self.url.encode("utf-8"))
+            except:
+                logging.exception(
+                    "Errore nel calcolo della lunghezza di %s; imposto a 0"
+                )
+                self._duration = 0
         return self._duration
 
     @property