gotostage.py 2.6 KB

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