mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-30 07:38:18 +01:00
[gaia] add support for authentication(closes #14605)
This commit is contained in:
parent
c0b7d11713
commit
313e8b2b18
|
@ -4,12 +4,17 @@ from __future__ import unicode_literals
|
|||
import re
|
||||
|
||||
from .common import InfoExtractor
|
||||
from ..compat import compat_str
|
||||
from ..compat import (
|
||||
compat_str,
|
||||
compat_urllib_parse_unquote,
|
||||
)
|
||||
from ..utils import (
|
||||
ExtractorError,
|
||||
int_or_none,
|
||||
str_or_none,
|
||||
strip_or_none,
|
||||
try_get,
|
||||
urlencode_postdata,
|
||||
)
|
||||
|
||||
|
||||
|
@ -46,6 +51,29 @@ class GaiaIE(InfoExtractor):
|
|||
'skip_download': True,
|
||||
},
|
||||
}]
|
||||
_NETRC_MACHINE = 'gaia'
|
||||
_jwt = None
|
||||
|
||||
def _real_initialize(self):
|
||||
auth = self._get_cookies('https://www.gaia.com/').get('auth')
|
||||
if auth:
|
||||
auth = self._parse_json(
|
||||
compat_urllib_parse_unquote(auth.value),
|
||||
None, fatal=False)
|
||||
if not auth:
|
||||
username, password = self._get_login_info()
|
||||
if username is None:
|
||||
return
|
||||
auth = self._download_json(
|
||||
'https://auth.gaia.com/v1/login',
|
||||
None, data=urlencode_postdata({
|
||||
'username': username,
|
||||
'password': password
|
||||
}))
|
||||
if auth.get('success') is False:
|
||||
raise ExtractorError(', '.join(auth['messages']), expected=True)
|
||||
if auth:
|
||||
self._jwt = auth.get('jwt')
|
||||
|
||||
def _real_extract(self, url):
|
||||
display_id, vtype = re.search(self._VALID_URL, url).groups()
|
||||
|
@ -59,8 +87,12 @@ class GaiaIE(InfoExtractor):
|
|||
media_id = compat_str(vdata['nid'])
|
||||
title = node['title']
|
||||
|
||||
headers = None
|
||||
if self._jwt:
|
||||
headers = {'Authorization': 'Bearer ' + self._jwt}
|
||||
media = self._download_json(
|
||||
'https://brooklyn.gaia.com/media/' + media_id, media_id)
|
||||
'https://brooklyn.gaia.com/media/' + media_id,
|
||||
media_id, headers=headers)
|
||||
formats = self._extract_m3u8_formats(
|
||||
media['mediaUrls']['bcHLS'], media_id, 'mp4')
|
||||
self._sort_formats(formats)
|
||||
|
|
Loading…
Reference in New Issue
Block a user