diff options
author | Christopher Rosell <chrippa@tanuki.se> | 2012-04-21 21:57:20 +0200 |
---|---|---|
committer | Christopher Rosell <chrippa@tanuki.se> | 2012-04-21 21:57:20 +0200 |
commit | 22dd8a40c8bb9c1c7e845a47df5b84dfe2a8527e (patch) | |
tree | 2a60947960ccd89fd19ad45e992545dc8454ba8b /src/livestreamer/plugins/ownedtv.py | |
parent | e3b3bdf86e9e9921ce6c76e8dd587dbe0b41f33e (diff) |
Added PluginError exception to make error handling nicer.
Also added a utility function to do HTTP requests.
Diffstat (limited to 'src/livestreamer/plugins/ownedtv.py')
-rw-r--r-- | src/livestreamer/plugins/ownedtv.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/livestreamer/plugins/ownedtv.py b/src/livestreamer/plugins/ownedtv.py index 6461c15..c15e8c4 100644 --- a/src/livestreamer/plugins/ownedtv.py +++ b/src/livestreamer/plugins/ownedtv.py @@ -1,8 +1,9 @@ #!/usr/bin/env python3 -from livestreamer.plugins import Plugin, register_plugin -from livestreamer.stream import RTMPStream from livestreamer.compat import urllib +from livestreamer.plugins import Plugin, PluginError, register_plugin +from livestreamer.stream import RTMPStream +from livestreamer.utils import urlget import xml.dom.minidom, re @@ -34,9 +35,7 @@ class OwnedTV(Plugin): return "own3d.tv" in url def _get_channel_id(self, url): - fd = urlopener.open(url) - data = fd.read() - fd.close() + data = urlget(url, opener=urlopener) match = re.search(b"document.location.hash='/live/(\d+)'", data) if match: @@ -51,11 +50,13 @@ class OwnedTV(Plugin): streams = {} if channelid: - fd = urllib.urlopen(self.ConfigURL.format(channelid)) - data = fd.read() - fd.close() + data = urlget(self.ConfigURL.format(channelid)) + + try: + dom = xml.dom.minidom.parseString(data) + except Exception as err: + raise PluginError(("Unable to parse config XML: {0})").format(err)) - dom = xml.dom.minidom.parseString(data) channels = dom.getElementsByTagName("channels")[0] clip = channels.getElementsByTagName("clip")[0] |