2 from __future__
import unicode_literals
5 from .common
import InfoExtractor
8 compat_urllib_parse_unquote
,
20 class GaiaIE(InfoExtractor
):
21 _VALID_URL
= r
'https?://(?:www\.)?gaia\.com/video/(?P<id>[^/?]+).*?\bfullplayer=(?P<type>feature|preview)'
23 'url': 'https://www.gaia.com/video/connecting-universal-consciousness?fullplayer=feature',
27 'title': 'Connecting with Universal Consciousness',
28 'description': 'md5:844e209ad31b7d31345f5ed689e3df6f',
29 'upload_date': '20151116',
30 'timestamp': 1447707266,
35 'skip_download': True,
38 'url': 'https://www.gaia.com/video/connecting-universal-consciousness?fullplayer=preview',
42 'title': 'Connecting with Universal Consciousness',
43 'description': 'md5:844e209ad31b7d31345f5ed689e3df6f',
44 'upload_date': '20151116',
45 'timestamp': 1447707266,
50 'skip_download': True,
53 _NETRC_MACHINE
= 'gaia'
56 def _real_initialize(self
):
57 auth
= self
._get
_cookies
('https://www.gaia.com/').get('auth')
59 auth
= self
._parse
_json
(
60 compat_urllib_parse_unquote(auth
.value
),
63 username
, password
= self
._get
_login
_info
()
66 auth
= self
._download
_json
(
67 'https://auth.gaia.com/v1/login',
68 None, data
=urlencode_postdata({
72 if auth
.get('success') is False:
73 raise ExtractorError(', '.join(auth
['messages']), expected
=True)
75 self
._jwt
= auth
.get('jwt')
77 def _real_extract(self
, url
):
78 display_id
, vtype
= self
._match
_valid
_url
(url
).groups()
79 node_id
= self
._download
_json
(
80 'https://brooklyn.gaia.com/pathinfo', display_id
, query
={
81 'path': 'video/' + display_id
,
83 node
= self
._download
_json
(
84 'https://brooklyn.gaia.com/node/%d' % node_id
, node_id
)
86 media_id
= compat_str(vdata
['nid'])
91 headers
= {'Authorization': 'Bearer ' + self._jwt}
92 media
= self
._download
_json
(
93 'https://brooklyn.gaia.com/media/' + media_id
,
94 media_id
, headers
=headers
)
95 formats
= self
._extract
_m
3u8_formats
(
96 media
['mediaUrls']['bcHLS'], media_id
, 'mp4')
97 self
._sort
_formats
(formats
)
100 text_tracks
= media
.get('textTracks', {})
101 for key
in ('captions', 'subtitles'):
102 for lang
, sub_url
in text_tracks
.get(key
, {}).items():
103 subtitles
.setdefault(lang
, []).append({
107 fivestar
= node
.get('fivestar', {})
108 fields
= node
.get('fields', {})
110 def get_field_value(key
, value_key
='value'):
111 return try_get(fields
, lambda x
: x
[key
][0][value_key
])
115 'display_id': display_id
,
118 'description': strip_or_none(get_field_value('body') or get_field_value('teaser')),
119 'timestamp': int_or_none(node
.get('created')),
120 'subtitles': subtitles
,
121 'duration': int_or_none(vdata
.get('duration')),
122 'like_count': int_or_none(try_get(fivestar
, lambda x
: x
['up_count']['value'])),
123 'dislike_count': int_or_none(try_get(fivestar
, lambda x
: x
['down_count']['value'])),
124 'comment_count': int_or_none(node
.get('comment_count')),
125 'series': try_get(node
, lambda x
: x
['series']['title'], compat_str
),
126 'season_number': int_or_none(get_field_value('season')),
127 'season_id': str_or_none(get_field_value('series_nid', 'nid')),
128 'episode_number': int_or_none(get_field_value('episode')),