podcast: more resilient to invalid audio
This commit is contained in:
parent
32337c54cf
commit
d9123555ce
1 changed files with 9 additions and 4 deletions
|
@ -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:
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue