]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/scrippsnetworks.py
debian/README.source: Change 'markup'.
[youtubedl] / youtube_dl / extractor / scrippsnetworks.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import json
5 import hashlib
6 import re
7
8 from .aws import AWSIE
9 from .anvato import AnvatoIE
10 from ..utils import (
11 smuggle_url,
12 urlencode_postdata,
13 xpath_text,
14 )
15
16
17 class ScrippsNetworksWatchIE(AWSIE):
18 IE_NAME = 'scrippsnetworks:watch'
19 _VALID_URL = r'''(?x)
20 https?://
21 watch\.
22 (?P<site>geniuskitchen)\.com/
23 (?:
24 player\.[A-Z0-9]+\.html\#|
25 show/(?:[^/]+/){2}|
26 player/
27 )
28 (?P<id>\d+)
29 '''
30 _TESTS = [{
31 'url': 'http://watch.geniuskitchen.com/player/3787617/Ample-Hills-Ice-Cream-Bike/',
32 'info_dict': {
33 'id': '4194875',
34 'ext': 'mp4',
35 'title': 'Ample Hills Ice Cream Bike',
36 'description': 'Courtney Rada churns up a signature GK Now ice cream with The Scoopmaster.',
37 'uploader': 'ANV',
38 'upload_date': '20171011',
39 'timestamp': 1507698000,
40 },
41 'params': {
42 'skip_download': True,
43 },
44 'add_ie': [AnvatoIE.ie_key()],
45 }]
46
47 _SNI_TABLE = {
48 'geniuskitchen': 'genius',
49 }
50
51 _AWS_API_KEY = 'E7wSQmq0qK6xPrF13WmzKiHo4BQ7tip4pQcSXVl1'
52 _AWS_PROXY_HOST = 'web.api.video.snidigital.com'
53
54 _AWS_USER_AGENT = 'aws-sdk-js/2.80.0 callback'
55
56 def _real_extract(self, url):
57 mobj = re.match(self._VALID_URL, url)
58 site_id, video_id = mobj.group('site', 'id')
59
60 aws_identity_id_json = json.dumps({
61 'IdentityId': '%s:7655847c-0ae7-4d9b-80d6-56c062927eb3' % self._AWS_REGION
62 }).encode('utf-8')
63 token = self._download_json(
64 'https://cognito-identity.%s.amazonaws.com/' % self._AWS_REGION, video_id,
65 data=aws_identity_id_json,
66 headers={
67 'Accept': '*/*',
68 'Content-Type': 'application/x-amz-json-1.1',
69 'Referer': url,
70 'X-Amz-Content-Sha256': hashlib.sha256(aws_identity_id_json).hexdigest(),
71 'X-Amz-Target': 'AWSCognitoIdentityService.GetOpenIdToken',
72 'X-Amz-User-Agent': self._AWS_USER_AGENT,
73 })['Token']
74
75 sts = self._download_xml(
76 'https://sts.amazonaws.com/', video_id, data=urlencode_postdata({
77 'Action': 'AssumeRoleWithWebIdentity',
78 'RoleArn': 'arn:aws:iam::710330595350:role/Cognito_WebAPIUnauth_Role',
79 'RoleSessionName': 'web-identity',
80 'Version': '2011-06-15',
81 'WebIdentityToken': token,
82 }), headers={
83 'Referer': url,
84 'X-Amz-User-Agent': self._AWS_USER_AGENT,
85 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
86 })
87
88 def get(key):
89 return xpath_text(
90 sts, './/{https://sts.amazonaws.com/doc/2011-06-15/}%s' % key,
91 fatal=True)
92
93 mcp_id = self._aws_execute_api({
94 'uri': '/1/web/brands/%s/episodes/scrid/%s' % (self._SNI_TABLE[site_id], video_id),
95 'access_key': get('AccessKeyId'),
96 'secret_key': get('SecretAccessKey'),
97 'session_token': get('SessionToken'),
98 }, video_id)['results'][0]['mcpId']
99
100 return self.url_result(
101 smuggle_url(
102 'anvato:anvato_scripps_app_web_prod_0837996dbe373629133857ae9eb72e740424d80a:%s' % mcp_id,
103 {'geo_countries': ['US']}),
104 AnvatoIE.ie_key(), video_id=mcp_id)