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