]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/gettr.py
2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
19 class GettrBaseIE(InfoExtractor
):
20 _BASE_REGEX
= r
'https?://(www\.)?gettr\.com/'
21 _MEDIA_BASE_URL
= 'https://media.gettr.com/'
23 def _call_api(self
, path
, video_id
, *args
, **kwargs
):
24 return self
._download
_json
(urljoin('https://api.gettr.com/u/', path
), video_id
, *args
, **kwargs
)['result']
27 class GettrIE(GettrBaseIE
):
28 _VALID_URL
= GettrBaseIE
._BASE
_REGEX
+ r
'post/(?P<id>[a-z0-9]+)'
31 'url': 'https://www.gettr.com/post/pcf6uv838f',
34 'title': 'md5:9086a646bbd06c41c4fe8e52b3c93454',
35 'description': 'md5:be0577f1e4caadc06de4a002da2bf287',
37 'uploader': 'EpochTV',
38 'uploader_id': 'epochtv',
39 'upload_date': '20210927',
40 'thumbnail': r
're:^https?://.+/out\.jpg',
41 'timestamp': 1632782451.058,
43 'tags': ['hornofafrica', 'explorations'],
46 'url': 'https://gettr.com/post/p4iahp',
49 'title': 'md5:b03c07883db6fbc1aab88877a6c3b149',
50 'description': 'md5:741b7419d991c403196ed2ea7749a39d',
52 'uploader': 'Neues Forum Freiheit',
53 'uploader_id': 'nf_freiheit',
54 'upload_date': '20210718',
55 'thumbnail': r
're:^https?://.+/out\.jpg',
56 'timestamp': 1626594455.017,
62 'url': 'https://gettr.com/post/pxn5b743a9',
63 'only_matching': True,
66 'url': 'https://gettr.com/post/pxtiiz5ca2',
67 'only_matching': True,
70 'url': 'https://gettr.com/post/pxlu8p3b13',
71 'only_matching': True,
74 'url': 'https://gettr.com/post/pv6wp9e24c',
75 'only_matching': True,
76 'add_ie': ['Youtube'],
79 def _real_extract(self
, url
):
80 post_id
= self
._match
_id
(url
)
81 webpage
= self
._download
_webpage
(url
, post_id
)
82 api_data
= self
._call
_api
('post/%s?incl="poststats|userinfo"' % post_id
, post_id
)
84 post_data
= api_data
.get('data')
85 user_data
= try_get(api_data
, lambda x
: x
['aux']['uinf'][post_data
['uid']], dict) or {}
87 vid
= post_data
.get('vid')
88 ovid
= post_data
.get('ovid')
90 if post_data
.get('p_type') == 'stream':
91 return self
.url_result(f
'https://gettr.com/streaming/{post_id}', ie
='GettrStreaming', video_id
=post_id
)
94 embed_url
= url_or_none(post_data
.get('prevsrc'))
95 shared_post_id
= traverse_obj(api_data
, ('aux', 'shrdpst', '_id'), ('data', 'rpstIds', 0), expected_type
=str)
98 return self
.url_result(embed_url
)
100 return self
.url_result(f
'https://gettr.com/post/{shared_post_id}', ie
='Gettr', video_id
=shared_post_id
)
102 raise ExtractorError('There\'s no video in this post.')
104 title
= description
= str_or_none(
105 post_data
.get('txt') or self
._og
_search
_description
(webpage
))
107 uploader
= str_or_none(
108 user_data
.get('nickname')
109 or self
._search
_regex
(r
'^(.+?) on GETTR', self
._og
_search
_title
(webpage
, default
=''), 'uploader', fatal
=False))
112 title
= '%s - %s' % (uploader
, title
)
114 formats
, subtitles
= self
._extract
_m
3u8_formats
_and
_subtitles
(
115 urljoin(self
._MEDIA
_BASE
_URL
, vid
), post_id
, 'mp4',
116 entry_protocol
='m3u8_native', m3u8_id
='hls', fatal
=False) if vid
else ([], {})
120 'url': urljoin(self
._MEDIA
_BASE
_URL
, ovid
),
123 'width': int_or_none(post_data
.get('vid_wid')),
124 'height': int_or_none(post_data
.get('vid_hgt')),
127 self
._sort
_formats
(formats
)
132 'description': description
,
134 'subtitles': subtitles
,
135 'uploader': uploader
,
136 'uploader_id': str_or_none(
137 dict_get(user_data
, ['_id', 'username'])
138 or post_data
.get('uid')),
139 'thumbnail': url_or_none(
140 urljoin(self
._MEDIA
_BASE
_URL
, post_data
.get('main'))
141 or self
._html
_search
_meta
(['og:image', 'image'], webpage
, 'thumbnail', fatal
=False)),
142 'timestamp': float_or_none(dict_get(post_data
, ['cdate', 'udate']), scale
=1000),
143 'duration': float_or_none(post_data
.get('vid_dur')),
144 'tags': post_data
.get('htgs'),
148 class GettrStreamingIE(GettrBaseIE
):
149 _VALID_URL
= GettrBaseIE
._BASE
_REGEX
+ r
'streaming/(?P<id>[a-z0-9]+)'
152 'url': 'https://gettr.com/streaming/psoiulc122',
156 'description': 'md5:56bca4b8f48f1743d9fd03d49c723017',
158 'uploader': 'Corona Investigative Committee',
159 'uploader_id': 'coronacommittee',
160 'duration': 5180.184,
161 'thumbnail': r
're:^https?://.+',
162 'title': 'Day 1: Opening Session of the Grand Jury Proceeding',
163 'timestamp': 1644080997.164,
164 'upload_date': '20220205',
167 'url': 'https://gettr.com/streaming/psfmeefcc1',
171 'title': 'Session 90: "The Virus Of Power"',
173 'uploader_id': 'coronacommittee',
174 'description': 'md5:98986acdf656aa836bf36f9c9704c65b',
175 'uploader': 'Corona Investigative Committee',
176 'thumbnail': r
're:^https?://.+',
177 'duration': 21872.507,
178 'timestamp': 1643976662.858,
179 'upload_date': '20220204',
183 def _real_extract(self
, url
):
184 video_id
= self
._match
_id
(url
)
185 video_info
= self
._call
_api
('live/join/%s' % video_id
, video_id
, data
={})
187 live_info
= video_info
['broadcast']
188 live_url
= url_or_none(live_info
.get('url'))
190 formats
, subtitles
= self
._extract
_m
3u8_formats
_and
_subtitles
(
191 live_url
, video_id
, ext
='mp4',
192 entry_protocol
='m3u8_native', m3u8_id
='hls', fatal
=False) if live_url
else ([], {})
195 'url': urljoin(self
._MEDIA
_BASE
_URL
, thumbnail
),
196 } for thumbnail
in try_get(video_info
, lambda x
: x
['postData']['imgs'], list) or []]
198 self
._sort
_formats
(formats
)
202 'title': try_get(video_info
, lambda x
: x
['postData']['ttl'], str),
203 'description': try_get(video_info
, lambda x
: x
['postData']['dsc'], str),
205 'subtitles': subtitles
,
206 'thumbnails': thumbnails
,
207 'uploader': try_get(video_info
, lambda x
: x
['liveHostInfo']['nickname'], str),
208 'uploader_id': try_get(video_info
, lambda x
: x
['liveHostInfo']['_id'], str),
209 'view_count': int_or_none(live_info
.get('viewsCount')),
210 'timestamp': float_or_none(live_info
.get('startAt'), scale
=1000),
211 'duration': float_or_none(live_info
.get('duration'), scale
=1000),
212 'is_live': bool_or_none(live_info
.get('isLive')),