| 
									
										
										
										
											2017-02-08 20:44:23 +01:00
										 |  |  | # coding: utf-8 | 
					
						
							|  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 01:46:05 +07:00
										 |  |  | import json | 
					
						
							|  |  |  | import hashlib | 
					
						
							|  |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-19 02:00:13 +01:00
										 |  |  | from .aws import AWSIE | 
					
						
							| 
									
										
										
										
											2017-10-15 01:46:05 +07:00
										 |  |  | from .anvato import AnvatoIE | 
					
						
							| 
									
										
										
										
											2017-02-08 20:44:23 +01:00
										 |  |  | from ..utils import ( | 
					
						
							| 
									
										
										
										
											2017-10-15 06:11:35 +07:00
										 |  |  |     smuggle_url, | 
					
						
							| 
									
										
										
										
											2017-10-15 01:46:05 +07:00
										 |  |  |     urlencode_postdata, | 
					
						
							|  |  |  |     xpath_text, | 
					
						
							| 
									
										
										
										
											2017-02-08 20:44:23 +01:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-19 02:00:13 +01:00
										 |  |  | class ScrippsNetworksWatchIE(AWSIE): | 
					
						
							| 
									
										
										
										
											2017-02-08 20:44:23 +01:00
										 |  |  |     IE_NAME = 'scrippsnetworks:watch' | 
					
						
							| 
									
										
										
										
											2017-10-15 01:46:05 +07:00
										 |  |  |     _VALID_URL = r'''(?x)
 | 
					
						
							|  |  |  |                     https?:// | 
					
						
							|  |  |  |                         watch\. | 
					
						
							| 
									
										
										
										
											2018-12-17 16:34:51 +01:00
										 |  |  |                         (?P<site>geniuskitchen)\.com/ | 
					
						
							| 
									
										
										
										
											2017-10-15 01:46:05 +07:00
										 |  |  |                         (?: | 
					
						
							|  |  |  |                             player\.[A-Z0-9]+\.html\#| | 
					
						
							| 
									
										
										
										
											2017-10-15 02:01:16 +07:00
										 |  |  |                             show/(?:[^/]+/){2}| | 
					
						
							|  |  |  |                             player/ | 
					
						
							| 
									
										
										
										
											2017-10-15 01:46:05 +07:00
										 |  |  |                         ) | 
					
						
							|  |  |  |                         (?P<id>\d+) | 
					
						
							|  |  |  |                     '''
 | 
					
						
							|  |  |  |     _TESTS = [{ | 
					
						
							| 
									
										
										
										
											2018-12-17 16:34:51 +01:00
										 |  |  |         'url': 'http://watch.geniuskitchen.com/player/3787617/Ample-Hills-Ice-Cream-Bike/', | 
					
						
							| 
									
										
										
										
											2017-02-08 20:44:23 +01:00
										 |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2018-12-17 16:34:51 +01:00
										 |  |  |             'id': '4194875', | 
					
						
							| 
									
										
										
										
											2017-02-08 20:44:23 +01:00
										 |  |  |             'ext': 'mp4', | 
					
						
							| 
									
										
										
										
											2018-12-17 16:34:51 +01:00
										 |  |  |             'title': 'Ample Hills Ice Cream Bike', | 
					
						
							|  |  |  |             'description': 'Courtney Rada churns up a signature GK Now ice cream with The Scoopmaster.', | 
					
						
							| 
									
										
										
										
											2017-10-15 01:46:05 +07:00
										 |  |  |             'uploader': 'ANV', | 
					
						
							| 
									
										
										
										
											2018-12-17 16:34:51 +01:00
										 |  |  |             'upload_date': '20171011', | 
					
						
							|  |  |  |             'timestamp': 1507698000, | 
					
						
							| 
									
										
										
										
											2017-10-15 01:46:05 +07:00
										 |  |  |         }, | 
					
						
							|  |  |  |         'params': { | 
					
						
							|  |  |  |             'skip_download': True, | 
					
						
							| 
									
										
										
										
											2017-02-08 20:44:23 +01:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2017-10-15 01:46:05 +07:00
										 |  |  |         'add_ie': [AnvatoIE.ie_key()], | 
					
						
							|  |  |  |     }] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     _SNI_TABLE = { | 
					
						
							| 
									
										
										
										
											2017-10-15 02:01:16 +07:00
										 |  |  |         'geniuskitchen': 'genius', | 
					
						
							| 
									
										
										
										
											2017-02-08 20:44:23 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-10-15 01:46:05 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     _AWS_API_KEY = 'E7wSQmq0qK6xPrF13WmzKiHo4BQ7tip4pQcSXVl1' | 
					
						
							| 
									
										
										
										
											2017-12-19 02:00:13 +01:00
										 |  |  |     _AWS_PROXY_HOST = 'web.api.video.snidigital.com' | 
					
						
							| 
									
										
										
										
											2017-10-15 01:46:05 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-19 02:00:13 +01:00
										 |  |  |     _AWS_USER_AGENT = 'aws-sdk-js/2.80.0 callback' | 
					
						
							| 
									
										
										
										
											2017-02-08 20:44:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2017-10-15 01:46:05 +07:00
										 |  |  |         mobj = re.match(self._VALID_URL, url) | 
					
						
							|  |  |  |         site_id, video_id = mobj.group('site', 'id') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-19 02:00:13 +01:00
										 |  |  |         aws_identity_id_json = json.dumps({ | 
					
						
							|  |  |  |             'IdentityId': '%s:7655847c-0ae7-4d9b-80d6-56c062927eb3' % self._AWS_REGION | 
					
						
							|  |  |  |         }).encode('utf-8') | 
					
						
							| 
									
										
										
										
											2017-10-15 01:46:05 +07:00
										 |  |  |         token = self._download_json( | 
					
						
							| 
									
										
										
										
											2017-12-19 02:00:13 +01:00
										 |  |  |             'https://cognito-identity.%s.amazonaws.com/' % self._AWS_REGION, video_id, | 
					
						
							|  |  |  |             data=aws_identity_id_json, | 
					
						
							| 
									
										
										
										
											2017-10-15 01:46:05 +07:00
										 |  |  |             headers={ | 
					
						
							|  |  |  |                 'Accept': '*/*', | 
					
						
							|  |  |  |                 'Content-Type': 'application/x-amz-json-1.1', | 
					
						
							|  |  |  |                 'Referer': url, | 
					
						
							| 
									
										
										
										
											2017-12-19 02:00:13 +01:00
										 |  |  |                 'X-Amz-Content-Sha256': hashlib.sha256(aws_identity_id_json).hexdigest(), | 
					
						
							| 
									
										
										
										
											2017-10-15 01:46:05 +07:00
										 |  |  |                 'X-Amz-Target': 'AWSCognitoIdentityService.GetOpenIdToken', | 
					
						
							|  |  |  |                 'X-Amz-User-Agent': self._AWS_USER_AGENT, | 
					
						
							|  |  |  |             })['Token'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         sts = self._download_xml( | 
					
						
							|  |  |  |             'https://sts.amazonaws.com/', video_id, data=urlencode_postdata({ | 
					
						
							|  |  |  |                 'Action': 'AssumeRoleWithWebIdentity', | 
					
						
							|  |  |  |                 'RoleArn': 'arn:aws:iam::710330595350:role/Cognito_WebAPIUnauth_Role', | 
					
						
							|  |  |  |                 'RoleSessionName': 'web-identity', | 
					
						
							|  |  |  |                 'Version': '2011-06-15', | 
					
						
							|  |  |  |                 'WebIdentityToken': token, | 
					
						
							|  |  |  |             }), headers={ | 
					
						
							|  |  |  |                 'Referer': url, | 
					
						
							|  |  |  |                 'X-Amz-User-Agent': self._AWS_USER_AGENT, | 
					
						
							|  |  |  |                 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def get(key): | 
					
						
							|  |  |  |             return xpath_text( | 
					
						
							|  |  |  |                 sts, './/{https://sts.amazonaws.com/doc/2011-06-15/}%s' % key, | 
					
						
							|  |  |  |                 fatal=True) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-19 02:00:13 +01:00
										 |  |  |         mcp_id = self._aws_execute_api({ | 
					
						
							|  |  |  |             'uri': '/1/web/brands/%s/episodes/scrid/%s' % (self._SNI_TABLE[site_id], video_id), | 
					
						
							|  |  |  |             'access_key': get('AccessKeyId'), | 
					
						
							|  |  |  |             'secret_key': get('SecretAccessKey'), | 
					
						
							|  |  |  |             'session_token': get('SessionToken'), | 
					
						
							|  |  |  |         }, video_id)['results'][0]['mcpId'] | 
					
						
							| 
									
										
										
										
											2017-10-15 01:46:05 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return self.url_result( | 
					
						
							| 
									
										
										
										
											2017-10-15 06:11:35 +07:00
										 |  |  |             smuggle_url( | 
					
						
							|  |  |  |                 'anvato:anvato_scripps_app_web_prod_0837996dbe373629133857ae9eb72e740424d80a:%s' % mcp_id, | 
					
						
							|  |  |  |                 {'geo_countries': ['US']}), | 
					
						
							| 
									
										
										
										
											2017-10-15 01:46:05 +07:00
										 |  |  |             AnvatoIE.ie_key(), video_id=mcp_id) |