]>
Commit | Line | Data |
---|---|---|
82980182 RA |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
b21ab850 S |
4 | import json |
5 | import hashlib | |
b21ab850 S |
6 | import re |
7 | ||
78466fca | 8 | from .aws import AWSIE |
b21ab850 | 9 | from .anvato import AnvatoIE |
82980182 | 10 | from ..utils import ( |
48272705 | 11 | smuggle_url, |
b21ab850 S |
12 | urlencode_postdata, |
13 | xpath_text, | |
82980182 RA |
14 | ) |
15 | ||
16 | ||
78466fca | 17 | class ScrippsNetworksWatchIE(AWSIE): |
82980182 | 18 | IE_NAME = 'scrippsnetworks:watch' |
b21ab850 S |
19 | _VALID_URL = r'''(?x) |
20 | https?:// | |
21 | watch\. | |
57eb45b1 | 22 | (?P<site>hgtv|foodnetwork|travelchannel|diynetwork|cookingchanneltv|geniuskitchen)\.com/ |
b21ab850 S |
23 | (?: |
24 | player\.[A-Z0-9]+\.html\#| | |
57eb45b1 S |
25 | show/(?:[^/]+/){2}| |
26 | player/ | |
b21ab850 S |
27 | ) |
28 | (?P<id>\d+) | |
29 | ''' | |
30 | _TESTS = [{ | |
31 | 'url': 'http://watch.hgtv.com/show/HGTVE/Best-Ever-Treehouses/2241515/Best-Ever-Treehouses/', | |
82980182 RA |
32 | 'md5': '26545fd676d939954c6808274bdb905a', |
33 | 'info_dict': { | |
b21ab850 | 34 | 'id': '4173834', |
82980182 | 35 | 'ext': 'mp4', |
b21ab850 S |
36 | 'title': 'Best Ever Treehouses', |
37 | 'description': "We're searching for the most over the top treehouses.", | |
38 | 'uploader': 'ANV', | |
39 | 'upload_date': '20170922', | |
40 | 'timestamp': 1506056400, | |
41 | }, | |
42 | 'params': { | |
43 | 'skip_download': True, | |
82980182 | 44 | }, |
b21ab850 S |
45 | 'add_ie': [AnvatoIE.ie_key()], |
46 | }, { | |
47 | 'url': 'http://watch.diynetwork.com/show/DSAL/Salvage-Dawgs/2656646/Covington-Church/', | |
48 | 'only_matching': True, | |
49 | }, { | |
50 | 'url': 'http://watch.diynetwork.com/player.HNT.html#2656646', | |
51 | 'only_matching': True, | |
57eb45b1 S |
52 | }, { |
53 | 'url': 'http://watch.geniuskitchen.com/player/3787617/Ample-Hills-Ice-Cream-Bike/', | |
54 | 'only_matching': True, | |
b21ab850 S |
55 | }] |
56 | ||
57 | _SNI_TABLE = { | |
58 | 'hgtv': 'hgtv', | |
59 | 'diynetwork': 'diy', | |
60 | 'foodnetwork': 'food', | |
61 | 'cookingchanneltv': 'cook', | |
62 | 'travelchannel': 'trav', | |
57eb45b1 | 63 | 'geniuskitchen': 'genius', |
82980182 | 64 | } |
b21ab850 | 65 | |
b21ab850 | 66 | _AWS_API_KEY = 'E7wSQmq0qK6xPrF13WmzKiHo4BQ7tip4pQcSXVl1' |
78466fca | 67 | _AWS_PROXY_HOST = 'web.api.video.snidigital.com' |
b21ab850 | 68 | |
78466fca | 69 | _AWS_USER_AGENT = 'aws-sdk-js/2.80.0 callback' |
82980182 RA |
70 | |
71 | def _real_extract(self, url): | |
b21ab850 S |
72 | mobj = re.match(self._VALID_URL, url) |
73 | site_id, video_id = mobj.group('site', 'id') | |
74 | ||
78466fca RA |
75 | aws_identity_id_json = json.dumps({ |
76 | 'IdentityId': '%s:7655847c-0ae7-4d9b-80d6-56c062927eb3' % self._AWS_REGION | |
77 | }).encode('utf-8') | |
b21ab850 | 78 | token = self._download_json( |
78466fca RA |
79 | 'https://cognito-identity.%s.amazonaws.com/' % self._AWS_REGION, video_id, |
80 | data=aws_identity_id_json, | |
b21ab850 S |
81 | headers={ |
82 | 'Accept': '*/*', | |
83 | 'Content-Type': 'application/x-amz-json-1.1', | |
84 | 'Referer': url, | |
78466fca | 85 | 'X-Amz-Content-Sha256': hashlib.sha256(aws_identity_id_json).hexdigest(), |
b21ab850 S |
86 | 'X-Amz-Target': 'AWSCognitoIdentityService.GetOpenIdToken', |
87 | 'X-Amz-User-Agent': self._AWS_USER_AGENT, | |
88 | })['Token'] | |
89 | ||
90 | sts = self._download_xml( | |
91 | 'https://sts.amazonaws.com/', video_id, data=urlencode_postdata({ | |
92 | 'Action': 'AssumeRoleWithWebIdentity', | |
93 | 'RoleArn': 'arn:aws:iam::710330595350:role/Cognito_WebAPIUnauth_Role', | |
94 | 'RoleSessionName': 'web-identity', | |
95 | 'Version': '2011-06-15', | |
96 | 'WebIdentityToken': token, | |
97 | }), headers={ | |
98 | 'Referer': url, | |
99 | 'X-Amz-User-Agent': self._AWS_USER_AGENT, | |
100 | 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', | |
101 | }) | |
102 | ||
103 | def get(key): | |
104 | return xpath_text( | |
105 | sts, './/{https://sts.amazonaws.com/doc/2011-06-15/}%s' % key, | |
106 | fatal=True) | |
107 | ||
78466fca RA |
108 | mcp_id = self._aws_execute_api({ |
109 | 'uri': '/1/web/brands/%s/episodes/scrid/%s' % (self._SNI_TABLE[site_id], video_id), | |
110 | 'access_key': get('AccessKeyId'), | |
111 | 'secret_key': get('SecretAccessKey'), | |
112 | 'session_token': get('SessionToken'), | |
113 | }, video_id)['results'][0]['mcpId'] | |
b21ab850 S |
114 | |
115 | return self.url_result( | |
48272705 S |
116 | smuggle_url( |
117 | 'anvato:anvato_scripps_app_web_prod_0837996dbe373629133857ae9eb72e740424d80a:%s' % mcp_id, | |
118 | {'geo_countries': ['US']}), | |
b21ab850 | 119 | AnvatoIE.ie_key(), video_id=mcp_id) |