diff options
-rw-r--r-- | src/livestreamer/stream/__init__.py (renamed from src/livestreamer/stream.py) | 50 | ||||
-rw-r--r-- | src/livestreamer/stream/http.py | 17 | ||||
-rw-r--r-- | src/livestreamer/stream/rtmpdump.py | 35 |
3 files changed, 57 insertions, 45 deletions
diff --git a/src/livestreamer/stream.py b/src/livestreamer/stream/__init__.py index 82d9a9a..235d2f7 100644 --- a/src/livestreamer/stream.py +++ b/src/livestreamer/stream/__init__.py @@ -1,5 +1,4 @@ -from .compat import str, is_win32 -from .utils import urlget +from ..compat import str import os import pbs @@ -58,48 +57,9 @@ class StreamProcess(Stream): return stream.process.stdout -class RTMPStream(StreamProcess): - def __init__(self, session, params): - StreamProcess.__init__(self, session, params) - self.rtmpdump = self.session.options.get("rtmpdump") or (is_win32 and "rtmpdump.exe" or "rtmpdump") - self.params["flv"] = "-" +from .http import HTTPStream +from .rtmpdump import RTMPStream - try: - self.cmd = getattr(pbs, self.rtmpdump) - except pbs.CommandNotFound as err: - raise StreamError(("Unable to find {0} command").format(str(err))) - - def open(self): - if "jtv" in self.params and not self._has_jtv_support(): - raise StreamError("Installed rtmpdump does not support --jtv argument") - - return StreamProcess.open(self) - - def _has_jtv_support(self): - try: - help = self.cmd(help=True, _err_to_out=True) - except pbs.ErrorReturnCode as err: - raise StreamError(("Error while checking rtmpdump compatibility: {0}").format(str(err.stdout, "ascii"))) - - for line in help.split("\n"): - if line[:5] == "--jtv": - return True - - return False - -class HTTPStream(Stream): - def __init__(self, session, url, **args): - Stream.__init__(self, session) - - self.url = url - self.args = args - - def open(self): - res = urlget(self.url, prefetch=False, - exception=StreamError, - **self.args) - - return res.raw - -__all__ = ["StreamError", "Stream", "StreamProcess", "RTMPStream", "HTTPStream"] +__all__ = ["StreamError", "Stream", "StreamProcess", + "RTMPStream", "HTTPStream"] diff --git a/src/livestreamer/stream/http.py b/src/livestreamer/stream/http.py new file mode 100644 index 0000000..ab9a763 --- /dev/null +++ b/src/livestreamer/stream/http.py @@ -0,0 +1,17 @@ +from . import Stream +from ..utils import urlget + +class HTTPStream(Stream): + def __init__(self, session, url, **args): + Stream.__init__(self, session) + + self.url = url + self.args = args + + def open(self): + res = urlget(self.url, prefetch=False, + exception=StreamError, + **self.args) + + return res.raw + diff --git a/src/livestreamer/stream/rtmpdump.py b/src/livestreamer/stream/rtmpdump.py new file mode 100644 index 0000000..68ed969 --- /dev/null +++ b/src/livestreamer/stream/rtmpdump.py @@ -0,0 +1,35 @@ +from . import StreamProcess +from ..compat import str, is_win32 + +import pbs + +class RTMPStream(StreamProcess): + def __init__(self, session, params): + StreamProcess.__init__(self, session, params) + + self.rtmpdump = self.session.options.get("rtmpdump") or (is_win32 and "rtmpdump.exe" or "rtmpdump") + self.params["flv"] = "-" + + try: + self.cmd = getattr(pbs, self.rtmpdump) + except pbs.CommandNotFound as err: + raise StreamError(("Unable to find {0} command").format(str(err))) + + def open(self): + if "jtv" in self.params and not self._has_jtv_support(): + raise StreamError("Installed rtmpdump does not support --jtv argument") + + return StreamProcess.open(self) + + def _has_jtv_support(self): + try: + help = self.cmd(help=True, _err_to_out=True) + except pbs.ErrorReturnCode as err: + raise StreamError(("Error while checking rtmpdump compatibility: {0}").format(str(err.stdout, "ascii"))) + + for line in help.split("\n"): + if line[:5] == "--jtv": + return True + + return False + |