]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/scrippsnetworks.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / scrippsnetworks.py
CommitLineData
b21ab850 1import hashlib
e897bd82 2import json
b21ab850 3
b21ab850 4from .anvato import AnvatoIE
e897bd82 5from .aws import AWSIE
7ea55819 6from .common import InfoExtractor
82980182 7from ..utils import (
48272705 8 smuggle_url,
b21ab850
S
9 urlencode_postdata,
10 xpath_text,
82980182
RA
11)
12
13
78466fca 14class 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()],
19c90e40 42 'skip': '404 Not Found',
b21ab850
S
43 }]
44
45 _SNI_TABLE = {
57eb45b1 46 'geniuskitchen': 'genius',
82980182 47 }
b21ab850 48
b21ab850 49 _AWS_API_KEY = 'E7wSQmq0qK6xPrF13WmzKiHo4BQ7tip4pQcSXVl1'
78466fca 50 _AWS_PROXY_HOST = 'web.api.video.snidigital.com'
b21ab850 51
78466fca 52 _AWS_USER_AGENT = 'aws-sdk-js/2.80.0 callback'
82980182
RA
53
54 def _real_extract(self, url):
5ad28e7f 55 mobj = self._match_valid_url(url)
b21ab850
S
56 site_id, video_id = mobj.group('site', 'id')
57
78466fca
RA
58 aws_identity_id_json = json.dumps({
59 'IdentityId': '%s:7655847c-0ae7-4d9b-80d6-56c062927eb3' % self._AWS_REGION
60 }).encode('utf-8')
b21ab850 61 token = self._download_json(
78466fca
RA
62 'https://cognito-identity.%s.amazonaws.com/' % self._AWS_REGION, video_id,
63 data=aws_identity_id_json,
b21ab850
S
64 headers={
65 'Accept': '*/*',
66 'Content-Type': 'application/x-amz-json-1.1',
67 'Referer': url,
78466fca 68 'X-Amz-Content-Sha256': hashlib.sha256(aws_identity_id_json).hexdigest(),
b21ab850
S
69 'X-Amz-Target': 'AWSCognitoIdentityService.GetOpenIdToken',
70 'X-Amz-User-Agent': self._AWS_USER_AGENT,
71 })['Token']
72
73 sts = self._download_xml(
74 'https://sts.amazonaws.com/', video_id, data=urlencode_postdata({
75 'Action': 'AssumeRoleWithWebIdentity',
76 'RoleArn': 'arn:aws:iam::710330595350:role/Cognito_WebAPIUnauth_Role',
77 'RoleSessionName': 'web-identity',
78 'Version': '2011-06-15',
79 'WebIdentityToken': token,
80 }), headers={
81 'Referer': url,
82 'X-Amz-User-Agent': self._AWS_USER_AGENT,
83 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
84 })
85
86 def get(key):
87 return xpath_text(
88 sts, './/{https://sts.amazonaws.com/doc/2011-06-15/}%s' % key,
89 fatal=True)
90
78466fca
RA
91 mcp_id = self._aws_execute_api({
92 'uri': '/1/web/brands/%s/episodes/scrid/%s' % (self._SNI_TABLE[site_id], video_id),
93 'access_key': get('AccessKeyId'),
94 'secret_key': get('SecretAccessKey'),
95 'session_token': get('SessionToken'),
96 }, video_id)['results'][0]['mcpId']
b21ab850
S
97
98 return self.url_result(
48272705
S
99 smuggle_url(
100 'anvato:anvato_scripps_app_web_prod_0837996dbe373629133857ae9eb72e740424d80a:%s' % mcp_id,
101 {'geo_countries': ['US']}),
b21ab850 102 AnvatoIE.ie_key(), video_id=mcp_id)
7ea55819
RA
103
104
105class ScrippsNetworksIE(InfoExtractor):
02649035 106 _VALID_URL = r'https?://(?:www\.)?(?P<site>cookingchanneltv|discovery|(?:diy|food)network|hgtv|travelchannel)\.com/videos/[0-9a-z-]+-(?P<id>\d+)'
7ea55819
RA
107 _TESTS = [{
108 'url': 'https://www.cookingchanneltv.com/videos/the-best-of-the-best-0260338',
109 'info_dict': {
110 'id': '0260338',
111 'ext': 'mp4',
112 'title': 'The Best of the Best',
113 'description': 'Catch a new episode of MasterChef Canada Tuedsay at 9/8c.',
114 'timestamp': 1475678834,
115 'upload_date': '20161005',
116 'uploader': 'SCNI-SCND',
7e09c147 117 'tags': 'count:10',
118 'creator': 'Cooking Channel',
19c90e40 119 'duration': 29.995,
120 'chapters': [{'start_time': 0.0, 'end_time': 29.995, 'title': '<Untitled Chapter 1>'}],
121 'thumbnail': 'https://images.dds.discovery.com/up/tp/Scripps_-_Food_Category_Prod/122/987/0260338_630x355.jpg',
7ea55819
RA
122 },
123 'add_ie': ['ThePlatform'],
339c339f 124 'expected_warnings': ['No HLS formats found'],
7ea55819
RA
125 }, {
126 'url': 'https://www.diynetwork.com/videos/diy-barnwood-tablet-stand-0265790',
127 'only_matching': True,
128 }, {
129 'url': 'https://www.foodnetwork.com/videos/chocolate-strawberry-cake-roll-7524591',
130 'only_matching': True,
131 }, {
132 'url': 'https://www.hgtv.com/videos/cookie-decorating-101-0301929',
133 'only_matching': True,
134 }, {
135 'url': 'https://www.travelchannel.com/videos/two-climates-one-bag-5302184',
136 'only_matching': True,
02649035 137 }, {
7bac7741 138 'url': 'https://www.discovery.com/videos/guardians-of-the-glades-cooking-with-tom-cobb-5578368',
02649035 139 'only_matching': True,
7ea55819
RA
140 }]
141 _ACCOUNT_MAP = {
142 'cookingchanneltv': 2433005105,
02649035 143 'discovery': 2706091867,
7ea55819
RA
144 'diynetwork': 2433004575,
145 'foodnetwork': 2433005105,
146 'hgtv': 2433004575,
147 'travelchannel': 2433005739,
148 }
149 _TP_TEMPL = 'https://link.theplatform.com/s/ip77QC/media/guid/%d/%s?mbr=true'
150
151 def _real_extract(self, url):
5ad28e7f 152 site, guid = self._match_valid_url(url).groups()
7ea55819
RA
153 return self.url_result(smuggle_url(
154 self._TP_TEMPL % (self._ACCOUNT_MAP[site], guid),
155 {'force_smil_url': True}), 'ThePlatform', guid)