from livestreamer.utils import urlopen

import pbs

class StreamError(Exception):
    pass

class Stream(object):
    def open(self):
       raise NotImplementedError

class RTMPStream(Stream):
    def __init__(self, params):
        self.params = params or {}

    def open(self):
        try:
            rtmpdump = pbs.rtmpdump
        except pbs.CommandNotFound:
            raise StreamError("Unable to find 'rtmpdump' command")

        self.params["flv"] = "-"
        self.params["_bg"] = True

        stream = rtmpdump(**self.params)

        return stream.process.stdout

class HTTPStream(Stream):
    def __init__(self, url):
        self.url = url

    def open(self):
        return urlopen(self.url)


@@ -33,16 +33,26 @@
 rlopen%0A%0A
+import os%0A
 import p
@@ -504,16 +504,68 @@
 %5D = True
+%0A        self.params%5B%22_err%22%5D = open(os.devnull, %22w%22)
 %0A%0A      

Fix rtmpdump locking up when stderr buffer is filled.