diff options
author | Christopher Rosell <chrippa@tanuki.se> | 2011-08-15 04:37:22 +0200 |
---|---|---|
committer | Christopher Rosell <chrippa@tanuki.se> | 2011-08-15 04:37:22 +0200 |
commit | 03ff523bfe2f2a3848470ce0ca46f2ef7116453c (patch) | |
tree | eca46b63d5eee1b67c662c67874ac1f4a6bca5de /src/livestreamer/plugins/ustreamtv.py |
Initial commit.
Diffstat (limited to 'src/livestreamer/plugins/ustreamtv.py')
-rw-r--r-- | src/livestreamer/plugins/ustreamtv.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/livestreamer/plugins/ustreamtv.py b/src/livestreamer/plugins/ustreamtv.py new file mode 100644 index 0000000..a33b1d4 --- /dev/null +++ b/src/livestreamer/plugins/ustreamtv.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 + +from livestreamer.plugins import Plugin, register_plugin +from livestreamer.utils import CommandLine + +import urllib.request, urllib.error, urllib.parse +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" + + def can_handle_url(self, url): + return "ustream.tv" in url + + def get_channel_id(self, url): + fd = urllib.request.urlopen(url) + data = fd.read() + fd.close() + + match = re.search(b"channelId=(\d+)", data) + if match: + return int(match.group(1)) + + def get_streams(self, url): + def get_amf_value(data, key): + pattern = ("{0}\W\W\W(.+?)\x00").format(key) + match = re.search(bytes(pattern, "ascii"), data) + if match: + return str(match.group(1), "ascii") + + channelid = self.get_channel_id(url) + + if not channelid: + return False + + fd = urllib.request.urlopen(self.AMFURL.format(channelid)) + data = fd.read() + fd.close() + + stream = {} + + playpath = get_amf_value(data, "streamName") + cdnurl = get_amf_value(data, "cdnUrl") + fmsurl = get_amf_value(data, "fmsUrl") + + if not playpath: + return False + + stream["playpath"] = playpath + stream["rtmp"] = cdnurl or fmsurl + stream["url"] = url + + 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) |