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,
|
url,
|
||||||
]
|
]
|
||||||
).split(b"\n")
|
).split(b"\n")
|
||||||
except CalledProcessError:
|
except CalledProcessError as exc:
|
||||||
logging.exception("error probing `%s`", url)
|
raise ValueError("error probing `%s`" % url) from exc
|
||||||
return 0
|
|
||||||
duration = next(l for l in lineout if l.startswith(b"duration="))
|
duration = next(l for l in lineout if l.startswith(b"duration="))
|
||||||
value = duration.split(b"=")[1]
|
value = duration.split(b"=")[1]
|
||||||
return int(float(value))
|
return int(float(value))
|
||||||
|
@ -64,7 +63,13 @@ class Audio(object):
|
||||||
def duration(self):
|
def duration(self):
|
||||||
"""lazy-calculation"""
|
"""lazy-calculation"""
|
||||||
if self._duration is None:
|
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
|
return self._duration
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
Loading…
Reference in a new issue