aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/extractor
diff options
context:
space:
mode:
authorRemita Amine <remitamine@gmail.com>2019-04-02 15:49:43 +0100
committerRemita Amine <remitamine@gmail.com>2019-04-02 15:50:06 +0100
commit313e8b2b18d6befc27ce145f49583d90ba8caee2 (patch)
tree47dfeaa234e76bacd6239e456cf86a31abd261c7 /youtube_dl/extractor
parentc0b7d11713e57b75189a38b3732aa217f149e5ef (diff)
[gaia] add support for authentication(closes #14605)
Diffstat (limited to 'youtube_dl/extractor')
-rw-r--r--youtube_dl/extractor/gaia.py36
1 files changed, 34 insertions, 2 deletions
diff --git a/youtube_dl/extractor/gaia.py b/youtube_dl/extractor/gaia.py
index f2eef3f4c..e9527758f 100644
--- a/youtube_dl/extractor/gaia.py
+++ b/youtube_dl/extractor/gaia.py
@@ -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)