From 04d02a9d57c834d3044871ce7dcc90932e686e46 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sergey=20M=E2=80=A4?= Date: Sat, 6 Dec 2014 21:24:20 +0600 Subject: [PATCH] [twitch] Add login support (#3986) --- youtube_dl/extractor/twitch.py | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/youtube_dl/extractor/twitch.py b/youtube_dl/extractor/twitch.py index 36aa1ad6e..397d167e8 100644 --- a/youtube_dl/extractor/twitch.py +++ b/youtube_dl/extractor/twitch.py @@ -1,3 +1,4 @@ +# coding: utf-8 from __future__ import unicode_literals import itertools @@ -5,6 +6,8 @@ import re from .common import InfoExtractor from ..utils import ( + compat_urllib_parse, + compat_urllib_request, ExtractorError, parse_iso8601, ) @@ -24,6 +27,7 @@ class TwitchIE(InfoExtractor): """ _PAGE_LIMIT = 100 _API_BASE = 'https://api.twitch.tv' + _LOGIN_URL = 'https://secure.twitch.tv/user/login' _TESTS = [{ 'url': 'http://www.twitch.tv/riotgames/b/577357806', 'info_dict': { @@ -109,6 +113,44 @@ class TwitchIE(InfoExtractor): 'view_count': info['views'], } + def _real_initialize(self): + self._login() + + def _login(self): + (username, password) = self._get_login_info() + if username is None: + return + + login_page = self._download_webpage( + self._LOGIN_URL, None, 'Downloading login page') + + authenticity_token = self._search_regex( + r']*>(?P[^<]+)", response) + if m: + raise ExtractorError( + 'Unable to login: %s' % m.group('msg').strip(), expected=True) + def _real_extract(self, url): mobj = re.match(self._VALID_URL, url) if mobj.group('chapterid'): -- 2.22.2