scrippsnetworks.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import json
  2. import hashlib
  3. from .aws import AWSIE
  4. from .anvato import AnvatoIE
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. smuggle_url,
  8. urlencode_postdata,
  9. xpath_text,
  10. )
  11. class ScrippsNetworksWatchIE(AWSIE):
  12. IE_NAME = 'scrippsnetworks:watch'
  13. _VALID_URL = r'''(?x)
  14. https?://
  15. watch\.
  16. (?P<site>geniuskitchen)\.com/
  17. (?:
  18. player\.[A-Z0-9]+\.html\#|
  19. show/(?:[^/]+/){2}|
  20. player/
  21. )
  22. (?P<id>\d+)
  23. '''
  24. _TESTS = [{
  25. 'url': 'http://watch.geniuskitchen.com/player/3787617/Ample-Hills-Ice-Cream-Bike/',
  26. 'info_dict': {
  27. 'id': '4194875',
  28. 'ext': 'mp4',
  29. 'title': 'Ample Hills Ice Cream Bike',
  30. 'description': 'Courtney Rada churns up a signature GK Now ice cream with The Scoopmaster.',
  31. 'uploader': 'ANV',
  32. 'upload_date': '20171011',
  33. 'timestamp': 1507698000,
  34. },
  35. 'params': {
  36. 'skip_download': True,
  37. },
  38. 'add_ie': [AnvatoIE.ie_key()],
  39. }]
  40. _SNI_TABLE = {
  41. 'geniuskitchen': 'genius',
  42. }
  43. _AWS_API_KEY = 'E7wSQmq0qK6xPrF13WmzKiHo4BQ7tip4pQcSXVl1'
  44. _AWS_PROXY_HOST = 'web.api.video.snidigital.com'
  45. _AWS_USER_AGENT = 'aws-sdk-js/2.80.0 callback'
  46. def _real_extract(self, url):
  47. mobj = self._match_valid_url(url)
  48. site_id, video_id = mobj.group('site', 'id')
  49. aws_identity_id_json = json.dumps({
  50. 'IdentityId': '%s:7655847c-0ae7-4d9b-80d6-56c062927eb3' % self._AWS_REGION
  51. }).encode('utf-8')
  52. token = self._download_json(
  53. 'https://cognito-identity.%s.amazonaws.com/' % self._AWS_REGION, video_id,
  54. data=aws_identity_id_json,
  55. headers={
  56. 'Accept': '*/*',
  57. 'Content-Type': 'application/x-amz-json-1.1',
  58. 'Referer': url,
  59. 'X-Amz-Content-Sha256': hashlib.sha256(aws_identity_id_json).hexdigest(),
  60. 'X-Amz-Target': 'AWSCognitoIdentityService.GetOpenIdToken',
  61. 'X-Amz-User-Agent': self._AWS_USER_AGENT,
  62. })['Token']
  63. sts = self._download_xml(
  64. 'https://sts.amazonaws.com/', video_id, data=urlencode_postdata({
  65. 'Action': 'AssumeRoleWithWebIdentity',
  66. 'RoleArn': 'arn:aws:iam::710330595350:role/Cognito_WebAPIUnauth_Role',
  67. 'RoleSessionName': 'web-identity',
  68. 'Version': '2011-06-15',
  69. 'WebIdentityToken': token,
  70. }), headers={
  71. 'Referer': url,
  72. 'X-Amz-User-Agent': self._AWS_USER_AGENT,
  73. 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
  74. })
  75. def get(key):
  76. return xpath_text(
  77. sts, './/{https://sts.amazonaws.com/doc/2011-06-15/}%s' % key,
  78. fatal=True)
  79. mcp_id = self._aws_execute_api({
  80. 'uri': '/1/web/brands/%s/episodes/scrid/%s' % (self._SNI_TABLE[site_id], video_id),
  81. 'access_key': get('AccessKeyId'),
  82. 'secret_key': get('SecretAccessKey'),
  83. 'session_token': get('SessionToken'),
  84. }, video_id)['results'][0]['mcpId']
  85. return self.url_result(
  86. smuggle_url(
  87. 'anvato:anvato_scripps_app_web_prod_0837996dbe373629133857ae9eb72e740424d80a:%s' % mcp_id,
  88. {'geo_countries': ['US']}),
  89. AnvatoIE.ie_key(), video_id=mcp_id)
  90. class ScrippsNetworksIE(InfoExtractor):
  91. _VALID_URL = r'https?://(?:www\.)?(?P<site>cookingchanneltv|discovery|(?:diy|food)network|hgtv|travelchannel)\.com/videos/[0-9a-z-]+-(?P<id>\d+)'
  92. _TESTS = [{
  93. 'url': 'https://www.cookingchanneltv.com/videos/the-best-of-the-best-0260338',
  94. 'info_dict': {
  95. 'id': '0260338',
  96. 'ext': 'mp4',
  97. 'title': 'The Best of the Best',
  98. 'description': 'Catch a new episode of MasterChef Canada Tuedsay at 9/8c.',
  99. 'timestamp': 1475678834,
  100. 'upload_date': '20161005',
  101. 'uploader': 'SCNI-SCND',
  102. },
  103. 'add_ie': ['ThePlatform'],
  104. }, {
  105. 'url': 'https://www.diynetwork.com/videos/diy-barnwood-tablet-stand-0265790',
  106. 'only_matching': True,
  107. }, {
  108. 'url': 'https://www.foodnetwork.com/videos/chocolate-strawberry-cake-roll-7524591',
  109. 'only_matching': True,
  110. }, {
  111. 'url': 'https://www.hgtv.com/videos/cookie-decorating-101-0301929',
  112. 'only_matching': True,
  113. }, {
  114. 'url': 'https://www.travelchannel.com/videos/two-climates-one-bag-5302184',
  115. 'only_matching': True,
  116. }, {
  117. 'url': 'https://www.discovery.com/videos/guardians-of-the-glades-cooking-with-tom-cobb-5578368',
  118. 'only_matching': True,
  119. }]
  120. _ACCOUNT_MAP = {
  121. 'cookingchanneltv': 2433005105,
  122. 'discovery': 2706091867,
  123. 'diynetwork': 2433004575,
  124. 'foodnetwork': 2433005105,
  125. 'hgtv': 2433004575,
  126. 'travelchannel': 2433005739,
  127. }
  128. _TP_TEMPL = 'https://link.theplatform.com/s/ip77QC/media/guid/%d/%s?mbr=true'
  129. def _real_extract(self, url):
  130. site, guid = self._match_valid_url(url).groups()
  131. return self.url_result(smuggle_url(
  132. self._TP_TEMPL % (self._ACCOUNT_MAP[site], guid),
  133. {'force_smil_url': True}), 'ThePlatform', guid)