]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/gotostage.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / yt_dlp / extractor / gotostage.py
CommitLineData
e897bd82
SS
1import json
2
92ddaa41 3from .common import InfoExtractor
e897bd82 4from ..utils import try_get, url_or_none
92ddaa41
P
5
6
7class GoToStageIE(InfoExtractor):
8 _VALID_URL = r'https?://(?:www\.)?gotostage\.com/channel/[a-z0-9]+/recording/(?P<id>[a-z0-9]+)/watch'
9 _TESTS = [{
10 'url': 'https://www.gotostage.com/channel/8901680603948959494/recording/60bb55548d434f21b9ce4f0e225c4895/watch',
11 'md5': 'ca72ce990cdcd7a2bd152f7217e319a2',
12 'info_dict': {
13 'id': '60bb55548d434f21b9ce4f0e225c4895',
14 'ext': 'mp4',
15 'title': 'What is GoToStage?',
16 'thumbnail': r're:^https?://.*\.jpg$',
add96eb9 17 'duration': 93.924711,
18 },
92ddaa41
P
19 }, {
20 'url': 'https://www.gotostage.com/channel/bacc3d3535b34bafacc3f4ef8d4df78a/recording/831e74cd3e0042be96defba627b6f676/watch?source=HOMEPAGE',
21 'only_matching': True,
22 }]
23
24 def _real_extract(self, url):
25 video_id = self._match_id(url)
26 metadata = self._download_json(
add96eb9 27 f'https://api.gotostage.com/contents?ids={video_id}',
92ddaa41
P
28 video_id,
29 note='Downloading video metadata',
30 errnote='Unable to download video metadata')[0]
31
32 registration_data = {
33 'product': metadata['product'],
34 'resourceType': metadata['contentType'],
35 'productReferenceKey': metadata['productRefKey'],
36 'firstName': 'foo',
37 'lastName': 'bar',
add96eb9 38 'email': 'foobar@example.com',
92ddaa41
P
39 }
40
41 registration_response = self._download_json(
42 'https://api-registrations.logmeininc.com/registrations',
43 video_id,
44 data=json.dumps(registration_data).encode(),
45 expected_status=409,
46 headers={'Content-Type': 'application/json'},
47 note='Register user',
48 errnote='Unable to register user')
49
50 content_response = self._download_json(
add96eb9 51 f'https://api.gotostage.com/contents/{video_id}/asset',
92ddaa41
P
52 video_id,
53 headers={'x-registrantkey': registration_response['registrationKey']},
54 note='Get download url',
55 errnote='Unable to get download url')
56
57 return {
58 'id': video_id,
add96eb9 59 'title': try_get(metadata, lambda x: x['title'], str),
60 'url': try_get(content_response, lambda x: x['cdnLocation'], str),
92ddaa41
P
61 'ext': 'mp4',
62 'thumbnail': url_or_none(try_get(metadata, lambda x: x['thumbnail']['location'])),
63 'duration': try_get(metadata, lambda x: x['duration'], float),
add96eb9 64 'categories': [try_get(metadata, lambda x: x['category'], str)],
65 'is_live': False,
92ddaa41 66 }