diff options
author | Christopher Rosell <chrippa@tanuki.se> | 2012-03-21 22:49:15 +0100 |
---|---|---|
committer | Christopher Rosell <chrippa@tanuki.se> | 2012-03-21 22:49:15 +0100 |
commit | edfc2de50a4a15fc883a57dffed1e1ae60e93fc9 (patch) | |
tree | 8402d30dd8b5b0c6d4241cd9df542b95e0b1ba7c /src/livestreamer/plugins/justintv.py | |
parent | 1f413ed99ca82fc35e004b627654e3e41b8704a2 (diff) |
Make livestreamer more usable as a library.
Diffstat (limited to 'src/livestreamer/plugins/justintv.py')
-rw-r--r-- | src/livestreamer/plugins/justintv.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/livestreamer/plugins/justintv.py b/src/livestreamer/plugins/justintv.py index 8db4db4..b21f9a4 100644 --- a/src/livestreamer/plugins/justintv.py +++ b/src/livestreamer/plugins/justintv.py @@ -13,6 +13,8 @@ class JustinTV(Plugin): MetadataURL = "http://www.justin.tv/meta/{0}.xml?on_site=true" SWFURL = "http://www.justin.tv/widgets/live_embed_player.swf" + cookie = None + @classmethod def can_handle_url(self, url): return ("justin.tv" in url) or ("twitch.tv" in url) @@ -21,6 +23,10 @@ class JustinTV(Plugin): def handle_parser(self, parser): parser.add_argument("--jtv-cookie", metavar="cookie", help="JustinTV cookie to allow access to subscription channels") + @classmethod + def handle_args(self, args): + self.cookie = args.jtv_cookie + def _get_channel_name(self, url): fd = urllib.urlopen(url) data = fd.read() @@ -30,9 +36,9 @@ class JustinTV(Plugin): if match: return str(match.group(1), "ascii") - def _get_metadata(self, channel, cookie=None): - if cookie: - headers = {"Cookie": cookie} + def _get_metadata(self, channel): + if self.cookie: + headers = {"Cookie": self.cookie} req = urllib.Request(self.MetadataURL.format(channel), headers=headers) else: req = urllib.Request(self.MetadataURL.format(channel)) @@ -76,7 +82,7 @@ class JustinTV(Plugin): if not channelname: return False - metadata = self._get_metadata(channelname, self.args.jtv_cookie) + metadata = self._get_metadata(channelname) if "chansub_guid" in metadata: fd = urllib.urlopen(self.StreamInfoURLSub.format(channelname, randomp, metadata["chansub_guid"])) |