From 8a9578b460383c983de269742838f8515e9311c7 Mon Sep 17 00:00:00 2001 From: Christopher Rosell Date: Mon, 27 Aug 2012 13:51:17 +0200 Subject: livestreamer.plugins.gomtv: Add some logging. --- src/livestreamer/cli.py | 4 ++-- src/livestreamer/compat.py | 4 +--- src/livestreamer/plugins/gomtv.py | 17 +++++++++++++---- src/livestreamer/plugins/justintv.py | 4 ++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/livestreamer/cli.py b/src/livestreamer/cli.py index a36c837..f294d35 100644 --- a/src/livestreamer/cli.py +++ b/src/livestreamer/cli.py @@ -265,8 +265,8 @@ def main(): if args.stdout or args.output == "-": set_msg_output(sys.stderr) - if args.gomtv_password is True: - gomtv_password = getpass.getpass("GOMTV Password:") + if args.gomtv_username and (args.gomtv_password is None or (len(args.gomtv_password) < 1)): + gomtv_password = getpass.getpass("Enter GOMTV password: ") else: gomtv_password = args.gomtv_password diff --git a/src/livestreamer/compat.py b/src/livestreamer/compat.py index f023bd8..fb69c6c 100644 --- a/src/livestreamer/compat.py +++ b/src/livestreamer/compat.py @@ -26,13 +26,11 @@ except ImportError: try: from urllib.parse import urlparse, parse_qs, urlencode - import http.cookies as cookies import http.cookiejar as cookiejar except ImportError: from urlparse import urlparse, parse_qs from urllib import urlencode - import Cookie as cookies import cookielib as cookiejar __all__ = ["is_py2", "is_py3", "is_win32", "input", "stdout", "str", - "bytes", "urllib", "urlparse", "parse_qs", "cookies", "cookiejar"] + "bytes", "urllib", "urlparse", "parse_qs", "cookiejar"] diff --git a/src/livestreamer/plugins/gomtv.py b/src/livestreamer/plugins/gomtv.py index bdfbbec..8d7c3c9 100644 --- a/src/livestreamer/plugins/gomtv.py +++ b/src/livestreamer/plugins/gomtv.py @@ -21,7 +21,7 @@ limitations under the License. """ -from livestreamer.compat import str, bytes, urlencode, urllib, urlparse, cookies, cookiejar +from livestreamer.compat import str, bytes, urlencode, urllib, urlparse, cookiejar from livestreamer.plugins import Plugin, PluginError, NoStreamsError from livestreamer.stream import HTTPStream from livestreamer.utils import urlget @@ -57,7 +57,7 @@ class GomTV(Plugin): def _get_streams(self): options = self.options # Setting urllib up so that we can store cookies - self.cookiejar = cookiejar.LWPCookieJar() + self.cookiejar = cookiejar.CookieJar() self.opener = urllib.build_opener(urllib.HTTPCookieProcessor(self.cookiejar)) if options.get("cookie"): @@ -89,7 +89,6 @@ class GomTV(Plugin): if (username is None or password is None) and cookies is None: raise PluginError("GOMTV.net Requires a username and password or cookie") - if cookies is not None: for cookie in cookies.split(";"): try: @@ -97,13 +96,15 @@ class GomTV(Plugin): except ValueError: continue - c = cookiejar.Cookie(version=0, name=name, value=value, + c = cookiejar.Cookie(version=0, name=name.strip(), value=value.strip(), port=None, port_specified=False, domain="gomtv.net", domain_specified=False, domain_initial_dot=False, path="/", path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={"HttpOnly": None}, rfc2109=False) self.cookiejar.set_cookie(c) + + self.logger.info("Attempting to authenticate with cookies") else: values = { "cmd": "login", @@ -114,12 +115,20 @@ class GomTV(Plugin): data = bytes(urlencode(values), "ascii") headers = {"Referer": self.BaseURL} request = urllib.Request(self.LoginURL, data, headers) + + self.logger.info("Attempting to authenticate with username/password") urlget(request, opener=self.opener) + req = urllib.Request(self.LoginCheckURL) if b"Please need login" in urlget(req, opener=self.opener): raise PluginError("Authentication failed") + for cookie in self.cookiejar: + if cookie.name == "SES_USERNICK": + self.logger.info(("Successfully logged in as {0}").format(cookie.value)) + break + def getEventLivePageURL(self, gomtvLiveURL, response): match = re.search(' \"(.*)\";', response) diff --git a/src/livestreamer/plugins/justintv.py b/src/livestreamer/plugins/justintv.py index 4aeca9b..d40c32e 100644 --- a/src/livestreamer/plugins/justintv.py +++ b/src/livestreamer/plugins/justintv.py @@ -73,13 +73,13 @@ class JustinTV(Plugin): chansub = None if self.options.get("cookie") is not None: - self.logger.debug("Attempting to authenticate using cookie") + self.logger.info("Attempting to authenticate using cookies") metadata = self._get_metadata(channelname) chansub = metadata["access_guid"] if "login" in metadata and metadata["login"] is not None: - self.logger.debug("Successfully logged in as {0}", metadata["login"]) + self.logger.info("Successfully logged in as {0}", metadata["login"]) randomp = int(random.random() * 999999) -- cgit v1.2.3