Embedded subtitles provider: improve exception handling

Related to fese's library update. Close #1819
pull/1806/head v1.0.4-beta.29
Vitiko 3 years ago
parent 5f29baca34
commit f01d916f95

@ -14,7 +14,7 @@ from babelfish import Language
from babelfish.exceptions import LanguageError from babelfish.exceptions import LanguageError
import pysubs2 import pysubs2
__version__ = "0.1.2" __version__ = "0.1.3"
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -134,19 +134,21 @@ class FFprobeSubtitleStream:
# fixme: we still don't know if "DURATION" is a common tag/key # fixme: we still don't know if "DURATION" is a common tag/key
if "DURATION" in self.tags: if "DURATION" in self.tags:
try: try:
h, m, s = self.tags["DURATION"].split(":") h, m, s = [
except ValueError: ts.replace(",", ".").strip()
pass for ts in self.tags["DURATION"].split(":")
else: ]
self.duration = float(s) + float(m) * 60 + float(h) * 60 * 60 self.duration = float(s) + float(m) * 60 + float(h) * 60 * 60
self.duration_ts = int(self.duration * 1000) self.duration_ts = int(self.duration * 1000)
except ValueError as error:
logger.warning("Couldn't get duration field: %s. Using 0", error)
else: else:
try: try:
self.duration = float(stream.get("duration", 0)) self.duration = float(stream.get("duration", "0").replace(",", "."))
self.duration_ts = int(stream.get("duration_ts", 0)) self.duration_ts = int(stream.get("duration_ts", self.duration * 1000))
# some subtitles streams miss a duration completely and has "N/A" as value # some subtitles streams miss a duration completely and has "N/A" as value
except ValueError: except ValueError as error:
pass logger.warning("Couldn't get duration field: %s. Using 0", error)
self.start_pts = int(stream.get("start_pts", 0)) self.start_pts = int(stream.get("start_pts", 0))

Loading…
Cancel
Save