From 7ce4938cff4b4f352cc2cade258391be2771fede Mon Sep 17 00:00:00 2001 From: Christopher Rosell Date: Sat, 8 Sep 2012 00:13:07 +0200 Subject: Add a exception argument to urlopen. --- src/livestreamer/stream.py | 9 ++++----- src/livestreamer/utils.py | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/livestreamer/stream.py b/src/livestreamer/stream.py index f72217b..82d9a9a 100644 --- a/src/livestreamer/stream.py +++ b/src/livestreamer/stream.py @@ -1,5 +1,5 @@ from .compat import str, is_win32 -from .utils import urlopen +from .utils import urlget import os import pbs @@ -96,10 +96,9 @@ class HTTPStream(Stream): self.args = args def open(self): - try: - res = urlopen(self.url, prefetch=False, **self.args) - except Exception as err: - raise StreamError(str(err)) + res = urlget(self.url, prefetch=False, + exception=StreamError, + **self.args) return res.raw diff --git a/src/livestreamer/utils.py b/src/livestreamer/utils.py index 90b9379..dfee53f 100644 --- a/src/livestreamer/utils.py +++ b/src/livestreamer/utils.py @@ -22,14 +22,14 @@ class ArgumentParser(argparse.ArgumentParser): else: yield "--%s" % line -def urlopen(url, method="get", **args): +def urlopen(url, method="get", exception=PluginError, **args): if "data" in args and args["data"] is not None: method = "post" try: res = requests.request(method, url, config=RequestsConfig, timeout=15, **args) except requests.exceptions.RequestException as err: - raise PluginError(("Unable to open URL: {url} ({err})").format(url=url, err=str(err))) + raise exception(("Unable to open URL: {url} ({err})").format(url=url, err=str(err))) return res -- cgit v1.2.3