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
(compat_urllib_parse_unquote(auth
.value
), None, fatal
=False)
60 self
._jwt
= auth
.get('jwt')
62 def _perform_login(self
, username
, password
):
65 auth
= self
._download
_json
(
66 'https://auth.gaia.com/v1/login',
67 None, data
=urlencode_postdata({
71 if auth
.get('success') is False:
72 raise ExtractorError(', '.join(auth
['messages']), expected
=True)
73 self
._jwt
= auth
.get('jwt')
75 def _real_extract(self
, url
):
76 display_id
, vtype
= self
._match
_valid
_url
(url
).groups()
77 node_id
= self
._download
_json
(
78 'https://brooklyn.gaia.com/pathinfo', display_id
, query
={
79 'path': 'video/' + display_id
,
81 node
= self
._download
_json
(
82 'https://brooklyn.gaia.com/node/%d' % node_id
, node_id
)
84 media_id
= compat_str(vdata
['nid'])
89 headers
= {'Authorization': 'Bearer ' + self._jwt}
90 media
= self
._download
_json
(
91 'https://brooklyn.gaia.com/media/' + media_id
,
92 media_id
, headers
=headers
)
93 formats
= self
._extract
_m
3u8_formats
(
94 media
['mediaUrls']['bcHLS'], media_id
, 'mp4')
95 self
._sort
_formats
(formats
)
98 text_tracks
= media
.get('textTracks', {})
99 for key
in ('captions', 'subtitles'):
100 for lang
, sub_url
in text_tracks
.get(key
, {}).items():
101 subtitles
.setdefault(lang
, []).append({
105 fivestar
= node
.get('fivestar', {})
106 fields
= node
.get('fields', {})
108 def get_field_value(key
, value_key
='value'):
109 return try_get(fields
, lambda x
: x
[key
][0][value_key
])
113 'display_id': display_id
,
116 'description': strip_or_none(get_field_value('body') or get_field_value('teaser')),
117 'timestamp': int_or_none(node
.get('created')),
118 'subtitles': subtitles
,
119 'duration': int_or_none(vdata
.get('duration')),
120 'like_count': int_or_none(try_get(fivestar
, lambda x
: x
['up_count']['value'])),
121 'dislike_count': int_or_none(try_get(fivestar
, lambda x
: x
['down_count']['value'])),
122 'comment_count': int_or_none(node
.get('comment_count')),
123 'series': try_get(node
, lambda x
: x
['series']['title'], compat_str
),
124 'season_number': int_or_none(get_field_value('season')),
125 'season_id': str_or_none(get_field_value('series_nid', 'nid')),
126 'episode_number': int_or_none(get_field_value('episode')),