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.

119 lines
4.2 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>hgtv|foodnetwork|travelchannel|diynetwork|cookingchanneltv|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.hgtv.com/show/HGTVE/Best-Ever-Treehouses/2241515/Best-Ever-Treehouses/',
  28. 'md5': '26545fd676d939954c6808274bdb905a',
  29. 'info_dict': {
  30. 'id': '4173834',
  31. 'ext': 'mp4',
  32. 'title': 'Best Ever Treehouses',
  33. 'description': "We're searching for the most over the top treehouses.",
  34. 'uploader': 'ANV',
  35. 'upload_date': '20170922',
  36. 'timestamp': 1506056400,
  37. },
  38. 'params': {
  39. 'skip_download': True,
  40. },
  41. 'add_ie': [AnvatoIE.ie_key()],
  42. }, {
  43. 'url': 'http://watch.diynetwork.com/show/DSAL/Salvage-Dawgs/2656646/Covington-Church/',
  44. 'only_matching': True,
  45. }, {
  46. 'url': 'http://watch.diynetwork.com/player.HNT.html#2656646',
  47. 'only_matching': True,
  48. }, {
  49. 'url': 'http://watch.geniuskitchen.com/player/3787617/Ample-Hills-Ice-Cream-Bike/',
  50. 'only_matching': True,
  51. }]
  52. _SNI_TABLE = {
  53. 'hgtv': 'hgtv',
  54. 'diynetwork': 'diy',
  55. 'foodnetwork': 'food',
  56. 'cookingchanneltv': 'cook',
  57. 'travelchannel': 'trav',
  58. 'geniuskitchen': 'genius',
  59. }
  60. _AWS_API_KEY = 'E7wSQmq0qK6xPrF13WmzKiHo4BQ7tip4pQcSXVl1'
  61. _AWS_PROXY_HOST = 'web.api.video.snidigital.com'
  62. _AWS_USER_AGENT = 'aws-sdk-js/2.80.0 callback'
  63. def _real_extract(self, url):
  64. mobj = re.match(self._VALID_URL, url)
  65. site_id, video_id = mobj.group('site', 'id')
  66. aws_identity_id_json = json.dumps({
  67. 'IdentityId': '%s:7655847c-0ae7-4d9b-80d6-56c062927eb3' % self._AWS_REGION
  68. }).encode('utf-8')
  69. token = self._download_json(
  70. 'https://cognito-identity.%s.amazonaws.com/' % self._AWS_REGION, video_id,
  71. data=aws_identity_id_json,
  72. headers={
  73. 'Accept': '*/*',
  74. 'Content-Type': 'application/x-amz-json-1.1',
  75. 'Referer': url,
  76. 'X-Amz-Content-Sha256': hashlib.sha256(aws_identity_id_json).hexdigest(),
  77. 'X-Amz-Target': 'AWSCognitoIdentityService.GetOpenIdToken',
  78. 'X-Amz-User-Agent': self._AWS_USER_AGENT,
  79. })['Token']
  80. sts = self._download_xml(
  81. 'https://sts.amazonaws.com/', video_id, data=urlencode_postdata({
  82. 'Action': 'AssumeRoleWithWebIdentity',
  83. 'RoleArn': 'arn:aws:iam::710330595350:role/Cognito_WebAPIUnauth_Role',
  84. 'RoleSessionName': 'web-identity',
  85. 'Version': '2011-06-15',
  86. 'WebIdentityToken': token,
  87. }), headers={
  88. 'Referer': url,
  89. 'X-Amz-User-Agent': self._AWS_USER_AGENT,
  90. 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
  91. })
  92. def get(key):
  93. return xpath_text(
  94. sts, './/{https://sts.amazonaws.com/doc/2011-06-15/}%s' % key,
  95. fatal=True)
  96. mcp_id = self._aws_execute_api({
  97. 'uri': '/1/web/brands/%s/episodes/scrid/%s' % (self._SNI_TABLE[site_id], video_id),
  98. 'access_key': get('AccessKeyId'),
  99. 'secret_key': get('SecretAccessKey'),
  100. 'session_token': get('SessionToken'),
  101. }, video_id)['results'][0]['mcpId']
  102. return self.url_result(
  103. smuggle_url(
  104. 'anvato:anvato_scripps_app_web_prod_0837996dbe373629133857ae9eb72e740424d80a:%s' % mcp_id,
  105. {'geo_countries': ['US']}),
  106. AnvatoIE.ie_key(), video_id=mcp_id)