]>
Commit | Line | Data |
---|---|---|
3c1089db | 1 | from .common import InfoExtractor |
313e8b2b RA |
2 | from ..compat import ( |
3 | compat_str, | |
4 | compat_urllib_parse_unquote, | |
5 | ) | |
3c1089db | 6 | from ..utils import ( |
313e8b2b | 7 | ExtractorError, |
3c1089db RA |
8 | int_or_none, |
9 | str_or_none, | |
10 | strip_or_none, | |
11 | try_get, | |
313e8b2b | 12 | urlencode_postdata, |
3c1089db RA |
13 | ) |
14 | ||
15 | ||
16 | class GaiaIE(InfoExtractor): | |
17 | _VALID_URL = r'https?://(?:www\.)?gaia\.com/video/(?P<id>[^/?]+).*?\bfullplayer=(?P<type>feature|preview)' | |
18 | _TESTS = [{ | |
19 | 'url': 'https://www.gaia.com/video/connecting-universal-consciousness?fullplayer=feature', | |
20 | 'info_dict': { | |
21 | 'id': '89356', | |
22 | 'ext': 'mp4', | |
23 | 'title': 'Connecting with Universal Consciousness', | |
24 | 'description': 'md5:844e209ad31b7d31345f5ed689e3df6f', | |
25 | 'upload_date': '20151116', | |
26 | 'timestamp': 1447707266, | |
27 | 'duration': 936, | |
28 | }, | |
29 | 'params': { | |
30 | # m3u8 download | |
31 | 'skip_download': True, | |
32 | }, | |
33 | }, { | |
34 | 'url': 'https://www.gaia.com/video/connecting-universal-consciousness?fullplayer=preview', | |
35 | 'info_dict': { | |
36 | 'id': '89351', | |
37 | 'ext': 'mp4', | |
38 | 'title': 'Connecting with Universal Consciousness', | |
39 | 'description': 'md5:844e209ad31b7d31345f5ed689e3df6f', | |
40 | 'upload_date': '20151116', | |
41 | 'timestamp': 1447707266, | |
42 | 'duration': 53, | |
43 | }, | |
44 | 'params': { | |
45 | # m3u8 download | |
46 | 'skip_download': True, | |
47 | }, | |
48 | }] | |
313e8b2b RA |
49 | _NETRC_MACHINE = 'gaia' |
50 | _jwt = None | |
51 | ||
52 | def _real_initialize(self): | |
53 | auth = self._get_cookies('https://www.gaia.com/').get('auth') | |
54 | if auth: | |
52efa4b3 | 55 | auth = self._parse_json(compat_urllib_parse_unquote(auth.value), None, fatal=False) |
313e8b2b | 56 | self._jwt = auth.get('jwt') |
3c1089db | 57 | |
52efa4b3 | 58 | def _perform_login(self, username, password): |
59 | if self._jwt: | |
60 | return | |
61 | auth = self._download_json( | |
62 | 'https://auth.gaia.com/v1/login', | |
63 | None, data=urlencode_postdata({ | |
64 | 'username': username, | |
65 | 'password': password | |
66 | })) | |
67 | if auth.get('success') is False: | |
68 | raise ExtractorError(', '.join(auth['messages']), expected=True) | |
69 | self._jwt = auth.get('jwt') | |
70 | ||
3c1089db | 71 | def _real_extract(self, url): |
5ad28e7f | 72 | display_id, vtype = self._match_valid_url(url).groups() |
3c1089db RA |
73 | node_id = self._download_json( |
74 | 'https://brooklyn.gaia.com/pathinfo', display_id, query={ | |
75 | 'path': 'video/' + display_id, | |
76 | })['id'] | |
77 | node = self._download_json( | |
78 | 'https://brooklyn.gaia.com/node/%d' % node_id, node_id) | |
79 | vdata = node[vtype] | |
80 | media_id = compat_str(vdata['nid']) | |
81 | title = node['title'] | |
82 | ||
313e8b2b RA |
83 | headers = None |
84 | if self._jwt: | |
85 | headers = {'Authorization': 'Bearer ' + self._jwt} | |
3c1089db | 86 | media = self._download_json( |
313e8b2b RA |
87 | 'https://brooklyn.gaia.com/media/' + media_id, |
88 | media_id, headers=headers) | |
3c1089db RA |
89 | formats = self._extract_m3u8_formats( |
90 | media['mediaUrls']['bcHLS'], media_id, 'mp4') | |
3c1089db RA |
91 | |
92 | subtitles = {} | |
93 | text_tracks = media.get('textTracks', {}) | |
94 | for key in ('captions', 'subtitles'): | |
95 | for lang, sub_url in text_tracks.get(key, {}).items(): | |
96 | subtitles.setdefault(lang, []).append({ | |
97 | 'url': sub_url, | |
98 | }) | |
99 | ||
100 | fivestar = node.get('fivestar', {}) | |
101 | fields = node.get('fields', {}) | |
102 | ||
103 | def get_field_value(key, value_key='value'): | |
104 | return try_get(fields, lambda x: x[key][0][value_key]) | |
105 | ||
106 | return { | |
107 | 'id': media_id, | |
108 | 'display_id': display_id, | |
109 | 'title': title, | |
110 | 'formats': formats, | |
111 | 'description': strip_or_none(get_field_value('body') or get_field_value('teaser')), | |
112 | 'timestamp': int_or_none(node.get('created')), | |
113 | 'subtitles': subtitles, | |
114 | 'duration': int_or_none(vdata.get('duration')), | |
115 | 'like_count': int_or_none(try_get(fivestar, lambda x: x['up_count']['value'])), | |
116 | 'dislike_count': int_or_none(try_get(fivestar, lambda x: x['down_count']['value'])), | |
117 | 'comment_count': int_or_none(node.get('comment_count')), | |
118 | 'series': try_get(node, lambda x: x['series']['title'], compat_str), | |
119 | 'season_number': int_or_none(get_field_value('season')), | |
120 | 'season_id': str_or_none(get_field_value('series_nid', 'nid')), | |
121 | 'episode_number': int_or_none(get_field_value('episode')), | |
122 | } |