logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

scrippsnetworks.py (5632B)


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