mirror of
https://github.com/l1ving/youtube-dl
synced 2025-03-08 09:27:17 +08:00
[unauthorizedtv] Support login
This commit is contained in:
parent
2190c8a268
commit
f1bcfe63bf
@ -1,38 +1,45 @@
|
||||
# coding: utf-8
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
|
||||
from .common import InfoExtractor
|
||||
from ..utils import (
|
||||
ExtractorError,
|
||||
)
|
||||
|
||||
|
||||
class UnauthorizedTvIE(InfoExtractor):
|
||||
_VALID_URL = r'https?://(?:www\.)?unauthorized\.tv/programs/.*?cid=(?P<id>\d+)'
|
||||
_TEST = {
|
||||
'url': 'https://www.unauthorized.tv/programs/owens-shorts?cid=231148',
|
||||
'md5': 'dd9a5b81b9704c68942c2584086dd73f',
|
||||
'info_dict': {
|
||||
'id': '231148',
|
||||
'ext': 'mp4',
|
||||
'title': 'Millennials',
|
||||
}
|
||||
}
|
||||
_LOGIN_URL = 'https://www.unauthorized.tv/api/sessions'
|
||||
_NETRC_MACHINE = 'unauthorizedtv'
|
||||
|
||||
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)
|
||||
|
||||
headers = {
|
||||
'Referer': url,
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
'X-CSRF-Token': csrf_token,
|
||||
data = {
|
||||
'email': username,
|
||||
'password': password,
|
||||
}
|
||||
|
||||
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(
|
||||
'https://www.unauthorized.tv/api/chapters?ids[]=%s' % video_id,
|
||||
video_id,
|
||||
headers=headers
|
||||
)
|
||||
|
||||
video_title = metadata[0]['title']
|
||||
|
Loading…
x
Reference in New Issue
Block a user