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