+
+ # Task 2: http://docs.aws.amazon.com/general/latest/gr/sigv4-create-string-to-sign.html
+ credential_string = '/'.join([date, self._AWS_REGION, self._AWS_SERVICE, self._AWS_REQUEST])
+ string_to_sign = '\n'.join([
+ 'AWS4-HMAC-SHA256', datetime_now, credential_string,
+ aws_hash(canonical_string)])
+
+ # Task 3: http://docs.aws.amazon.com/general/latest/gr/sigv4-calculate-signature.html
+ def aws_hmac(key, msg):
+ return hmac.new(key, msg.encode('utf-8'), hashlib.sha256)
+
+ def aws_hmac_digest(key, msg):
+ return aws_hmac(key, msg).digest()
+
+ def aws_hmac_hexdigest(key, msg):
+ return aws_hmac(key, msg).hexdigest()
+
+ k_secret = 'AWS4' + secret_access_key
+ k_date = aws_hmac_digest(k_secret.encode('utf-8'), date)
+ k_region = aws_hmac_digest(k_date, self._AWS_REGION)
+ k_service = aws_hmac_digest(k_region, self._AWS_SERVICE)
+ k_signing = aws_hmac_digest(k_service, self._AWS_REQUEST)
+
+ signature = aws_hmac_hexdigest(k_signing, string_to_sign)
+
+ auth_header = ', '.join([
+ 'AWS4-HMAC-SHA256 Credential=%s' % '/'.join(
+ [access_key_id, date, self._AWS_REGION, self._AWS_SERVICE, self._AWS_REQUEST]),
+ 'SignedHeaders=%s' % self._AWS_SIGNED_HEADERS,
+ 'Signature=%s' % signature,
+ ])
+
+ mcp_id = self._download_json(
+ 'https://%s%s' % (self._SNI_HOST, uri), video_id, headers={
+ 'Accept': '*/*',
+ 'Referer': url,
+ 'Authorization': auth_header,
+ 'X-Amz-Date': datetime_now,
+ 'X-Amz-Security-Token': session_token,
+ 'X-Api-Key': self._AWS_API_KEY,
+ })['results'][0]['mcpId']
+
+ return self.url_result(
+ smuggle_url(
+ 'anvato:anvato_scripps_app_web_prod_0837996dbe373629133857ae9eb72e740424d80a:%s' % mcp_id,
+ {'geo_countries': ['US']}),
+ AnvatoIE.ie_key(), video_id=mcp_id)