You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. import hashlib
  5. import re
  6. from .aws import AWSIE
  7. from .anvato import AnvatoIE
  8. from ..utils import (
  9. smuggle_url,
  10. urlencode_postdata,
  11. xpath_text,
  12. )
  13. class ScrippsNetworksWatchIE(AWSIE):
  14. IE_NAME = 'scrippsnetworks:watch'
  15. _VALID_URL = r'''(?x)
  16. https?://
  17. watch\.
  18. (?P<site>geniuskitchen)\.com/
  19. (?:
  20. player\.[A-Z0-9]+\.html\#|
  21. show/(?:[^/]+/){2}|
  22. player/
  23. )
  24. (?P<id>\d+)
  25. '''
  26. _TESTS = [{
  27. 'url': 'http://watch.geniuskitchen.com/player/3787617/Ample-Hills-Ice-Cream-Bike/',
  28. 'info_dict': {
  29. 'id': '4194875',
  30. 'ext': 'mp4',
  31. 'title': 'Ample Hills Ice Cream Bike',
  32. 'description': 'Courtney Rada churns up a signature GK Now ice cream with The Scoopmaster.',
  33. 'uploader': 'ANV',
  34. 'upload_date': '20171011',
  35. 'timestamp': 1507698000,
  36. },
  37. 'params': {
  38. 'skip_download': True,
  39. },
  40. 'add_ie': [AnvatoIE.ie_key()],
  41. }]
  42. _SNI_TABLE = {
  43. 'geniuskitchen': 'genius',
  44. }
  45. _AWS_API_KEY = 'E7wSQmq0qK6xPrF13WmzKiHo4BQ7tip4pQcSXVl1'
  46. _AWS_PROXY_HOST = 'web.api.video.snidigital.com'
  47. _AWS_USER_AGENT = 'aws-sdk-js/2.80.0 callback'
  48. def _real_extract(self, url):
  49. mobj = re.match(self._VALID_URL, url)
  50. site_id, video_id = mobj.group('site', 'id')
  51. aws_identity_id_json = json.dumps({
  52. 'IdentityId': '%s:7655847c-0ae7-4d9b-80d6-56c062927eb3' % self._AWS_REGION
  53. }).encode('utf-8')
  54. token = self._download_json(
  55. 'https://cognito-identity.%s.amazonaws.com/' % self._AWS_REGION, video_id,
  56. data=aws_identity_id_json,
  57. headers={
  58. 'Accept': '*/*',
  59. 'Content-Type': 'application/x-amz-json-1.1',
  60. 'Referer': url,
  61. 'X-Amz-Content-Sha256': hashlib.sha256(aws_identity_id_json).hexdigest(),
  62. 'X-Amz-Target': 'AWSCognitoIdentityService.GetOpenIdToken',
  63. 'X-Amz-User-Agent': self._AWS_USER_AGENT,
  64. })['Token']
  65. sts = self._download_xml(
  66. 'https://sts.amazonaws.com/', video_id, data=urlencode_postdata({
  67. 'Action': 'AssumeRoleWithWebIdentity',
  68. 'RoleArn': 'arn:aws:iam::710330595350:role/Cognito_WebAPIUnauth_Role',
  69. 'RoleSessionName': 'web-identity',
  70. 'Version': '2011-06-15',
  71. 'WebIdentityToken': token,
  72. }), headers={
  73. 'Referer': url,
  74. 'X-Amz-User-Agent': self._AWS_USER_AGENT,
  75. 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
  76. })
  77. def get(key):
  78. return xpath_text(
  79. sts, './/{https://sts.amazonaws.com/doc/2011-06-15/}%s' % key,
  80. fatal=True)
  81. mcp_id = self._aws_execute_api({
  82. 'uri': '/1/web/brands/%s/episodes/scrid/%s' % (self._SNI_TABLE[site_id], video_id),
  83. 'access_key': get('AccessKeyId'),
  84. 'secret_key': get('SecretAccessKey'),
  85. 'session_token': get('SessionToken'),
  86. }, video_id)['results'][0]['mcpId']
  87. return self.url_result(
  88. smuggle_url(
  89. 'anvato:anvato_scripps_app_web_prod_0837996dbe373629133857ae9eb72e740424d80a:%s' % mcp_id,
  90. {'geo_countries': ['US']}),
  91. AnvatoIE.ie_key(), video_id=mcp_id)