aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/livestreamer/plugins
diff options
context:
space:
mode:
authorGravatar Christopher Rosell <chrippa@tanuki.se>2012-03-21 16:24:45 +0100
committerGravatar Christopher Rosell <chrippa@tanuki.se>2012-03-21 16:24:45 +0100
commit0f3765749001279fe232914bfa852650c4fd1162 (patch)
tree4236330f90d37783ddb76418a106b70d3912d6c1 /src/livestreamer/plugins
parentf175241692dfc461d773589653fd55c47508a293 (diff)
Refactor the stream/command line handling.
Diffstat (limited to 'src/livestreamer/plugins')
-rw-r--r--src/livestreamer/plugins/__init__.py3
-rw-r--r--src/livestreamer/plugins/justintv.py37
-rw-r--r--src/livestreamer/plugins/ownedtv.py21
-rw-r--r--src/livestreamer/plugins/ustreamtv.py26
4 files changed, 29 insertions, 58 deletions
diff --git a/src/livestreamer/plugins/__init__.py b/src/livestreamer/plugins/__init__.py
index 1eaf829..a989799 100644
--- a/src/livestreamer/plugins/__init__.py
+++ b/src/livestreamer/plugins/__init__.py
@@ -24,9 +24,6 @@ class Plugin(object):
def get_streams(self):
raise NotImplementedError
- def stream_cmdline(self, stream, filename):
- raise NotImplementedError
-
def load_plugins(plugins):
for loader, name, ispkg in pkgutil.iter_modules(plugins.__path__):
file, pathname, desc = imp.find_module(name, plugins.__path__)
diff --git a/src/livestreamer/plugins/justintv.py b/src/livestreamer/plugins/justintv.py
index 233a17b..8db4db4 100644
--- a/src/livestreamer/plugins/justintv.py
+++ b/src/livestreamer/plugins/justintv.py
@@ -1,7 +1,8 @@
#!/usr/bin/env python3
from livestreamer.plugins import Plugin, register_plugin
-from livestreamer.utils import CommandLine, swfverify
+from livestreamer.stream import RTMPStream
+from livestreamer.utils import swfverify
from livestreamer.compat import urllib, str
import xml.dom.minidom, re, sys, random
@@ -93,31 +94,27 @@ class JustinTV(Plugin):
dom = xml.dom.minidom.parseString(data)
nodes = dom.getElementsByTagName("nodes")[0]
+ swfhash, swfsize = swfverify(self.SWFURL)
+
for node in nodes.childNodes:
- stream = {}
+ info = {}
for child in node.childNodes:
- stream[child.tagName] = self._get_node_text(child)
+ info[child.tagName] = self._get_node_text(child)
+
+ stream = RTMPStream({
+ "rtmp": ("{0}/{1}").format(info["connect"], info["play"]),
+ "swfUrl": self.SWFURL,
+ "swfhash": swfhash,
+ "swfsize": swfsize,
+ "live": 1
+ })
+
+ if "token" in info:
+ stream.params["jtv"] = info["token"]
sname = clean_tag(node.tagName)
streams[sname] = stream
return streams
- def stream_cmdline(self, stream, filename):
- swfhash, swfsize = swfverify(self.SWFURL)
-
- cmd = CommandLine("rtmpdump")
- cmd.arg("rtmp", ("{0}/{1}").format(stream["connect"], stream["play"]))
- cmd.arg("swfUrl", self.SWFURL)
- cmd.arg("swfhash", swfhash)
- cmd.arg("swfsize", swfsize)
- cmd.arg("live", True)
- cmd.arg("flv", filename)
-
- if "token" in stream:
- cmd.arg("jtv", stream["token"])
-
- return cmd.format()
-
-
register_plugin("justintv", JustinTV)
diff --git a/src/livestreamer/plugins/ownedtv.py b/src/livestreamer/plugins/ownedtv.py
index 779dd2c..ab9c479 100644
--- a/src/livestreamer/plugins/ownedtv.py
+++ b/src/livestreamer/plugins/ownedtv.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
from livestreamer.plugins import Plugin, register_plugin
-from livestreamer.utils import CommandLine
+from livestreamer.stream import RTMPStream
from livestreamer.compat import urllib
import xml.dom.minidom, re
@@ -76,22 +76,11 @@ class OwnedTV(Plugin):
playpath = streamel.getAttribute("name")
if not name in streams:
- streams[name] = {
- "base": base,
- "name": name,
- "playpath": playpath
- }
+ streams[name] = RTMPStream({
+ "rtmp": ("{0}/{1}").format(base, playpath),
+ "live": 1
+ })
return streams
-
- def stream_cmdline(self, stream, filename):
- cmd = CommandLine("rtmpdump")
- cmd.arg("rtmp", ("{0}/{1}").format(stream["base"], stream["playpath"]))
- cmd.arg("live", True)
- cmd.arg("flv", filename)
-
- return cmd.format()
-
-
register_plugin("own3dtv", OwnedTV)
diff --git a/src/livestreamer/plugins/ustreamtv.py b/src/livestreamer/plugins/ustreamtv.py
index f191589..5f120f5 100644
--- a/src/livestreamer/plugins/ustreamtv.py
+++ b/src/livestreamer/plugins/ustreamtv.py
@@ -1,12 +1,11 @@
#!/usr/bin/env python3
from livestreamer.plugins import Plugin, register_plugin
-from livestreamer.utils import CommandLine
+from livestreamer.stream import RTMPStream
from livestreamer.compat import urllib, str, bytes
import xml.dom.minidom, re
-
class UStreamTV(Plugin):
AMFURL = "http://cgw.ustream.tv/Viewer/getStream/1/{0}.amf"
SWFURL = "http://cdn1.ustream.tv/swf/4/viewer.rsl.210.swf"
@@ -40,8 +39,6 @@ class UStreamTV(Plugin):
data = fd.read()
fd.close()
- stream = {}
-
playpath = get_amf_value(data, "streamName")
cdnurl = get_amf_value(data, "cdnUrl")
fmsurl = get_amf_value(data, "fmsUrl")
@@ -49,22 +46,13 @@ class UStreamTV(Plugin):
if not playpath:
return False
- stream["playpath"] = playpath
- stream["rtmp"] = cdnurl or fmsurl
- stream["url"] = self.url
+ stream = RTMPStream({
+ "rtmp": ("{0}/{1}").format(cdnurl or fmsurl, playpath),
+ "pageUrl": self.url,
+ "swfUrl": self.SWFURL,
+ "live": 1
+ })
return {"live": stream}
-
- def stream_cmdline(self, stream, filename):
- cmd = CommandLine("rtmpdump")
- cmd.arg("rtmp", ("{0}/{1}").format(stream["rtmp"], stream["playpath"]))
- cmd.arg("swfUrl", self.SWFURL)
- cmd.arg("pageUrl", stream["url"])
- cmd.arg("live", True)
- cmd.arg("flv", filename)
-
- return cmd.format()
-
-
register_plugin("ustreamtv", UStreamTV)