[unauthorizedtv] Support login

This commit is contained in:
Kevin G 2019-12-21 20:25:39 -08:00
parent 2190c8a268
commit f1bcfe63bf

View File

@ -1,38 +1,45 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import json
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import (
ExtractorError,
)
class UnauthorizedTvIE(InfoExtractor): class UnauthorizedTvIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?unauthorized\.tv/programs/.*?cid=(?P<id>\d+)' _VALID_URL = r'https?://(?:www\.)?unauthorized\.tv/programs/.*?cid=(?P<id>\d+)'
_TEST = { _LOGIN_URL = 'https://www.unauthorized.tv/api/sessions'
'url': 'https://www.unauthorized.tv/programs/owens-shorts?cid=231148', _NETRC_MACHINE = 'unauthorizedtv'
'md5': 'dd9a5b81b9704c68942c2584086dd73f',
'info_dict': {
'id': '231148',
'ext': 'mp4',
'title': 'Millennials',
}
}
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url)
html = self._download_webpage(url, video_id) username, password = self._get_login_info()
if username is None:
self.raise_login_required()
csrf_token = self._html_search_meta('csrf-token', html, 'csrf token', fatal=True) data = {
'email': username,
headers = { 'password': password,
'Referer': url,
'X-Requested-With': 'XMLHttpRequest',
'X-CSRF-Token': csrf_token,
} }
login_page = self._download_json(
self._LOGIN_URL, None, 'Logging in',
data=json.dumps(data).encode(), headers={
'Content-Type': 'application/json',
'Referer': self._LOGIN_URL,
})
if login_page.get('id') is None:
raise ExtractorError('Invalid username or password', expected=True)
video_id = self._match_id(url)
metadata = self._download_json( metadata = self._download_json(
'https://www.unauthorized.tv/api/chapters?ids[]=%s' % video_id, 'https://www.unauthorized.tv/api/chapters?ids[]=%s' % video_id,
video_id, video_id,
headers=headers
) )
video_title = metadata[0]['title'] video_title = metadata[0]['title']