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