diff options
Diffstat (limited to 'src/livestreamer/utils.py')
-rw-r--r-- | src/livestreamer/utils.py | 41 |
1 files changed, 14 insertions, 27 deletions
diff --git a/src/livestreamer/utils.py b/src/livestreamer/utils.py index 5ab8a63..5735695 100644 --- a/src/livestreamer/utils.py +++ b/src/livestreamer/utils.py @@ -1,35 +1,11 @@ #!/usr/bin/env python3 -from livestreamer.compat import urllib, bytes +from livestreamer.compat import urllib from livestreamer.plugins import PluginError import hmac, hashlib, zlib, argparse SWF_KEY = b"Genuine Adobe Flash Player 001" -class CommandLine(object): - def __init__(self, command): - self.command = command - self.args = {} - self.pipe = None - - def format(self): - args = [] - - for key, value in self.args.items(): - if value == True: - args.append(("--{0}").format(key)) - else: - escaped = str(value).replace('"', '\\"').replace("$", "\$").replace("`", "\`") - args.append(("--{0} \"{1}\"").format(key, escaped)) - - args = (" ").join(args) - cmdline = ("{0} {1}").format(self.command, args) - - if self.pipe: - cmdline += (" | {0}").format(self.pipe) - - return cmdline - class ArgumentParser(argparse.ArgumentParser): def convert_arg_line_to_args(self, line): split = line.find("=") @@ -37,16 +13,27 @@ class ArgumentParser(argparse.ArgumentParser): val = line[split+1:].strip() yield "--%s=%s" % (key, val) -def urlget(url, data=None, timeout=None, opener=None): +def urlopen(url, data=None, timeout=None, opener=None): try: if opener is not None: fd = opener.open(url) else: fd = urllib.urlopen(url, data, timeout) + except IOError as err: + if type(err) is urllib.URLError: + raise PluginError(err.reason) + else: + raise PluginError(err) + + return fd + +def urlget(url, data=None, timeout=None, opener=None): + fd = urlopen(url, data, timeout, opener) + + try: data = fd.read() fd.close() - except IOError as err: if type(err) is urllib.URLError: raise PluginError(err.reason) |