From d9123555ceffef148cc2092832504611c575c8a7 Mon Sep 17 00:00:00 2001 From: boyska Date: Wed, 3 Mar 2021 00:58:11 +0100 Subject: [PATCH] podcast: more resilient to invalid audio --- larigira/audiogen_podcast.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/larigira/audiogen_podcast.py b/larigira/audiogen_podcast.py index 88ae56e..3d663f6 100644 --- a/larigira/audiogen_podcast.py +++ b/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