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