scrippsnetworks.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import hashlib
  2. import json
  3. from .anvato import AnvatoIE
  4. from .aws import AWSIE
  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. 'skip': '404 Not Found',
  40. }]
  41. _SNI_TABLE = {
  42. 'geniuskitchen': 'genius',
  43. }
  44. _AWS_API_KEY = 'E7wSQmq0qK6xPrF13WmzKiHo4BQ7tip4pQcSXVl1'
  45. _AWS_PROXY_HOST = 'web.api.video.snidigital.com'
  46. _AWS_USER_AGENT = 'aws-sdk-js/2.80.0 callback'
  47. def _real_extract(self, url):
  48. mobj = self._match_valid_url(url)
  49. site_id, video_id = mobj.group('site', 'id')
  50. aws_identity_id_json = json.dumps({
  51. 'IdentityId': f'{self._AWS_REGION}:7655847c-0ae7-4d9b-80d6-56c062927eb3',
  52. }).encode()
  53. token = self._download_json(
  54. f'https://cognito-identity.{self._AWS_REGION}.amazonaws.com/', video_id,
  55. data=aws_identity_id_json,
  56. headers={
  57. 'Accept': '*/*',
  58. 'Content-Type': 'application/x-amz-json-1.1',
  59. 'Referer': url,
  60. 'X-Amz-Content-Sha256': hashlib.sha256(aws_identity_id_json).hexdigest(),
  61. 'X-Amz-Target': 'AWSCognitoIdentityService.GetOpenIdToken',
  62. 'X-Amz-User-Agent': self._AWS_USER_AGENT,
  63. })['Token']
  64. sts = self._download_xml(
  65. 'https://sts.amazonaws.com/', video_id, data=urlencode_postdata({
  66. 'Action': 'AssumeRoleWithWebIdentity',
  67. 'RoleArn': 'arn:aws:iam::710330595350:role/Cognito_WebAPIUnauth_Role',
  68. 'RoleSessionName': 'web-identity',
  69. 'Version': '2011-06-15',
  70. 'WebIdentityToken': token,
  71. }), headers={
  72. 'Referer': url,
  73. 'X-Amz-User-Agent': self._AWS_USER_AGENT,
  74. 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
  75. })
  76. def get(key):
  77. return xpath_text(
  78. sts, f'.//{{https://sts.amazonaws.com/doc/2011-06-15/}}{key}',
  79. fatal=True)
  80. mcp_id = self._aws_execute_api({
  81. 'uri': f'/1/web/brands/{self._SNI_TABLE[site_id]}/episodes/scrid/{video_id}',
  82. 'access_key': get('AccessKeyId'),
  83. 'secret_key': get('SecretAccessKey'),
  84. 'session_token': get('SessionToken'),
  85. }, video_id)['results'][0]['mcpId']
  86. return self.url_result(
  87. smuggle_url(
  88. f'anvato:anvato_scripps_app_web_prod_0837996dbe373629133857ae9eb72e740424d80a:{mcp_id}',
  89. {'geo_countries': ['US']}),
  90. AnvatoIE.ie_key(), video_id=mcp_id)
  91. class ScrippsNetworksIE(InfoExtractor):
  92. _VALID_URL = r'https?://(?:www\.)?(?P<site>cookingchanneltv|discovery|(?:diy|food)network|hgtv|travelchannel)\.com/videos/[0-9a-z-]+-(?P<id>\d+)'
  93. _TESTS = [{
  94. 'url': 'https://www.cookingchanneltv.com/videos/the-best-of-the-best-0260338',
  95. 'info_dict': {
  96. 'id': '0260338',
  97. 'ext': 'mp4',
  98. 'title': 'The Best of the Best',
  99. 'description': 'Catch a new episode of MasterChef Canada Tuedsay at 9/8c.',
  100. 'timestamp': 1475678834,
  101. 'upload_date': '20161005',
  102. 'uploader': 'SCNI-SCND',
  103. 'tags': 'count:10',
  104. 'creator': 'Cooking Channel',
  105. 'duration': 29.995,
  106. 'chapters': [{'start_time': 0.0, 'end_time': 29.995, 'title': '<Untitled Chapter 1>'}],
  107. 'thumbnail': 'https://images.dds.discovery.com/up/tp/Scripps_-_Food_Category_Prod/122/987/0260338_630x355.jpg',
  108. },
  109. 'add_ie': ['ThePlatform'],
  110. 'expected_warnings': ['No HLS formats found'],
  111. }, {
  112. 'url': 'https://www.diynetwork.com/videos/diy-barnwood-tablet-stand-0265790',
  113. 'only_matching': True,
  114. }, {
  115. 'url': 'https://www.foodnetwork.com/videos/chocolate-strawberry-cake-roll-7524591',
  116. 'only_matching': True,
  117. }, {
  118. 'url': 'https://www.hgtv.com/videos/cookie-decorating-101-0301929',
  119. 'only_matching': True,
  120. }, {
  121. 'url': 'https://www.travelchannel.com/videos/two-climates-one-bag-5302184',
  122. 'only_matching': True,
  123. }, {
  124. 'url': 'https://www.discovery.com/videos/guardians-of-the-glades-cooking-with-tom-cobb-5578368',
  125. 'only_matching': True,
  126. }]
  127. _ACCOUNT_MAP = {
  128. 'cookingchanneltv': 2433005105,
  129. 'discovery': 2706091867,
  130. 'diynetwork': 2433004575,
  131. 'foodnetwork': 2433005105,
  132. 'hgtv': 2433004575,
  133. 'travelchannel': 2433005739,
  134. }
  135. _TP_TEMPL = 'https://link.theplatform.com/s/ip77QC/media/guid/%d/%s?mbr=true'
  136. def _real_extract(self, url):
  137. site, guid = self._match_valid_url(url).groups()
  138. return self.url_result(smuggle_url(
  139. self._TP_TEMPL % (self._ACCOUNT_MAP[site], guid),
  140. {'force_smil_url': True}), 'ThePlatform', guid)